UNPKG

@4players/odin

Version:

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

122 lines (121 loc) 4.54 kB
import { IOdinClientSettings, IOdinClientEvents, OdinConnectionState } from './types'; import { OdinRoom } from './room'; /** * Class providing static methods to handle ODIN client connections. */ export declare class OdinClient { /** * Optional audio service used for ODIN audio functionality. */ private static _audioService?; /** * RTCPeerConnection handler for handling WebRTC operations. */ private static _rtcHandler?; /** * Web Worker used for off-thread operations. */ private static _worker?; /** * Main WebSocket stream to interact with the ODIN server. */ private static _mainStream; /** * EventTarget instance to listen for and dispatch custom events. */ private static _eventTarget; /** * Connection state of the client to the ODIN server. */ private static _state; /** * Array holding the currently available `OdinRoom` instances. */ private static _rooms; /** * @ignore */ constructor(); /** * Global settings for ODIN connections. */ static config: IOdinClientSettings; /** * An array of available `OdinRoom` instances. */ static get rooms(): OdinRoom[]; /** * The current state of the main stream connection. */ static get connectionState(): OdinConnectionState; /** * Updates the state of the connection. */ private static set connectionState(value); /** * Returns the event handler of the client. * * @ignore */ static get eventTarget(): EventTarget; /** * Authenticates the client, establishes the main stream connection, sets up audio context and WebRTC connection, and finally * creates `OdinRoom` instances. * * @private */ private static connect; /** * Authenticates against the ODIN server and returns `OdinRoom` instances for all rooms set in the specified token. * * This function accepts an optional `AudioContext` parameter for audio capture. The `AudioContext` interface is a part of * the Web Audio API that represents an audio-processing graph, which can be used to control and manipulate audio signals * in web applications. If the `AudioContext` is not provided or explicitly set to `undefined`, we will try to create one * internally. * * @param token The room token for authentication * @param gateway The gateway to authenticate against * @param audioContext An optional audio context to use for capture * @returns A promise of the available rooms */ static initRooms(token: string, gateway?: string, audioContext?: AudioContext): Promise<OdinRoom[]>; /** * Authenticates against the ODIN server and returns an `OdinRoom` instance for the first room set in the specified token. * * This function accepts an optional `AudioContext` parameter for audio capture. The `AudioContext` interface is a part of * the Web Audio API that represents an audio-processing graph, which can be used to control and manipulate audio signals * in web applications. If the `AudioContext` is not provided or explicitly set to `undefined`, we will try to create one * internally. * * @param token The room token for authentication * @param gateway The gateway to authenticate against * @param audioContext An optional audio context to use for capture * @returns A promise of the first available room */ static initRoom(token: string, gateway?: string, audioContext?: AudioContext): Promise<OdinRoom>; /** * Not implemented. * * @private */ private static mainHandler; /** * Authenticates against the gateway and returns its result. * * @param token The token for authentication * @param gateway The gateway to authenticate against * @returns A promise resolving to the authentication result */ private static authGateway; /** * Disconnects from all rooms and stops all audio handling. */ static disconnect(state?: OdinConnectionState): void; /** * Registers to client events from `IOdinClientEvents`. * * @param eventName The name of the event to listen to * @param handler The callback to handle the event */ static addEventListener<Event extends keyof IOdinClientEvents>(eventName: Event, handler: IOdinClientEvents[Event]): void; }