Listen to session changes
This commit is contained in:
parent
13ba4a7707
commit
e20ab6b708
1 changed files with 17 additions and 9 deletions
26
js/cast.js
26
js/cast.js
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue