mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix autocast when already connected
This commit is contained in:
parent
b9925ebf73
commit
2b1f3470f4
1 changed files with 22 additions and 6 deletions
|
@ -2,6 +2,7 @@ import { playbackManager } from '../components/playback/playbackmanager';
|
||||||
import Events from '../utils/events.ts';
|
import Events from '../utils/events.ts';
|
||||||
|
|
||||||
export function enable(enabled) {
|
export function enable(enabled) {
|
||||||
|
console.debug('[autocast] %s cast player', enabled ? 'enabling' : 'disabling');
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
const currentPlayerInfo = playbackManager.getPlayerInfo();
|
||||||
|
|
||||||
|
@ -22,20 +23,35 @@ export function isEnabled() {
|
||||||
|
|
||||||
function onOpen() {
|
function onOpen() {
|
||||||
const playerId = localStorage.getItem('autocastPlayerId');
|
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) {
|
playbackManager.getTargets().then(function (targets) {
|
||||||
for (const target of targets) {
|
console.debug('[autocast] playback targets', targets);
|
||||||
if (target.id == playerId) {
|
|
||||||
playbackManager.trySetActivePlayer(target.playerName, target);
|
const player = targets.find(target => target.id === playerId);
|
||||||
break;
|
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) {
|
export function initialize(apiClient) {
|
||||||
if (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 {
|
} else {
|
||||||
console.warn('[autoCast] cannot initialize missing apiClient');
|
console.warn('[autoCast] cannot initialize missing apiClient');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue