-
Notifications
You must be signed in to change notification settings - Fork 5
/
subscribedEvents.js
60 lines (50 loc) · 1.49 KB
/
subscribedEvents.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// All custom Events subscribes
(function(player, pubSub, speechRecog) {
// Custom Events for the YouTube player that can be used to override a youtube event
pubSub.subscribe('readyOverride', function(){})
pubSub.subscribe('stateChangeOverride', function(){})
pubSub.subscribe('errorOverride', function(){})
pubSub.subscribe('playbackQualityChangeOverride', function(){})
pubSub.subscribe('playbackRateChangeOverride', function(){})
// Custom Events for the YouTube player to do basic actions like play/pause/stop
pubSub.subscribe('play', function() {
player.playVideo()
})
pubSub.subscribe('pause', function() {
player.pauseVideo()
})
pubSub.subscribe('stop', function() {
player.stopVideo()
})
pubSub.subscribe('ended', function() {
console.log('video has finished playing')
})
// Custom Events for speech Recognition
pubSub.subscribe('speechRecogResults', function(finalWords) {
var strng = speechRecog.trim(finalWords.transcript)
if (finalWords.confidence >= 0.4 ) {
console.log('Computer heard: "' + strng + '"')
} else {
console.log('Did you say: "' + strng + '?"')
}
switch(speechRecog.matchWord(finalWords.transcript, strng)) {
case 'play' : {
pubSub.on('play')
}
break;
case 'POS' :
case 'pause' : {
pubSub.on('pause')
}
break;
case 'stop' : {
pubSub.on('stop')
}
break;
default : {
console.log('No handler for the word(s): ' + strng)
}
break;
}
})
})(window.APP.instance, window.APP.pubSub, window.APP.rg)