Created
May 9, 2014 06:03
-
-
Save kevinthecity/0086873ced0a4c8a78e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Copyright (C) 2014 Google Inc. All Rights Reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software | |
distributed under the License is distributed on an "AS IS" BASIS, | |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
See the License for the specific language governing permissions and | |
limitations under the License. | |
--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
body { | |
overflow:hidden; | |
padding:35px; | |
} | |
div{ | |
height:720PX; | |
width:1280PX; | |
text-align:center; | |
border:0px solid silver; | |
display: table-cell; | |
vertical-align:middle; | |
color:#FFFFFF; | |
font-weight:bold; | |
font-family:Verdana, Geneva, sans-serif; | |
font-size:40px; | |
} | |
</style> | |
<title>Cast Hello Text</title> | |
</head> | |
<body> | |
<div id="message"></div> | |
<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() { | |
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:com.phamousapps.chromecastlikes'); | |
// handler for the CastMessageBus message event | |
window.messageBus.onMessage = function(event) { | |
console.log('Message [' + event.senderId + ']: ' + event.data); | |
var jsonData = JSON.parse(event.data); | |
if(jsonData.type === "photo"){ | |
displayPhotoPost(jsonData.src); | |
} else if (jsonData.type === "text") { | |
displayText(jsonData.src); | |
} else if (jsonData.type === "video") { | |
displayVideo(jsonData.src); | |
} else if (jsonData.type === "chat") { | |
displayChatPost(jsonData.src); | |
} else if (jsonData.type === "quote") { | |
displayQuotePost(jsonData.src); | |
} else if (jsonData.type === "quote") { | |
displayQuotePost(jsonData.src); | |
} else if (jsonData.type === "audio") { | |
displayAudio(jsonData.src); | |
} | |
// 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); | |
setBackgroundColor("#c4c4c4"); | |
document.getElementById("message").innerHTML=text; | |
window.castReceiverManager.setApplicationState(text); | |
}; | |
// utility function to display the text message in the input field | |
function displayQuotePost(text) { | |
console.log(text); | |
setBackgroundColor("#f2992e"); | |
document.getElementById("message").innerHTML=text; | |
window.castReceiverManager.setApplicationState(text); | |
}; | |
// utility function to display the text message in the input field | |
function displayChatPost(text) { | |
console.log(text); | |
setBackgroundColor("#37aad4"); | |
document.getElementById("message").innerHTML=text; | |
window.castReceiverManager.setApplicationState(text); | |
}; | |
// utility function to display the text message in the input field | |
function displayPhotoPost(text) { | |
console.log(text); | |
setBackgroundColor("#d95e40"); | |
// document.getElementById("message").innerHTML='<img src="' + text + '">'; | |
document.getElementById("message").innerHTML=""; | |
var el = document.getElementById("message"); | |
el.styles["background-image"]="url(" + text + ")"; | |
el.styles["background-size"]="contains"; | |
el.styles["height"]="100%"; | |
el.styles["width"]="100%"; | |
// el.styles["display"]="none"; | |
// el.styles["display"]="block"; | |
window.castReceiverManager.setApplicationState(text); | |
}; | |
// utility function to display the text message in the input field | |
function displayVideo(text) { | |
console.log(text); | |
setBackgroundColor("#748089"); | |
document.getElementById("message").innerHTML=text; | |
window.castReceiverManager.setApplicationState(text); | |
} | |
// utility function to display the text message in the input field | |
function displayAudio(text) { | |
console.log(text); | |
setBackgroundColor("#ac7ebe"); | |
document.getElementById("message").innerHTML=text; | |
window.castReceiverManager.setApplicationState(text); | |
} | |
function setBackgroundColor(color){ | |
document.body.style.background = color; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment