mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-15 18:08:17 -07:00
Merge pull request #6013 from thornbill/fix-autocast-maybe
Fix autocast when already connected
This commit is contained in:
commit
a1721ddd17
@ -2,6 +2,7 @@ import { playbackManager } from '../components/playback/playbackmanager';
|
||||
import Events from '../utils/events.ts';
|
||||
|
||||
export function enable(enabled) {
|
||||
console.debug('[autocast] %s cast player', enabled ? 'enabling' : 'disabling');
|
||||
if (enabled) {
|
||||
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
||||
|
||||
@ -22,20 +23,35 @@ export function isEnabled() {
|
||||
|
||||
function onOpen() {
|
||||
const playerId = localStorage.getItem('autocastPlayerId');
|
||||
if (!playerId) {
|
||||
console.debug('[autocast] no active cast player');
|
||||
return;
|
||||
}
|
||||
|
||||
console.debug('[autocast] initializing cast player', playerId);
|
||||
|
||||
playbackManager.getTargets().then(function (targets) {
|
||||
for (const target of targets) {
|
||||
if (target.id == playerId) {
|
||||
playbackManager.trySetActivePlayer(target.playerName, target);
|
||||
break;
|
||||
}
|
||||
console.debug('[autocast] playback targets', targets);
|
||||
|
||||
const player = targets.find(target => target.id === playerId);
|
||||
if (player) {
|
||||
console.debug('[autocast] found target player', player);
|
||||
playbackManager.trySetActivePlayer(player.playerName, player);
|
||||
} else {
|
||||
console.debug('[autocast] selected cast player not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function initialize(apiClient) {
|
||||
if (apiClient) {
|
||||
Events.on(apiClient, 'websocketopen', onOpen);
|
||||
if (apiClient.isWebSocketOpen()) {
|
||||
console.debug('[autoCast] connection ready');
|
||||
onOpen();
|
||||
} else {
|
||||
console.debug('[autoCast] initializing connection listener');
|
||||
Events.on(apiClient, 'websocketopen', onOpen);
|
||||
}
|
||||
} else {
|
||||
console.warn('[autoCast] cannot initialize missing apiClient');
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user