UNPKG

@msquared/pixel-streaming-client

Version:

Browser client for viewing pixel-streamed content from MSquared events

141 lines 5.38 kB
/** * This is the minimal code and types needed to fetch Sessions from Morpheus Platform. * * The `sessionManager.clientFetch` code has been minimally reimplemeted in the * `doFetch` method and any of it's required external data is passed into the * SessionClient constructor. It has significantly less robust error handling, * however as the usage code just returns `undefined` on any error, we don't * need the all of that functionaily _yet_. * * @module */ import type { StreamProvider } from "./client"; import type { Fetch, Logger, Token } from "./types"; export declare enum SessionState { Queued = "QUEUED",// Session is new and waiting in a queue with other Sessions. Admitted = "ADMITTED",// Session has been manually admitted, pending available capacity. Ready = "READY",// Session is clear to join the deployment; capacity is available. Pending = "PENDING",// Session is awaiting a streaming slot. Active = "ACTIVE",// Session is connected to the deployment and/or has streaming configuration data. Replaced = "REPLACED",// Session has been replaced by a newer session for the same user. Expired = "EXPIRED",// Session expired. Failed = "FAILED",// Session failed unrecoverably. Deleted = "DELETED" } type PostSessionRequest = { streamId: string; metadata: { browserName: string; browserVersion: number; osName: string; deviceModel: string; deviceType: string; ubitusSupported: boolean; geforceSupported: boolean; forceProvider?: StreamProvider; }; }; export type GeforceStreamConfig = { name: StreamProvider.GeforceNow; cmsId: string; nonce: string; redirect: string; partnerId: string; zone?: string; state?: string; windowed?: boolean; sessionId: string; }; export type UbitusStreamConfig = { name: StreamProvider.Ubitus; keepAlivePath?: string; launcherToken: string; gameLabel: string; token: string; server: string; gameChannel: string; sessionId: string; }; export type StreamConfig = GeforceStreamConfig | UbitusStreamConfig; export type Session = { sessionId: string; state: string; providerConfig?: StreamConfig; }; export type FetchSessionConfigParameters = { projectId: string; streamId: string; sessionMetadata: PostSessionRequest["metadata"]; worldId?: string; onStateChange?: (state: SessionState) => void; }; export type SessionClientOptions = { organizationId?: string; fetch?: Fetch; host?: string; protocol?: "http" | "https"; token?: Token; logger?: Logger; }; export declare class SessionClient { private organizationId?; private token?; private fetch; private logger; private baseURL?; constructor(opts: SessionClientOptions); /** * Refreshes an existing Session. This should be called on a regular basis until the session state becomes `READY`, * at which point the streaming configuration data will be available. * * @param projectId The Project ID for the current project. * @param worldId The World ID for the current session. * @param sessionId The Session ID for the current session. * * @return The refreshed Session object, or undefined if the session could not be refreshed. */ private refreshSession; /** * Handles polling of a session until it reaches a useable or failed state. Retries every few seconds. * * @param projectId The Project ID for the current project. * @param worldId The World ID for the current session. * @param sessionId The Session ID for the current session. * @param onStateChange An optional callback that will be provided with session state values. * * @return The Session object, or undefined if the session could not be created. */ private pollSession; /** * Creates a Session configuration; may create a World-scoped session if the World ID is supplied _and_ the backend * allows it. * * @param projectId The Project ID for the current project. * @param streamId The Stream ID for the current session. * @param sessionMetadata The metadata for the current session. * @param worldId The optional World ID for the current session. * @param onStateChange An optional callback that will be provided with session state values. * * @return The Session object, or undefined if the session could not be created. */ createSession({ projectId, streamId, sessionMetadata, worldId, onStateChange, }: FetchSessionConfigParameters): Promise<Session | undefined>; /** * Deletes an existing Session. * * @param projectId The Project ID for the current project. * @param worldId The World ID for the current session. * @param sessionId The Session ID for the current session. * @param deletionReason An optional reason for the deletion, for example an error code from the streaming provider. * * @return Undefined on success. */ deleteSession({ projectId, worldId, sessionId, deletionReason, }: { projectId: string; worldId: string; sessionId: string; deletionReason?: string; }): Promise<undefined>; private doFetch; } export {}; //# sourceMappingURL=session.d.ts.map