1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #4843 from nielsvanvelzen/nvv-cc-from-user-config

Use cast receiver application from user configuration
This commit is contained in:
Bill Thornton 2023-10-24 17:28:18 -04:00 committed by GitHub
commit d7ccd24094
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 40 deletions

View file

@ -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 += `<option value='${escapeHTML(app.Id)}'>${escapeHTML(app.Name)}</option>`;
}
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 => {
apiClient.getSystemInfo().then(systemInfo => {
userSettings.setUserInfo(userId, apiClient).then(() => {
self.dataLoaded = true;
loadForm(context, user, userSettings, apiClient);
loadForm(context, user, userSettings, systemInfo, apiClient);
});
});
});
}

View file

@ -139,10 +139,7 @@
</div>
<div class="selectContainer">
<select is="emby-select" class="selectChromecastVersion" label="${LabelChromecastVersion}">
<option value="stable">${LabelStable}</option>
<option value="unstable">${LabelUnstable}</option>
</select>
<select is="emby-select" class="selectChromecastVersion" label="${LabelChromecastVersion}"></select>
</div>
<div class="selectContainer">

View file

@ -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,9 +102,15 @@ 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;
if (!applicationID) {
console.warn(`Not initializing chromecast: CastReceiverId is ${applicationID}`);
return;
}
// request session
const sessionRequest = new chrome.cast.SessionRequest(applicationID);
@ -118,6 +120,7 @@ class CastPlayer {
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() {

View file

@ -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.
@ -663,7 +650,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);