Listen to session changes

This commit is contained in:
Pierre Rudloff 2016-06-22 12:50:11 +02:00
parent 13ba4a7707
commit e20ab6b708

View file

@ -16,21 +16,29 @@ function onMediaDiscovered() {
} }
} }
function sessionListener(e) {
'use strict';
session = e;
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
if (session.media.length !== 0) {
onMediaDiscovered('onRequestSessionSuccess', session.media[0]);
}
}
function onStopCast() { function onStopCast() {
'use strict'; 'use strict';
stopBtn.classList.add('cast_hidden'); stopBtn.classList.add('cast_hidden');
launchBtn.classList.remove('cast_hidden'); launchBtn.classList.remove('cast_hidden');
} }
function updateListener() {
'use strict';
if (session.status !== chrome.cast.SessionStatus.CONNECTED) {
onStopCast();
}
}
function sessionListener(e) {
'use strict';
session = e;
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener'));
session.addUpdateListener(updateListener.bind(this));
if (session.media.length !== 0) {
onMediaDiscovered('onRequestSessionSuccess', session.media[0]);
}
}
function stopCast() { function stopCast() {
'use strict'; 'use strict';
session.stop(onStopCast); session.stop(onStopCast);