mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
commit
ec44723ee6
6 changed files with 71 additions and 0 deletions
47
src/scripts/autocast.js
Normal file
47
src/scripts/autocast.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
import events from 'events';
|
||||
import playbackManager from 'playbackManager';
|
||||
|
||||
export function supported() {
|
||||
return typeof(Storage) !== 'undefined';
|
||||
}
|
||||
|
||||
export function enable(enabled) {
|
||||
if (!supported()) return;
|
||||
|
||||
if (enabled) {
|
||||
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
||||
|
||||
if (currentPlayerInfo && currentPlayerInfo.id) {
|
||||
localStorage.setItem('autocastPlayerId', currentPlayerInfo.id);
|
||||
}
|
||||
} else {
|
||||
localStorage.removeItem('autocastPlayerId');
|
||||
}
|
||||
}
|
||||
|
||||
export function isEnabled() {
|
||||
if (!supported()) return false;
|
||||
|
||||
const playerId = localStorage.getItem('autocastPlayerId');
|
||||
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
||||
|
||||
return (currentPlayerInfo && playerId && currentPlayerInfo.id === playerId);
|
||||
}
|
||||
|
||||
function onOpen() {
|
||||
const playerId = localStorage.getItem('autocastPlayerId');
|
||||
|
||||
playbackManager.getTargets().then(function (targets) {
|
||||
for (var i = 0; i < targets.length; i++) {
|
||||
if (targets[i].id == playerId) {
|
||||
playbackManager.trySetActivePlayer(targets[i].playerName, targets[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const apiClient = window.connectionManager.currentApiClient();
|
||||
if (apiClient && supported()) {
|
||||
events.on(apiClient, 'websocketopen', onOpen);
|
||||
}
|
|
@ -52,6 +52,7 @@ import 'flexStyles';
|
|||
|
||||
lazyLoadViewMenuBarImages();
|
||||
bindMenuEvents();
|
||||
updateCastIcon();
|
||||
}
|
||||
|
||||
function getCurrentApiClient() {
|
||||
|
@ -1002,6 +1003,7 @@ import 'flexStyles';
|
|||
};
|
||||
|
||||
window.LibraryMenu = LibraryMenu;
|
||||
renderHeader();
|
||||
|
||||
export default LibraryMenu;
|
||||
|
||||
|
|
|
@ -581,6 +581,7 @@ function initClient() {
|
|||
define('webSettings', [scriptsPath + '/settings/webSettings'], returnFirstDependency);
|
||||
define('appSettings', [scriptsPath + '/settings/appSettings'], returnFirstDependency);
|
||||
define('userSettings', [scriptsPath + '/settings/userSettings'], returnFirstDependency);
|
||||
define('autocast', [scriptsPath + '/autocast'], returnFirstDependency);
|
||||
|
||||
define('mediaSession', [componentsPath + '/playback/mediasession'], returnFirstDependency);
|
||||
define('actionsheet', [componentsPath + '/actionSheet/actionSheet'], returnFirstDependency);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue