UNPKG

fcr-core

Version:

Core APIs for building online scenes

77 lines (76 loc) 2.54 kB
import { FcrPeerSessionParamsSchema } from '../schema'; import { FcrSessionBase, FcrSessionResponse } from '../type'; export interface FcrPeerSessionControl { /** * Start a new peer session. */ startPeerSession(params: FcrPeerSessionParams): Promise<string>; /** * Stop the current peer session. */ stopPeerSession(sessionId: string): boolean; /** * End the current peer session. */ endPeerSession(sessionId: string, cause?: Record<string, unknown>): Promise<void>; /** * Accept an incoming peer session. */ acceptPeerSession(session: FcrPeerSession, cause?: Record<string, unknown>): Promise<void>; /** * Reject an incoming peer session. */ rejectPeerSession(session: FcrPeerSession, cause?: Record<string, unknown>): Promise<void>; /** * Add an observer to the peer session control. */ addObserver(observer: FcrPeerSessionObserver): void; /** * Remove an observer from the peer session control. */ removeObserver(observer: FcrPeerSessionObserver): void; /** * Releases the peer session control. */ release(): void; } export interface FcrPeerSessionObserver { /** * Called when a new peer session is received. * @param session The received peer session. */ onPeerSessionReceived?(session: FcrPeerSession): void; /** * Called when a peer session is accepted. * @param session The response of the accepted peer session. */ onPeerSessionAccepted?(session: FcrSessionResponse): void; /** * Called when a peer session is rejected. * @param session The response of the rejected peer session. */ onPeerSessionRejected?(session: FcrSessionResponse): void; /** * Called when a peer session is ended. * @param sessionId The ID of the peer session that was ended. * @param fromUserId The user ID of the user who ended the peer session. * @param cause The reason for the peer session being ended. */ onPeerSessionEnded?(sessionId: string, fromUserId: string, cause?: Record<string, unknown>): void; } export type FcrPeerSessionParams = FcrPeerSessionParamsSchema; export type FcrPeerSession = FcrSessionBase & {}; /** * The action of the peer session. * 0: request * 1: accept * 2: reject * 3: end */ export type FcrPeerSessionAction = 0 | 1 | 2 | 3; /** * The action of the peer session server response or request. * 0: receive * 1: accept */ export type FcrPeerSessionServerAction = 0 | 1;