export type PlayCommand = 'PlayNow' | 'PlayNext' | 'PlayLast' | 'PlayInstantMix' | 'PlayShuffle'; export type CreateApiSessionsSessionIdPlayingArgs = {sessionId: string, playCommand: PlayCommand, itemIds: Array, startPositionTicks?: (number | null) | undefined}; export type CreateApiSessionsSessionIdPlayingOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; /** * Instructs a session to play an item. * * POST /Sessions/{sessionId}/Playing */ export const createApiSessionsSessionIdPlaying = async (args: CreateApiSessionsSessionIdPlayingArgs, options?: CreateApiSessionsSessionIdPlayingOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.playCommand != null) query.append("playCommand", String(args.playCommand)) for (const item of args.itemIds ?? []) query.append("itemIds", String(item)) if (args.startPositionTicks != null) query.append("startPositionTicks", String(args.startPositionTicks)) if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/Sessions/${encodeURIComponent(String(args.sessionId))}/Playing${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };