-
Notifications
You must be signed in to change notification settings - Fork 3
/
receiver.js
45 lines (42 loc) · 1.24 KB
/
receiver.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
/**
* @fileOverview Code needed by the HTML Slidy receiver application to
* listen to messages from the presentation sender and react accordingly,
* dispatching received commands to the controlled slide show.
*/
window.onload = function () {
/**
* Pointer to the "w3c_slidy" object in controlled slideshow
*/
var controlledSlidy = null;
/**
* The controlled slideshow is displayed in a child iframe
*/
var iframe = document.querySelector('iframe');
iframe.onload = function () {
controlledSlidy = iframe.contentWindow.w3c_slidy;
};
/**
* React to the establishment of a new session
*/
navigator.presentation.onpresent = function (event) {
var presentationSession = event.session;
presentationSession.onmessage = function (message) {
var params = null;
if (!message || !message.cmd) {
return;
}
if (message.cmd === 'open') {
console.info('open slideshow at "' + message.url + '"');
iframe.src = message.url;
}
else if (!controlledSlidy) {
return;
}
else {
// Send command to controlled Slidy instance
params = message.params || [];
controlledSlidy[message.cmd].apply(controlledSlidy, params);
}
};
};
};