mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Move from components to scripts.
This commit is contained in:
parent
c8c8be39cd
commit
f5311864bc
3 changed files with 2 additions and 2 deletions
49
src/scripts/autocast.js
Normal file
49
src/scripts/autocast.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
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 && 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() {
|
||||
if (!supported()) return;
|
||||
|
||||
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) {
|
||||
events.on(apiClient, 'websocketopen', onOpen);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue