From 7c9c38d6828c9b9ea028a4146e92a06a77cdbc9d Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Thu, 5 Oct 2023 18:08:30 +0200 Subject: [PATCH 1/2] Use cast receiver application from user configuration --- src/plugins/chromecastPlayer/plugin.js | 43 ++++++++++++++++---------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/plugins/chromecastPlayer/plugin.js b/src/plugins/chromecastPlayer/plugin.js index c4c90c15b..59950b60d 100644 --- a/src/plugins/chromecastPlayer/plugin.js +++ b/src/plugins/chromecastPlayer/plugin.js @@ -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 { @@ -98,6 +93,7 @@ class CastPlayer { initializeCastPlayer() { const chrome = window.chrome; if (!chrome) { + console.warn('Not initializing chromecast: chrome object is missing'); return; } @@ -106,18 +102,25 @@ 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(); - // request session - const sessionRequest = new chrome.cast.SessionRequest(applicationID); - const apiConfig = new chrome.cast.ApiConfig(sessionRequest, - this.sessionListener.bind(this), - this.receiverListener.bind(this)); + apiClient.getUser(userId).then(user => { + const applicationID = user.Configuration.CastReceiverId; + if (!applicationID) { + console.warn(`Not initializing chromecast: CastReceiverId is ${applicationID}`); + return; + } - console.debug(`chromecast.initialize (applicationId=${applicationID})`); - chrome.cast.initialize(apiConfig, this.onInitSuccess.bind(this), this.errorHandler); + // 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); + }); } /** @@ -584,7 +587,15 @@ class ChromecastPlayer { this.isLocalPlayer = false; this.lastPlayerData = {}; - new CastSenderApi().load().then(initializeChromecast.bind(this)); + new CastSenderApi().load().then(() => { + Events.on(ServerConnections, 'localusersignedin', () => { + initializeChromecast.call(this); + }); + + if (ServerConnections.currentUserId) { + initializeChromecast.call(this); + } + }); } tryPair() { From 922244263c64388972a45eee9747f7eccbedecb0 Mon Sep 17 00:00:00 2001 From: Niels van Velzen Date: Sun, 15 Oct 2023 11:36:35 +0200 Subject: [PATCH 2/2] Update playback settings to use CastReceiverId --- .../playbackSettings/playbackSettings.js | 20 +++++++++++++------ .../playbackSettings.template.html | 5 +---- src/scripts/settings/userSettings.js | 14 ------------- 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/components/playbackSettings/playbackSettings.js b/src/components/playbackSettings/playbackSettings.js index 0e3a798b6..91d771a59 100644 --- a/src/components/playbackSettings/playbackSettings.js +++ b/src/components/playbackSettings/playbackSettings.js @@ -10,6 +10,7 @@ import '../../elements/emby-checkbox/emby-checkbox'; import ServerConnections from '../ServerConnections'; import toast from '../toast/toast'; import template from './playbackSettings.template.html'; +import escapeHTML from 'escape-html'; function fillSkipLengths(select) { const options = [5, 10, 15, 20, 25, 30]; @@ -136,7 +137,7 @@ function showHideQualityFields(context, user, apiClient) { }); } -function loadForm(context, user, userSettings, apiClient) { +function loadForm(context, user, userSettings, systemInfo, apiClient) { const loggedInUserId = apiClient.getCurrentUserId(); const userId = user.Id; @@ -186,7 +187,12 @@ function loadForm(context, user, userSettings, apiClient) { fillChromecastQuality(context.querySelector('.selectChromecastVideoQuality')); const selectChromecastVersion = context.querySelector('.selectChromecastVersion'); - selectChromecastVersion.value = userSettings.chromecastVersion(); + let ccAppsHtml = ''; + for (const app of systemInfo.CastReceiverApplications) { + ccAppsHtml += ``; + } + selectChromecastVersion.innerHTML = ccAppsHtml; + selectChromecastVersion.value = user.Configuration.CastReceiverId; const selectLabelMaxVideoWidth = context.querySelector('.selectLabelMaxVideoWidth'); selectLabelMaxVideoWidth.value = appSettings.maxVideoWidth(); @@ -222,7 +228,7 @@ function saveUser(context, user, userSettingsInstance, apiClient) { userSettingsInstance.enableNextVideoInfoOverlay(context.querySelector('.chkEnableNextVideoOverlay').checked); user.Configuration.RememberAudioSelections = context.querySelector('.chkRememberAudioSelections').checked; user.Configuration.RememberSubtitleSelections = context.querySelector('.chkRememberSubtitleSelections').checked; - userSettingsInstance.chromecastVersion(context.querySelector('.selectChromecastVersion').value); + user.Configuration.CastReceiverId = context.querySelector('.selectChromecastVersion').value; userSettingsInstance.skipForwardLength(context.querySelector('.selectSkipForwardLength').value); userSettingsInstance.skipBackLength(context.querySelector('.selectSkipBackLength').value); @@ -329,10 +335,12 @@ class PlaybackSettings { const userSettings = self.options.userSettings; apiClient.getUser(userId).then(user => { - userSettings.setUserInfo(userId, apiClient).then(() => { - self.dataLoaded = true; + apiClient.getSystemInfo().then(systemInfo => { + userSettings.setUserInfo(userId, apiClient).then(() => { + self.dataLoaded = true; - loadForm(context, user, userSettings, apiClient); + loadForm(context, user, userSettings, systemInfo, apiClient); + }); }); }); } diff --git a/src/components/playbackSettings/playbackSettings.template.html b/src/components/playbackSettings/playbackSettings.template.html index 44dfe85e0..e326182e6 100644 --- a/src/components/playbackSettings/playbackSettings.template.html +++ b/src/components/playbackSettings/playbackSettings.template.html @@ -138,10 +138,7 @@
- +
diff --git a/src/scripts/settings/userSettings.js b/src/scripts/settings/userSettings.js index 9dc065621..0092d3bdf 100644 --- a/src/scripts/settings/userSettings.js +++ b/src/scripts/settings/userSettings.js @@ -338,19 +338,6 @@ export class UserSettings { return this.get('datetimelocale', false); } - /** - * Get or set Chromecast version. - * @param {string|undefined} val - Chromecast version. - * @return {string} Chromecast version. - */ - chromecastVersion(val) { - if (val !== undefined) { - return this.set('chromecastVersion', val.toString()); - } - - return this.get('chromecastVersion') || 'stable'; - } - /** * Get or set amount of rewind. * @param {number|undefined} val - Amount of rewind. @@ -648,7 +635,6 @@ export const detailsBanner = currentSettings.detailsBanner.bind(currentSettings) export const useEpisodeImagesInNextUpAndResume = currentSettings.useEpisodeImagesInNextUpAndResume.bind(currentSettings); export const language = currentSettings.language.bind(currentSettings); export const dateTimeLocale = currentSettings.dateTimeLocale.bind(currentSettings); -export const chromecastVersion = currentSettings.chromecastVersion.bind(currentSettings); export const skipBackLength = currentSettings.skipBackLength.bind(currentSettings); export const skipForwardLength = currentSettings.skipForwardLength.bind(currentSettings); export const dashboardTheme = currentSettings.dashboardTheme.bind(currentSettings);