Skip to content

Commit c3a0693

Browse files
hjdivadcyril-sf
authored andcommitted
Tutorial: YouTube card events.
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'); ```
1 parent a409d3f commit c3a0693

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

example/cards/tutorial/youtube_card.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ Conductor.require('/vendor/jquery.js');
22
Conductor.requireCSS('/example/cards/tutorial/youtube_card.css');
33

44
Conductor.card({
5+
consumers: {
6+
video: Conductor.Oasis.Consumer.extend({
7+
events: {
8+
play: function () {
9+
this.card.loadPlayer().then(function (player) {
10+
player.playVideo();
11+
});
12+
}
13+
}
14+
})
15+
},
16+
517
videoId: null,
618

719
activate: function (data) {
@@ -34,7 +46,7 @@ Conductor.card({
3446
$('#player').show();
3547
break;
3648
default:
37-
throw new Error("Unuspported intent '" + intent + "'");
49+
throw new Error("Unsupported intent '" + intent + "'");
3850
}
3951
},
4052

@@ -102,6 +114,14 @@ Conductor.card({
102114
events: {
103115
onReady: function() {
104116
promise.resolve(player);
117+
},
118+
onStateChange: function (event) {
119+
var playerState = event.data;
120+
if (playerState === YT.PlayerState.ENDED &&
121+
card.consumers.video) {
122+
123+
card.consumers.video.send('videoWatched');
124+
}
105125
}
106126
}
107127
});

example/playground/js/playground.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ window.Playground = {
4343
{ videoId: '4d8ZDSyFS2g'}
4444
);
4545
this.addCard('../cards/tutorial/youtube_card.js', 1, []);
46+
this.addCard('../cards/tutorial/youtube_card.js', 1, ['video']);
4647
}
4748
};
4849

0 commit comments

Comments
 (0)