forked from DeMille/url-cast-receiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceiver.html
58 lines (46 loc) · 1.94 KB
/
receiver.html
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
<!DOCTYPE html>
<html>
<head>
<title>URL Cast Receiver</title>
<style type='text/css'>
html, body {width: 100%; height: 100%; padding: 0; margin: 0;}
body {overflow:hidden; background: #FFF;}
#iframe {width: 100%; height: 100%;}
</style>
</head>
<body>
<iframe src='' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' seamless='seamless' id='iframe'></iframe>
<script type='text/javascript' src='//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js'></script>
<script type='text/javascript'>
window.onload = function() {
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
castReceiverManager.onReady = function(event) {
window.castReceiverManager.setApplicationState('URL Cast ready...');
};
// messages on a custom namespace
var ns = 'urn:x-cast:com.url.cast';
window.messageBus = window.castReceiverManager.getCastMessageBus(ns);
window.messageBus.onMessage = function(e) {
var msg = JSON.parse(e.data);
window.messageBus.send(e.senderId, 'ok');
if (msg.type === 'iframe') updateFrame(msg.url);
if (msg.type === 'loc') updateLocation(msg.url);
};
// initialize CastReceiverManager
window.castReceiverManager.start({statusText: 'URL Cast starting...'});
};
// Update the iframe src
// warning: watch out for X-Frame-Options -> DENY
function updateFrame(url) {
window.castReceiverManager.setApplicationState('Now Playing: ' + url);
document.getElementById('iframe').src = url;
}
// Set the window location to the URL
// warning: this reciever dies essentially, because you navigated away
function updateLocation(url) {
window.castReceiverManager.setApplicationState('Now Playing: ' + url);
window.location.href = url;
}
</script>
</body>
</html>