Updating receiver

This commit is contained in:
Kasper Rynning-Tønnesen
2016-11-18 13:06:29 +01:00
parent a4a41f1e59
commit 40b552dc49
3 changed files with 11 additions and 30 deletions

View File

@@ -3,7 +3,7 @@ cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance(); window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
var customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:zoff.no'); var customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:zoff.no');
customMessageBus.onMessage = function(event) { customMessageBus.onMessage = function(event) {
console.log(event); ytMessages[event.message.type](event);
} }
/** /**
* Application config * Application config
@@ -54,7 +54,7 @@ ytChannelHandler.addEventListener(
); );
receiver.start(); receiver.start();
*/
window.addEventListener('load', function() { window.addEventListener('load', function() {
var tag = document.createElement('script'); var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api"; tag.src = "https://www.youtube.com/iframe_api";
@@ -107,15 +107,7 @@ function onPlayerReady() {
function onPlayerStateChange(event) { function onPlayerStateChange(event) {
channel.send({'event':'stateChange','message':event.data}); channel.send({'event':'stateChange','message':event.data});
/*if (event.data==YT.PlayerState.ENDED) { if (event.data==YT.PlayerState.ENDED) {
endcast(); endcast();
} }
} }
function onMessage(event) {
ytMessages[event.message.type](event);
}
function endcast() {
setTimeout(window.close, 2000);
}*/

File diff suppressed because one or more lines are too long

View File

@@ -38,6 +38,7 @@ var connect_error = false;
var access_token_data_youtube = {}; var access_token_data_youtube = {};
var youtube_authenticated = false; var youtube_authenticated = false;
var chromecastAvailable = false; var chromecastAvailable = false;
var castSession;
if(localStorage.debug === undefined){ if(localStorage.debug === undefined){
var debug = false; var debug = false;
@@ -241,22 +242,17 @@ initializeCastApi = function() {
cast.framework.CastContext.getInstance().setOptions({ cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: "E6856E24", receiverApplicationId: "E6856E24",
autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}); autoJoinPolicy: chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED});
//var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
//console.log(castSession);
var context = cast.framework.CastContext.getInstance(); var context = cast.framework.CastContext.getInstance();
context.addEventListener( context.addEventListener(
cast.framework.CastContextEventType.SESSION_STATE_CHANGED, cast.framework.CastContextEventType.SESSION_STATE_CHANGED,
function(event) { function(event) {
console.log(event); console.log(event);
switch (event.sessionState) { switch (event.sessionState) {
case cast.framework.SessionState.SESSION_STARTING:
var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
console.log(castSession);
break;
case cast.framework.SessionState.SESSION_STARTED: case cast.framework.SessionState.SESSION_STARTED:
var castSession = cast.framework.CastContext.getInstance().getCurrentSession(); castSession = cast.framework.CastContext.getInstance().getCurrentSession();
window.castSession = cast.framework.CastContext.getInstance().getCurrentSession();
chromecastAvailable = true;
//cast.framework.CastSession(castSession); //cast.framework.CastSession(castSession);
console.log(castSession);
$(".castButton").toggleClass("hide"); $(".castButton").toggleClass("hide");
$(".castButton-active").toggleClass("hide"); $(".castButton-active").toggleClass("hide");
break; break;
@@ -265,20 +261,13 @@ initializeCastApi = function() {
$(".castButton-active").toggleClass("hide"); $(".castButton-active").toggleClass("hide");
break; break;
case cast.framework.SessionState.SESSION_ENDED: case cast.framework.SessionState.SESSION_ENDED:
chromecastAvailable = false;
$(".castButton").toggleClass("hide"); $(".castButton").toggleClass("hide");
$(".castButton-active").toggleClass("hide"); $(".castButton-active").toggleClass("hide");
// Update locally as necessary // Update locally as necessary
break; break;
} }
}); });
console.log(context);
console.log("asd");
if(context.L == "NOT_CONNECTED"){
//$(".castButton").css("display", "inline-block");
var castSession = cast.framework.CastContext.getInstance().getCurrentSession();
console.log("hello");
console.log(castSession);
}
}; };
function setup_no_connection_listener(){ function setup_no_connection_listener(){