2024-04-30 15:59:48 -04:00
|
|
|
import ServerConnections from 'components/ServerConnections';
|
|
|
|
import { getItemQuery } from 'hooks/useItem';
|
|
|
|
import { toApi } from 'utils/jellyfin-apiclient/compat';
|
|
|
|
import { queryClient } from 'utils/query/queryClient';
|
2023-05-18 11:28:16 -04:00
|
|
|
|
|
|
|
import { playbackManager } from './playbackmanager';
|
|
|
|
|
2024-04-30 15:59:48 -04:00
|
|
|
async function mirrorIfEnabled(serverId: string, itemId: string) {
|
|
|
|
if (playbackManager.enableDisplayMirroring()) {
|
2023-05-18 11:28:16 -04:00
|
|
|
const playerInfo = playbackManager.getPlayerInfo();
|
|
|
|
|
|
|
|
if (playerInfo && !playerInfo.isLocalPlayer && playerInfo.supportedCommands.indexOf('DisplayContent') !== -1) {
|
2024-04-30 15:59:48 -04:00
|
|
|
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);
|
|
|
|
}
|
2023-05-18 11:28:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('viewshow', e => {
|
2024-04-30 15:59:48 -04:00
|
|
|
if (e.detail?.params?.id && e.detail?.params?.serverId) {
|
|
|
|
const { serverId, id } = e.detail.params;
|
2023-05-18 11:28:16 -04:00
|
|
|
|
2024-04-30 15:59:48 -04:00
|
|
|
void mirrorIfEnabled(serverId, id);
|
2023-05-18 11:28:16 -04:00
|
|
|
}
|
|
|
|
});
|