Refactor cast JS

This commit is contained in:
Pierre Rudloff 2017-05-09 19:32:39 +02:00
parent 82a1d96c3e
commit a1f4eb6c9d

View file

@ -33,10 +33,10 @@ var castModule = (function () {
function sessionListener(e) { function sessionListener(e) {
session = e; session = e;
session.addMediaListener(onMediaDiscovered.bind(this, 'addMediaListener')); session.addMediaListener(onMediaDiscovered);
session.addUpdateListener(updateListener.bind(this)); session.addUpdateListener(updateListener);
if (session.media.length !== 0) { if (session.media.length !== 0) {
onMediaDiscovered('onRequestSessionSuccess', session.media[0]); onMediaDiscovered();
} }
} }
@ -52,7 +52,7 @@ var castModule = (function () {
function onRequestSessionSuccess(e) { function onRequestSessionSuccess(e) {
session = e; session = e;
var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo); var videoLink = document.getElementById('video_link'), videoURL = videoLink.dataset.video, mediaInfo = new chrome.cast.media.MediaInfo(videoURL, 'video/' + videoLink.dataset.ext), request = new chrome.cast.media.LoadRequest(mediaInfo);
session.loadMedia(request, onMediaDiscovered.bind(this, 'loadMedia'), onMediaError); session.loadMedia(request, onMediaDiscovered, onMediaError);
} }
function onLaunchError(e) { function onLaunchError(e) {
@ -80,7 +80,8 @@ var castModule = (function () {
} }
function initializeCastApi() { function initializeCastApi() {
var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID), apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED); var sessionRequest = new chrome.cast.SessionRequest(chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID),
apiConfig = new chrome.cast.ApiConfig(sessionRequest, sessionListener, receiverListener, chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED);
chrome.cast.initialize(apiConfig, onInitSuccess, onError); chrome.cast.initialize(apiConfig, onInitSuccess, onError);
} }