Comments (5)
That's a good plan. Thank you again! I'll leave this issue open until we have at least a basic test that verifies that it can play a YouTube video.
from ember-youtube.
The problem
I've run into a problem with this piece of code. I was testing my own component that uses ember-youtube
inside of it and the test below is about changing the currentVideoId
for the player.
test('it should change video by click on the next video button', function (assert) {
assert.expect(1);
this.render(hbs`
{{#v-video-player
isOpen=true
video=videos
currentVideoId=currentVideoId}}
{{/v-video-player}}
`);
this.$('.js-v-video-player__next').click();
assert.equal(this.get('currentVideoId'), this.get('videos')[1].videoId);
});
.js-v-video-player__next
here is a button that switches currentVideoId
to the next video in the list of videos
.
I've tried even this option:
return wait().then(() => {
this.$('.js-v-video-player__next').click();
assert.equal(this.get('currentVideoId'), this.get('videos')[1].videoId);
});
but it works not all the time. Sometimes it fails and I haven't realized what it depends on.
So, logically, firstly it starts initializing the player, but it doesn't finish before ytid
changing and trying to run player initializing one more time.
The Solution
What about to save a promise from loadAndCreatePlayer
to a property and return it every time when loadAndCreatePlayer
is called, but the promise hasn't finished. I'd be looking like this:
loadAndCreatePlayer() {
let isRunning = this.get('loadAndCreatePlayerIsRunning');
if (isRunning) {
// some ember-concurrency would be nice here
return this.get('loadAndCreatePlayerIsRunning');
}
const promise = new RSVP.Promise((resolve, reject) => {
this.loadYouTubeApi().then(() => {
this.createPlayer().then(player => {
this.setProperties({
player,
playerState: 'ready'
});
this.sendAction('playerCreated', player);
this.set('loadAndCreatePlayerIsRunning', false);
resolve();
})
.catch(err => {
if (this.get('showDebug')) {
Ember.debug(err);
}
reject(err);
});
});
});
this.set('loadAndCreatePlayerIsRunning', promise);
// The `wait` helper waits for this run loop,
// but not the above promise, which is what i want.
if (Ember.testing) {
run.later(() => {}, 5000);
}
return promise;
},
In that way, tests pass every time. I'm gonna test this thing a bit more and send a PR with this editings if it's needed.
@oskarrough, what do you think?
from ember-youtube.
@lancedikson very happy that you're looking into it. I think that changes makes sense. Especially when it makes it testable.
I actually started refactoring it with ember-concurrency here https://github.com/oskarrough/ember-youtube/blob/develop/addon/components/ember-youtube.js#L28 to simplify exactly this logic but didn't get to finish it up. Also ended up rewriting much more than I should have in that branch so will have to try again.
from ember-youtube.
@oskarrough great! I guess we still could have my proposed fix as a hotfix and then you can release ember-concurrency implementation whenever it's done, right? I will send a PR today if you agree :)
from ember-youtube.
@lancedikson I think this is now finally fixed… with ember 3.0 there's a test helper waitFor
that can wait for an element to appear. Very handy.
from ember-youtube.
Related Issues (20)
- Automatically stop playback when compontent is removed. Play video when component is added. HOT 4
- Add support for changing isMuted and isPlaying. HOT 2
- Abstract YouTube API using Playtube HOT 1
- Use ember-lazy-video? HOT 3
- Jumping to different timestamps in the video HOT 3
- Update NPM version of ember-youtube HOT 2
- It doesn't work when I switch routes HOT 2
- Different instances of component have mutual playerVars HOT 4
- Full screen? HOT 5
- Don't load YT script if it is already loaded HOT 2
- Raises an exception if the component is destroyed before it initializes. HOT 2
- Can't get ember-youtube to work on iOS safari or chrome HOT 2
- Progress bar won't update on click if video is paused HOT 1
- ember-youtube rises some errors HOT 3
- Move babel to dev-dependencies HOT 2
- sendAction deprication HOT 2
- Switching between multiple videos triggers a widget api error HOT 3
- ember-concurrency should be a dependency HOT 2
- modernize addon HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-youtube.