mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Fix usages of item in location state
This commit is contained in:
parent
5dfefb0518
commit
23c15f8259
6 changed files with 144 additions and 92 deletions
|
@ -1,38 +1,41 @@
|
|||
import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
|
||||
import ServerConnections from 'components/ServerConnections';
|
||||
import { getItemQuery } from 'hooks/useItem';
|
||||
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
||||
import { queryClient } from 'utils/query/queryClient';
|
||||
|
||||
import { playbackManager } from './playbackmanager';
|
||||
|
||||
interface PlaybackInfo {
|
||||
item: BaseItemDto;
|
||||
context?: string;
|
||||
}
|
||||
|
||||
function mirrorItem(info: PlaybackInfo, player?: unknown) {
|
||||
const { item } = info;
|
||||
|
||||
playbackManager.displayContent({
|
||||
ItemName: item.Name,
|
||||
ItemId: item.Id,
|
||||
ItemType: item.Type,
|
||||
Context: info.context
|
||||
}, player);
|
||||
}
|
||||
|
||||
function mirrorIfEnabled(info: PlaybackInfo) {
|
||||
if (info && playbackManager.enableDisplayMirroring()) {
|
||||
async function mirrorIfEnabled(serverId: string, itemId: string) {
|
||||
if (playbackManager.enableDisplayMirroring()) {
|
||||
const playerInfo = playbackManager.getPlayerInfo();
|
||||
|
||||
if (playerInfo && !playerInfo.isLocalPlayer && playerInfo.supportedCommands.indexOf('DisplayContent') !== -1) {
|
||||
mirrorItem(info, playbackManager.getCurrentPlayer());
|
||||
const apiClient = ServerConnections.getApiClient(serverId);
|
||||
const api = toApi(apiClient);
|
||||
const userId = apiClient.getCurrentUserId();
|
||||
|
||||
try {
|
||||
const item = await queryClient.fetchQuery(getItemQuery(
|
||||
api,
|
||||
userId,
|
||||
itemId));
|
||||
|
||||
playbackManager.displayContent({
|
||||
ItemName: item.Name,
|
||||
ItemId: item.Id,
|
||||
ItemType: item.Type
|
||||
}, playbackManager.getCurrentPlayer());
|
||||
} catch (err) {
|
||||
console.error('[DisplayMirrorManager] failed to mirror item', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('viewshow', e => {
|
||||
const state = e.detail.state || {};
|
||||
const { item } = state;
|
||||
if (e.detail?.params?.id && e.detail?.params?.serverId) {
|
||||
const { serverId, id } = e.detail.params;
|
||||
|
||||
if (item?.ServerId) {
|
||||
mirrorIfEnabled({ item });
|
||||
void mirrorIfEnabled(serverId, id);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue