More updates receiver

This commit is contained in:
Kasper Rynning-Tønnesen
2016-11-18 12:54:22 +01:00
parent c12db4c3bf
commit fece31e31a
4 changed files with 80 additions and 9 deletions

View File

@@ -1,9 +1,17 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<script src="https://www.gstatic.com/cast/js/receiver/1.0/cast_receiver.js"> </script> <script src="https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"> </script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="receiver.js"></script> <script src="receiver.js"></script>
<style>
#player{
width: 100vw;
height: 100vh;
margin-left: -8px;
margin-top: -8px;
}
</style>
</head> </head>
<body> <body>
<div id="wrapper"> <div id="wrapper">

View File

@@ -1,3 +1,48 @@
cast.receiver.logger.setLevelValue(cast.receiver.LoggerLevel.DEBUG);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
/**
* Application config
**/
var appConfig = new cast.receiver.CastReceiverManager.Config();
/**
* Text that represents the application status. It should meet
* internationalization rules as may be displayed by the sender application.
* @type {string|undefined}
**/
appConfig.statusText = 'Ready to play';
/**
* Maximum time in seconds before closing an idle
* sender connection. Setting this value enables a heartbeat message to keep
* the connection alive. Used to detect unresponsive senders faster than
* typical TCP timeouts. The minimum value is 5 seconds, there is no upper
* bound enforced but practically it's minutes before platform TCP timeouts
* come into play. Default value is 10 seconds.
* @type {number|undefined}
**/
// 100 minutes for testing, use default 10sec in prod by not setting this value
appConfig.maxInactivity = 6000;
/**
* Initializes the system manager. The application should call this method when
* it is ready to start receiving messages, typically after registering
* to listen for the events it is interested on.
*/
window.castReceiverManager.start(appConfig);
window.castReceiverManager.onSenderDisconnected = function(event) {
if(window.castReceiverManager.getSenders().length == 0 &&
event.reason == cast.receiver.system.DisconnectReason.REQUESTED_BY_SENDER) {
window.close();
}
}
var customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:super.awesome.example');
customMessageBus.onMessage = function(event) {
console.log(event);
}
/*
var receiver = new cast.receiver.Receiver("E6856E24", ["no.zoff.customcast"],"",5); var receiver = new cast.receiver.Receiver("E6856E24", ["no.zoff.customcast"],"",5);
var ytChannelHandler = new cast.receiver.ChannelHandler("no.zoff.customcast"); var ytChannelHandler = new cast.receiver.ChannelHandler("no.zoff.customcast");
var nextVideo; var nextVideo;
@@ -63,7 +108,7 @@ 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) { function onMessage(event) {
@@ -72,4 +117,4 @@ function onPlayerStateChange(event) {
function endcast() { function endcast() {
setTimeout(window.close, 2000); setTimeout(window.close, 2000);
} }*/

File diff suppressed because one or more lines are too long

View File

@@ -37,6 +37,7 @@ var embed_autoplay = "&autoplay";
var connect_error = false; 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;
if(localStorage.debug === undefined){ if(localStorage.debug === undefined){
var debug = false; var debug = false;
@@ -238,14 +239,24 @@ function init(){
initializeCastApi = function() { initializeCastApi = function() {
cast.framework.CastContext.getInstance().setOptions({ cast.framework.CastContext.getInstance().setOptions({
receiverApplicationId: chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID}); receiverApplicationId: "E6856E24",
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();
//cast.framework.CastSession(castSession);
console.log(castSession);
$(".castButton").toggleClass("hide"); $(".castButton").toggleClass("hide");
$(".castButton-active").toggleClass("hide"); $(".castButton-active").toggleClass("hide");
break; break;
@@ -259,8 +270,15 @@ initializeCastApi = function() {
// Update locally as necessary // Update locally as necessary
break; break;
} }
}) });
$(".castButton").css("display", "inline-block"); 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(){