Skip to content

Commit

Permalink
Tutorial: YouTube card events.
Browse files Browse the repository at this point in the history
One can send events from the playground via:
```js
Playground.conductor.cards['../cards/tutorial/youtube_card.js'][1][0].sandbox.videoPort.send('play');

// we add the video port to the window for convenience in the tutorial
window.videoPort.send('play');
```
  • Loading branch information
hjdivad authored and cyril-sf committed Dec 13, 2013
1 parent a409d3f commit c3a0693
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 21 additions & 1 deletion example/cards/tutorial/youtube_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ Conductor.require('/vendor/jquery.js');
Conductor.requireCSS('/example/cards/tutorial/youtube_card.css');

Conductor.card({
consumers: {
video: Conductor.Oasis.Consumer.extend({
events: {
play: function () {
this.card.loadPlayer().then(function (player) {
player.playVideo();
});
}
}
})
},

videoId: null,

activate: function (data) {
Expand Down Expand Up @@ -34,7 +46,7 @@ Conductor.card({
$('#player').show();
break;
default:
throw new Error("Unuspported intent '" + intent + "'");
throw new Error("Unsupported intent '" + intent + "'");
}
},

Expand Down Expand Up @@ -102,6 +114,14 @@ Conductor.card({
events: {
onReady: function() {
promise.resolve(player);
},
onStateChange: function (event) {
var playerState = event.data;
if (playerState === YT.PlayerState.ENDED &&
card.consumers.video) {

card.consumers.video.send('videoWatched');
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions example/playground/js/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ window.Playground = {
{ videoId: '4d8ZDSyFS2g'}
);
this.addCard('../cards/tutorial/youtube_card.js', 1, []);
this.addCard('../cards/tutorial/youtube_card.js', 1, ['video']);
}
};

Expand Down

0 comments on commit c3a0693

Please sign in to comment.