export type PlaystateCommand = 'Stop' | 'Pause' | 'Unpause' | 'NextTrack' | 'PreviousTrack' | 'Seek' | 'Rewind' | 'FastForward' | 'PlayPause'; export type CreateApiSessionsSessionIdPlayingCommandArgs = {sessionId: string, command: PlaystateCommand, seekPositionTicks?: (number | null) | undefined, controllingUserId?: (string | null) | undefined}; export type CreateApiSessionsSessionIdPlayingCommandOptions = {baseUrl?: string | undefined, CustomAuthentication?: string | undefined, fetch?: typeof fetch | undefined}; /** * Issues a playstate command to a client. * * POST /Sessions/{sessionId}/Playing/{command} */ export const createApiSessionsSessionIdPlayingCommand = async (args: CreateApiSessionsSessionIdPlayingCommandArgs, options?: CreateApiSessionsSessionIdPlayingCommandOptions) => { const {baseUrl = "http://localhost", fetch: fetchFn = fetch, CustomAuthentication} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.seekPositionTicks != null) query.append("seekPositionTicks", String(args.seekPositionTicks)) if (args.controllingUserId != null) query.append("controllingUserId", String(args.controllingUserId)) if (CustomAuthentication !== undefined) headers.set("X-Emby-Authorization", CustomAuthentication) const url = `${baseUrl.replace(/\/+$/, '')}/Sessions/${encodeURIComponent(String(args.sessionId))}/Playing/${encodeURIComponent(String(args.command))}${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 };