Skip to content

Commit

Permalink
Use cast receiver application from user configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Oct 5, 2023
1 parent f7507fb commit 8a6e3d5
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/plugins/chromecastPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ const PLAYER_STATE = {
'ERROR': 'ERROR'
};

// production version registered with google
// replace this value if you want to test changes on another instance
const applicationStable = 'F007D354';
const applicationUnstable = '6F511C87';

const messageNamespace = 'urn:x-cast:com.connectsdk';

class CastPlayer {
Expand Down Expand Up @@ -106,18 +101,21 @@ class CastPlayer {
return;
}

let applicationID = userSettings.chromecastVersion();
if (applicationID === 'stable') applicationID = applicationStable;
if (applicationID === 'unstable') applicationID = applicationUnstable;
const apiClient = ServerConnections.currentApiClient();
const userId = apiClient.getCurrentUserId();

apiClient.getUser(userId).then(user => {
const applicationID = user.Configuration.CastReceiverId;

// request session
const sessionRequest = new chrome.cast.SessionRequest(applicationID);
const apiConfig = new chrome.cast.ApiConfig(sessionRequest,
this.sessionListener.bind(this),
this.receiverListener.bind(this));
// request session
const sessionRequest = new chrome.cast.SessionRequest(applicationID);
const apiConfig = new chrome.cast.ApiConfig(sessionRequest,
this.sessionListener.bind(this),
this.receiverListener.bind(this));

console.debug(`chromecast.initialize (applicationId=${applicationID})`);
chrome.cast.initialize(apiConfig, this.onInitSuccess.bind(this), this.errorHandler);
console.debug(`chromecast.initialize (applicationId=${applicationID})`);
chrome.cast.initialize(apiConfig, this.onInitSuccess.bind(this), this.errorHandler);
});
}

/**
Expand Down Expand Up @@ -584,7 +582,15 @@ class ChromecastPlayer {
this.isLocalPlayer = false;
this.lastPlayerData = {};

new CastSenderApi().load().then(initializeChromecast.bind(this));
new CastSenderApi().load().then(() => {
if (ServerConnections.currentUserId) {
initializeChromecast.call(this);
} else {
Events.on(ServerConnections, 'localusersignedin', () => {
initializeChromecast.call(this);
});
}
});
}

tryPair() {
Expand Down

0 comments on commit 8a6e3d5

Please sign in to comment.