On Github macdonst / OttawaJSChromeCast
Chromecast is a thumb-sized media streaming device that plugs into the HDMI port on your TV. Set it up with a simple mobile app, then send your favourite online shows, movies, music and more to your TV using your smartphone, tablet or laptop.
Sender Applications
Receiver Applications
<script type="text/javascript" src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script>
window['__onGCastApiAvailable'] = function(loaded, errorInfo) { if (loaded) { initializeCastApi(); } else { console.log(errorInfo); } }
initializeCastApi = function() { var sessionRequest = new chrome.cast.SessionRequest( chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID); var apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener); chrome.cast.initialize(apiConfig, onInitSuccess, onError); };
receiverListener = function (e) { if( e === chrome.cast.ReceiverAvailability.AVAILABLE) { console.log("Woohoo!"); } else { console.log("Doh!"); } }
startApp = function () { console.log("starting app..."); chrome.cast.requestSession(onRequestSessionSuccess, onLaunchError); } onRequestSessionSuccess = function (e) { session = e; }
var mediaInfo = new chrome.cast.media.MediaInfo(currentMediaURL); var request = new chrome.cast.media.LoadRequest(mediaInfo); session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); function onMediaDiscovered(how, media) { currentMedia = media; }
stopApp = function () { session.stop(onSuccess, onError); }