Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <style type="text/css">
- body {
- overflow:hidden;
- }
- div{
- height:720PX;
- width:1280PX;
- text-align:center;
- border:0px solid silver;
- display: table-cell;
- vertical-align:middle;
- color:#FFFFFF;
- background-color:#000000;
- font-weight:bold;
- font-family:Trebuchet MS, sans-serif;
- font-size:40px;
- }
- </style>
- <title>Example minimum receiver</title>
- <script src="//www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
- </head>
- <body>
- <div id="question"></div>
- <script>
- window.onload = function() {
- cast.receiver.logger.setLevelValue(0);
- window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
- console.log('Starting Receiver Manager');
- // handler for the 'ready' event
- castReceiverManager.onReady = function(event) {
- console.log('Received Ready event: ' + JSON.stringify(event.data));
- window.castReceiverManager.setApplicationState("Application status is ready...");
- };
- // handler for 'senderconnected' event
- castReceiverManager.onSenderConnected = function(event) {
- console.log('Received Sender Connected event: ' + event.data);
- console.log(window.castReceiverManager.getSender(event.data).userAgent);
- };
- // handler for 'senderdisconnected' event
- castReceiverManager.onSenderDisconnected = function(event) {
- console.log('Received Sender Disconnected event: ' + event.data);
- if (window.castReceiverManager.getSenders().length == 0) {
- window.close();
- }
- };
- // handler for 'systemvolumechanged' event
- castReceiverManager.onSystemVolumeChanged = function(event) {
- console.log('Received System Volume Changed event: ' + event.data['level'] + ' ' +
- event.data['muted']);
- };
- // create a CastMessageBus to handle messages for a custom namespace
- window.messageBus =
- window.castReceiverManager.getCastMessageBus(
- 'urn:x-cast:super.awesome.example');
- // handler for the CastMessageBus message event
- //Receives a JSON object
- window.messageBus.onMessage = function(event) {
- console.log('Message [' + event.senderId + ']: ' + event.data);
- // display the message from the sender
- displayText(event.data);
- // inform all senders on the CastMessageBus of the incoming message event
- // sender message listener will be invoked
- window.messageBus.send(event.senderId, event.data);
- }
- // initialize the CastReceiverManager with an application status message
- window.castReceiverManager.start({statusText: "Application is starting"});
- console.log('Receiver Manager started');
- };
- // utility function to display the text message in the input field
- function displayText(text) {
- console.log(text);
- document.getElementById("question").innerHTML=text;
- window.castReceiverManager.setApplicationState(text);
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement