UNPKG

@fishjam-cloud/js-server-sdk

Version:
880 lines (864 loc) 31.1 kB
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire'; import axios from 'axios'; /** * Describes peer status * @export * @interface Peer */ interface Peer$1 { /** * Assigned peer id * @type {string} * @memberof Peer */ 'id': string; /** * Custom metadata set by the peer * @type {object} * @memberof Peer */ 'metadata': object | null; /** * * @type {PeerStatus} * @memberof Peer */ 'status': PeerStatus; /** * * @type {SubscribeMode} * @memberof Peer */ 'subscribeMode': SubscribeMode; /** * Describes peer\'s subscriptions in manual mode * @type {Array<string>} * @memberof Peer */ 'subscriptions': Array<string>; /** * List of all peer\'s tracks * @type {Array<Track>} * @memberof Peer */ 'tracks': Array<Track$1>; /** * * @type {PeerType} * @memberof Peer */ 'type': PeerType; } /** * @type PeerOptions * Peer-specific options * @export */ type PeerOptions = PeerOptionsAgent | PeerOptionsWebRTC; /** * Options specific to the Agent peer * @export * @interface PeerOptionsAgent */ interface PeerOptionsAgent { /** * * @type {PeerOptionsAgentOutput} * @memberof PeerOptionsAgent */ 'output'?: PeerOptionsAgentOutput; /** * Configuration of peer\'s subscribing policy * @type {string} * @memberof PeerOptionsAgent */ 'subscribeMode'?: PeerOptionsAgentSubscribeModeEnum; } declare const PeerOptionsAgentSubscribeModeEnum: { readonly Auto: "auto"; readonly Manual: "manual"; }; type PeerOptionsAgentSubscribeModeEnum = typeof PeerOptionsAgentSubscribeModeEnum[keyof typeof PeerOptionsAgentSubscribeModeEnum]; /** * Output audio options * @export * @interface PeerOptionsAgentOutput */ interface PeerOptionsAgentOutput { /** * The format of the output audio * @type {string} * @memberof PeerOptionsAgentOutput */ 'audioFormat'?: PeerOptionsAgentOutputAudioFormatEnum; /** * The sample rate of the output audio * @type {number} * @memberof PeerOptionsAgentOutput */ 'audioSampleRate'?: PeerOptionsAgentOutputAudioSampleRateEnum; } declare const PeerOptionsAgentOutputAudioFormatEnum: { readonly Pcm16: "pcm16"; }; type PeerOptionsAgentOutputAudioFormatEnum = typeof PeerOptionsAgentOutputAudioFormatEnum[keyof typeof PeerOptionsAgentOutputAudioFormatEnum]; declare const PeerOptionsAgentOutputAudioSampleRateEnum: { readonly NUMBER_16000: 16000; readonly NUMBER_24000: 24000; }; type PeerOptionsAgentOutputAudioSampleRateEnum = typeof PeerOptionsAgentOutputAudioSampleRateEnum[keyof typeof PeerOptionsAgentOutputAudioSampleRateEnum]; /** * Options specific to the WebRTC peer * @export * @interface PeerOptionsWebRTC */ interface PeerOptionsWebRTC { /** * Enables the peer to use simulcast * @type {boolean} * @memberof PeerOptionsWebRTC */ 'enableSimulcast'?: boolean; /** * Custom peer metadata * @type {{ [key: string]: any; }} * @memberof PeerOptionsWebRTC */ 'metadata'?: { [key: string]: any; }; /** * Configuration of peer\'s subscribing policy * @type {string} * @memberof PeerOptionsWebRTC */ 'subscribeMode'?: PeerOptionsWebRTCSubscribeModeEnum; } declare const PeerOptionsWebRTCSubscribeModeEnum: { readonly Auto: "auto"; readonly Manual: "manual"; }; type PeerOptionsWebRTCSubscribeModeEnum = typeof PeerOptionsWebRTCSubscribeModeEnum[keyof typeof PeerOptionsWebRTCSubscribeModeEnum]; /** * Informs about the peer status * @export * @enum {string} */ declare const PeerStatus: { readonly Connected: "connected"; readonly Disconnected: "disconnected"; }; type PeerStatus = typeof PeerStatus[keyof typeof PeerStatus]; /** * Peer type * @export * @enum {string} */ declare const PeerType: { readonly Webrtc: "webrtc"; readonly Agent: "agent"; }; type PeerType = typeof PeerType[keyof typeof PeerType]; /** * Room configuration * @export * @interface RoomConfig */ interface RoomConfig { /** * Maximum amount of peers allowed into the room * @type {number} * @memberof RoomConfig */ 'maxPeers'?: number | null; /** * True if livestream viewers can omit specifying a token. * @type {boolean} * @memberof RoomConfig */ 'public'?: boolean; /** * The use-case of the room. If not provided, this defaults to conference. * @type {string} * @memberof RoomConfig */ 'roomType'?: RoomConfigRoomTypeEnum; /** * Enforces video codec for each peer in the room * @type {string} * @memberof RoomConfig */ 'videoCodec'?: RoomConfigVideoCodecEnum; /** * URL where Fishjam notifications will be sent * @type {string} * @memberof RoomConfig */ 'webhookUrl'?: string | null; } declare const RoomConfigRoomTypeEnum: { readonly FullFeature: "full_feature"; readonly AudioOnly: "audio_only"; readonly Broadcaster: "broadcaster"; readonly Livestream: "livestream"; readonly Conference: "conference"; readonly AudioOnlyLivestream: "audio_only_livestream"; }; type RoomConfigRoomTypeEnum = typeof RoomConfigRoomTypeEnum[keyof typeof RoomConfigRoomTypeEnum]; declare const RoomConfigVideoCodecEnum: { readonly H264: "h264"; readonly Vp8: "vp8"; }; type RoomConfigVideoCodecEnum = typeof RoomConfigVideoCodecEnum[keyof typeof RoomConfigVideoCodecEnum]; /** * Token for authorizing broadcaster streamer connection * @export * @interface StreamerToken */ interface StreamerToken { /** * * @type {string} * @memberof StreamerToken */ 'token': string; } /** * Configuration of peer\'s subscribing policy * @export * @enum {string} */ declare const SubscribeMode: { readonly Auto: "auto"; readonly Manual: "manual"; }; type SubscribeMode = typeof SubscribeMode[keyof typeof SubscribeMode]; /** * Describes media track of a Peer * @export * @interface Track */ interface Track$1 { /** * Assigned track id * @type {string} * @memberof Track */ 'id'?: string; /** * * @type {object} * @memberof Track */ 'metadata'?: object | null; /** * * @type {string} * @memberof Track */ 'type'?: TrackTypeEnum; } declare const TrackTypeEnum: { readonly Audio: "audio"; readonly Video: "video"; }; type TrackTypeEnum = typeof TrackTypeEnum[keyof typeof TrackTypeEnum]; /** * Token for authorizing broadcaster viewer connection * @export * @interface ViewerToken */ interface ViewerToken { /** * * @type {string} * @memberof ViewerToken */ 'token': string; } /** Defines types of tracks being published by peers and component */ declare enum TrackType$1 { TRACK_TYPE_UNSPECIFIED = 0, TRACK_TYPE_VIDEO = 1, TRACK_TYPE_AUDIO = 2, UNRECOGNIZED = -1 } /** Describes a media track */ interface Track { id: string; type: TrackType$1; metadata: string; } declare const Track: MessageFns$2<Track>; type Builtin$2 = Date | Function | Uint8Array | string | number | boolean | undefined; type DeepPartial$2<T> = T extends Builtin$2 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$2<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$2<U>> : T extends {} ? { [K in keyof T]?: DeepPartial$2<T[K]>; } : Partial<T>; type KeysOfUnion$2<T> = T extends T ? keyof T : never; type Exact$2<P, I extends P> = P extends Builtin$2 ? P : P & { [K in keyof P]: Exact$2<P[K], I[K]>; } & { [K in Exclude<keyof I, KeysOfUnion$2<P>>]: never; }; interface MessageFns$2<T> { encode(message: T, writer?: BinaryWriter): BinaryWriter; decode(input: BinaryReader | Uint8Array, length?: number): T; fromJSON(object: any): T; toJSON(message: T): unknown; create<I extends Exact$2<DeepPartial$2<T>, I>>(base?: I): T; fromPartial<I extends Exact$2<DeepPartial$2<T>, I>>(object: I): T; } declare enum ServerMessage_PeerType { PEER_TYPE_UNSPECIFIED = 0, PEER_TYPE_WEBRTC = 1, PEER_TYPE_AGENT = 2, UNRECOGNIZED = -1 } /** Defines message groups for which peer can subscribe */ declare enum ServerMessage_EventType { EVENT_TYPE_UNSPECIFIED = 0, EVENT_TYPE_SERVER_NOTIFICATION = 1, UNRECOGNIZED = -1 } /** Defines any type of message passed between FJ and server peer */ interface ServerMessage { roomCrashed?: ServerMessage_RoomCrashed | undefined; peerConnected?: ServerMessage_PeerConnected | undefined; peerDisconnected?: ServerMessage_PeerDisconnected | undefined; peerCrashed?: ServerMessage_PeerCrashed | undefined; componentCrashed?: ServerMessage_ComponentCrashed | undefined; authenticated?: ServerMessage_Authenticated | undefined; authRequest?: ServerMessage_AuthRequest | undefined; subscribeRequest?: ServerMessage_SubscribeRequest | undefined; subscribeResponse?: ServerMessage_SubscribeResponse | undefined; roomCreated?: ServerMessage_RoomCreated | undefined; roomDeleted?: ServerMessage_RoomDeleted | undefined; hlsPlayable?: ServerMessage_HlsPlayable | undefined; hlsUploaded?: ServerMessage_HlsUploaded | undefined; hlsUploadCrashed?: ServerMessage_HlsUploadCrashed | undefined; peerMetadataUpdated?: ServerMessage_PeerMetadataUpdated | undefined; trackAdded?: ServerMessage_TrackAdded | undefined; trackRemoved?: ServerMessage_TrackRemoved | undefined; trackMetadataUpdated?: ServerMessage_TrackMetadataUpdated | undefined; peerAdded?: ServerMessage_PeerAdded | undefined; peerDeleted?: ServerMessage_PeerDeleted | undefined; /** @deprecated */ streamConnected?: ServerMessage_StreamConnected | undefined; /** @deprecated */ streamDisconnected?: ServerMessage_StreamDisconnected | undefined; viewerConnected?: ServerMessage_ViewerConnected | undefined; viewerDisconnected?: ServerMessage_ViewerDisconnected | undefined; streamerConnected?: ServerMessage_StreamerConnected | undefined; streamerDisconnected?: ServerMessage_StreamerDisconnected | undefined; } declare const ServerMessage: MessageFns$1<ServerMessage>; /** Notification sent when a room crashes */ interface ServerMessage_RoomCrashed { roomId: string; } declare const ServerMessage_RoomCrashed: MessageFns$1<ServerMessage_RoomCrashed>; /** Notification sent when a peer is added */ interface ServerMessage_PeerAdded { roomId: string; peerId: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerAdded: MessageFns$1<ServerMessage_PeerAdded>; /** Notification sent when a peer is removed */ interface ServerMessage_PeerDeleted { roomId: string; peerId: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerDeleted: MessageFns$1<ServerMessage_PeerDeleted>; /** Notification sent when a peer connects */ interface ServerMessage_PeerConnected { roomId: string; peerId: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerConnected: MessageFns$1<ServerMessage_PeerConnected>; /** Notification sent when a peer disconnects from FJ */ interface ServerMessage_PeerDisconnected { roomId: string; peerId: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerDisconnected: MessageFns$1<ServerMessage_PeerDisconnected>; /** Notification sent when a peer crashes */ interface ServerMessage_PeerCrashed { roomId: string; peerId: string; reason: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerCrashed: MessageFns$1<ServerMessage_PeerCrashed>; /** Notification sent when a component crashes */ interface ServerMessage_ComponentCrashed { roomId: string; componentId: string; } declare const ServerMessage_ComponentCrashed: MessageFns$1<ServerMessage_ComponentCrashed>; /** Response sent by FJ, confirming successfull authentication */ interface ServerMessage_Authenticated { } declare const ServerMessage_Authenticated: MessageFns$1<ServerMessage_Authenticated>; /** Request sent by peer, to authenticate to FJ server */ interface ServerMessage_AuthRequest { token: string; } declare const ServerMessage_AuthRequest: MessageFns$1<ServerMessage_AuthRequest>; /** Request sent by peer to subsribe for certain message type */ interface ServerMessage_SubscribeRequest { eventType: ServerMessage_EventType; } declare const ServerMessage_SubscribeRequest: MessageFns$1<ServerMessage_SubscribeRequest>; /** Response sent by FJ, confirming subscription for message type */ interface ServerMessage_SubscribeResponse { eventType: ServerMessage_EventType; } declare const ServerMessage_SubscribeResponse: MessageFns$1<ServerMessage_SubscribeResponse>; /** Notification sent when a room is created */ interface ServerMessage_RoomCreated { roomId: string; } declare const ServerMessage_RoomCreated: MessageFns$1<ServerMessage_RoomCreated>; /** Notification sent when a room is deleted */ interface ServerMessage_RoomDeleted { roomId: string; } declare const ServerMessage_RoomDeleted: MessageFns$1<ServerMessage_RoomDeleted>; /** Notification sent when the HLS stream becomes available in a room */ interface ServerMessage_HlsPlayable { roomId: string; componentId: string; } declare const ServerMessage_HlsPlayable: MessageFns$1<ServerMessage_HlsPlayable>; /** Notification sent when the HLS recording is successfully uploded to AWS S3 */ interface ServerMessage_HlsUploaded { roomId: string; } declare const ServerMessage_HlsUploaded: MessageFns$1<ServerMessage_HlsUploaded>; /** Notification sent when the upload of HLS recording to AWS S3 fails */ interface ServerMessage_HlsUploadCrashed { roomId: string; } declare const ServerMessage_HlsUploadCrashed: MessageFns$1<ServerMessage_HlsUploadCrashed>; /** Notification sent when peer updates its metadata */ interface ServerMessage_PeerMetadataUpdated { roomId: string; peerId: string; metadata: string; peerType: ServerMessage_PeerType; } declare const ServerMessage_PeerMetadataUpdated: MessageFns$1<ServerMessage_PeerMetadataUpdated>; /** Notification sent when peer or component adds new track */ interface ServerMessage_TrackAdded { roomId: string; peerId?: string | undefined; componentId?: string | undefined; track: Track | undefined; } declare const ServerMessage_TrackAdded: MessageFns$1<ServerMessage_TrackAdded>; /** Notification sent when a track is removed */ interface ServerMessage_TrackRemoved { roomId: string; peerId?: string | undefined; componentId?: string | undefined; track: Track | undefined; } declare const ServerMessage_TrackRemoved: MessageFns$1<ServerMessage_TrackRemoved>; /** Notification sent when metadata of a multimedia track is updated */ interface ServerMessage_TrackMetadataUpdated { roomId: string; peerId?: string | undefined; componentId?: string | undefined; track: Track | undefined; } declare const ServerMessage_TrackMetadataUpdated: MessageFns$1<ServerMessage_TrackMetadataUpdated>; /** Notification sent when streamer successfully connects */ interface ServerMessage_StreamConnected { streamId: string; } declare const ServerMessage_StreamConnected: MessageFns$1<ServerMessage_StreamConnected>; /** Notification sent when streamer disconnects */ interface ServerMessage_StreamDisconnected { streamId: string; } declare const ServerMessage_StreamDisconnected: MessageFns$1<ServerMessage_StreamDisconnected>; /** Notification sent when viewer successfully connects */ interface ServerMessage_ViewerConnected { streamId: string; viewerId: string; } declare const ServerMessage_ViewerConnected: MessageFns$1<ServerMessage_ViewerConnected>; /** Notification sent when viewer disconnects */ interface ServerMessage_ViewerDisconnected { streamId: string; viewerId: string; } declare const ServerMessage_ViewerDisconnected: MessageFns$1<ServerMessage_ViewerDisconnected>; interface ServerMessage_StreamerConnected { streamId: string; streamerId: string; } declare const ServerMessage_StreamerConnected: MessageFns$1<ServerMessage_StreamerConnected>; interface ServerMessage_StreamerDisconnected { streamId: string; streamerId: string; } declare const ServerMessage_StreamerDisconnected: MessageFns$1<ServerMessage_StreamerDisconnected>; type Builtin$1 = Date | Function | Uint8Array | string | number | boolean | undefined; type DeepPartial$1<T> = T extends Builtin$1 ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial$1<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial$1<U>> : T extends {} ? { [K in keyof T]?: DeepPartial$1<T[K]>; } : Partial<T>; type KeysOfUnion$1<T> = T extends T ? keyof T : never; type Exact$1<P, I extends P> = P extends Builtin$1 ? P : P & { [K in keyof P]: Exact$1<P[K], I[K]>; } & { [K in Exclude<keyof I, KeysOfUnion$1<P>>]: never; }; interface MessageFns$1<T> { encode(message: T, writer?: BinaryWriter): BinaryWriter; decode(input: BinaryReader | Uint8Array, length?: number): T; fromJSON(object: any): T; toJSON(message: T): unknown; create<I extends Exact$1<DeepPartial$1<T>, I>>(base?: I): T; fromPartial<I extends Exact$1<DeepPartial$1<T>, I>>(object: I): T; } /** Notification containing a chunk of an agent's track's data stream */ interface AgentRequest_TrackData { trackId: string; data: Uint8Array; } declare const AgentRequest_TrackData: MessageFns<AgentRequest_TrackData>; /** Defines any type of message passed from Fishjam to agent peer */ interface AgentResponse { authenticated?: AgentResponse_Authenticated | undefined; trackData?: AgentResponse_TrackData | undefined; } declare const AgentResponse: MessageFns<AgentResponse>; /** Response confirming successful authentication */ interface AgentResponse_Authenticated { } declare const AgentResponse_Authenticated: MessageFns<AgentResponse_Authenticated>; /** Notification containing a chunk of a track's data stream */ interface AgentResponse_TrackData { peerId: string; track: Track | undefined; data: Uint8Array; } declare const AgentResponse_TrackData: MessageFns<AgentResponse_TrackData>; type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]>; } : Partial<T>; type KeysOfUnion<T> = T extends T ? keyof T : never; type Exact<P, I extends P> = P extends Builtin ? P : P & { [K in keyof P]: Exact<P[K], I[K]>; } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never; }; interface MessageFns<T> { encode(message: T, writer?: BinaryWriter): BinaryWriter; decode(input: BinaryReader | Uint8Array, length?: number): T; fromJSON(object: any): T; toJSON(message: T): unknown; create<I extends Exact<DeepPartial<T>, I>>(base?: I): T; fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T; } type EventMap = { [key: string]: (...args: any[]) => void } /** * Type-safe event emitter. * * Use it like this: * * ```typescript * type MyEvents = { * error: (error: Error) => void; * message: (from: string, content: string) => void; * } * * const myEmitter = new EventEmitter() as TypedEmitter<MyEvents>; * * myEmitter.emit("error", "x") // <- Will catch this type error; * ``` */ interface TypedEventEmitter<Events extends EventMap> { addListener<E extends keyof Events> (event: E, listener: Events[E]): this on<E extends keyof Events> (event: E, listener: Events[E]): this once<E extends keyof Events> (event: E, listener: Events[E]): this prependListener<E extends keyof Events> (event: E, listener: Events[E]): this prependOnceListener<E extends keyof Events> (event: E, listener: Events[E]): this off<E extends keyof Events>(event: E, listener: Events[E]): this removeAllListeners<E extends keyof Events> (event?: E): this removeListener<E extends keyof Events> (event: E, listener: Events[E]): this emit<E extends keyof Events> (event: E, ...args: Parameters<Events[E]>): boolean // The sloppy `eventNames()` return type is to mitigate type incompatibilities - see #5 eventNames (): (keyof Events | string | symbol)[] rawListeners<E extends keyof Events> (event: E): Events[E][] listeners<E extends keyof Events> (event: E): Events[E][] listenerCount<E extends keyof Events> (event: E): number getMaxListeners (): number setMaxListeners (maxListeners: number): this } declare const brand: unique symbol; /** * Branded type helper */ type Brand<T, TBrand extends string> = T & { [brand]: TBrand; }; /** * ID of the Room. * Room can be created with {@link FishjamClient.createRoom}. */ type RoomId = Brand<string, 'RoomId'>; /** * ID of Peer. Peer is associated with Room and can be created with {@link FishjamClient.createPeer}. */ type PeerId = Brand<string, 'PeerId'>; type Peer = Omit<Peer$1, 'id'> & { id: PeerId; }; type Room = { id: RoomId; peers: Peer[]; config: RoomConfig; }; type FishjamConfig = { fishjamId: string; managementToken: string; }; type ErrorEventHandler = (msg: Event) => void; type CloseEventHandler = (code: number, reason: string) => void; type AgentCallbacks = { onError?: ErrorEventHandler; onClose?: CloseEventHandler; }; type WithRoomId<T> = { [P in keyof T]: NonNullable<T[P]> extends { roomId: string; } ? Omit<NonNullable<T[P]>, 'roomId'> & { roomId: RoomId; } : T[P]; }; type WithPeerId<T> = { [P in keyof T]: NonNullable<T[P]> extends { peerId: string; } ? Omit<NonNullable<T[P]>, 'peerId'> & { peerId: PeerId; } : T[P]; }; type ExpectedEvents = 'roomCreated' | 'roomDeleted' | 'roomCrashed' | 'peerAdded' | 'peerDeleted' | 'peerConnected' | 'peerDisconnected' | 'peerMetadataUpdated' | 'peerCrashed' | 'streamConnected' | 'streamDisconnected' | 'viewerConnected' | 'viewerDisconnected' | 'trackAdded' | 'trackRemoved' | 'trackMetadataUpdated'; /** * @inline */ type MessageWithIds = WithPeerId<WithRoomId<ServerMessage>>; /** * @inline */ type Notifications = { [K in ExpectedEvents]: NonNullable<MessageWithIds[K]>; }; type RoomCreated = Notifications['roomCreated']; type RoomDeleted = Notifications['roomDeleted']; type RoomCrashed = Notifications['roomCrashed']; type PeerAdded = Notifications['peerAdded']; type PeerDeleted = Notifications['peerDeleted']; type PeerConnected = Notifications['peerConnected']; type PeerDisconnected = Notifications['peerDisconnected']; type PeerMetadataUpdated = Notifications['peerMetadataUpdated']; type PeerCrashed = Notifications['peerCrashed']; type StreamConnected = Notifications['streamConnected']; type StreamDisconnected = Notifications['streamDisconnected']; type ViewerConnected = Notifications['viewerConnected']; type ViewerDisconnected = Notifications['viewerDisconnected']; type TrackAdded = Notifications['trackAdded']; type TrackRemoved = Notifications['trackRemoved']; type TrackMetadataUpdated = Notifications['trackMetadataUpdated']; type NotificationEvents = { [K in ExpectedEvents]: (message: NonNullable<MessageWithIds[K]>) => void; }; declare const FishjamWSNotifier_base: new () => TypedEventEmitter<NotificationEvents>; /** * Notifier object that can be used to get notified about various events related to the Fishjam App. * @category Client */ declare class FishjamWSNotifier extends FishjamWSNotifier_base { private readonly client; constructor(config: FishjamConfig, onError: ErrorEventHandler, onClose: CloseEventHandler); private dispatchNotification; private setupConnection; private isExpectedEvent; } declare const expectedEventsList: readonly ["trackData"]; /** * @useDeclaredType */ type ExpectedAgentEvents = (typeof expectedEventsList)[number]; type IncomingTrackData = Omit<NonNullable<AgentResponse_TrackData>, 'peerId'> & { peerId: PeerId; }; type OutgoingTrackData = Omit<NonNullable<AgentRequest_TrackData>, 'peerId'> & { peerId: PeerId; }; type AgentTrack = Omit<Track, 'id'> & { id: TrackId; }; type TrackType = 'audio' | 'video'; type AudioCodecParameters = { encoding: 'opus' | 'pcm16'; sampleRate: 16000 | 24000 | 48000; channels: 1; }; type TrackId = Brand<string, 'TrackId'>; /** * @inline */ type ResponseWithPeerId = WithPeerId<AgentResponse>; type AgentEvents = { [K in ExpectedAgentEvents]: (message: NonNullable<ResponseWithPeerId[K]>) => void; }; declare const FishjamAgent_base: new () => TypedEventEmitter<AgentEvents>; declare class FishjamAgent extends FishjamAgent_base { private readonly client; constructor(config: FishjamConfig, agentToken: string, callbacks?: AgentCallbacks); /** * Creates an outgoing audio track for the agent * @returns a new audio track */ createTrack(codecParameters: AudioCodecParameters, metadata?: object): AgentTrack; /** * Interrupt track indentified by `trackId`. * * Any audio that has been sent by the agent, but not played * by Fishjam will be cleared and be prevented from playing. * * Audio sent after the interrupt will be played normally. */ interruptTrack(trackId: TrackId): void; /** * Deletes an outgoing audio track for the agent */ deleteTrack(trackId: TrackId): void; /** * Send audio data for the given track */ sendData(trackId: TrackId, data: Uint8Array): void; disconnect(): void; private dispatchNotification; private setupConnection; private isExpectedEvent; } /** * Client class that allows to manage Rooms and Peers for a Fishjam App. * It requires the Fishjam ID and management token that can be retrieved from the Fishjam Dashboard. * @category Client */ declare class FishjamClient { private readonly roomApi; private readonly viewerApi; private readonly streamerApi; private readonly fishjamConfig; /** * Create new instance of Fishjam Client. * * Example usage: * ``` * const fishjamClient = new FishjamClient({ * fishjamId: fastify.config.FISHJAM_ID, * managementToken: fastify.config.FISHJAM_MANAGEMENT_TOKEN, * }); * ``` */ constructor(config: FishjamConfig); /** * Create a new room. All peers connected to the same room will be able to send/receive streams to each other. */ createRoom(config?: RoomConfig): Promise<Room>; /** * Delete an existing room. All peers connected to this room will be disconnected and removed. */ deleteRoom(roomId: RoomId): Promise<void>; /** * Get a list of all existing rooms. */ getAllRooms(): Promise<Room[]>; /** * Create a new peer assigned to a room. */ createPeer(roomId: RoomId, options?: PeerOptionsWebRTC): Promise<{ peer: Peer; peerToken: string; }>; /** * Create a new agent assigned to a room. */ createAgent(roomId: RoomId, options?: PeerOptionsAgent, callbacks?: AgentCallbacks): Promise<{ agent: FishjamAgent; peer: Peer; }>; /** * Get details about a given room. */ getRoom(roomId: RoomId): Promise<Room>; /** * Delete a peer - this will also disconnect the peer from the room. */ deletePeer(roomId: RoomId, peerId: PeerId): Promise<void>; /** * Subscribe a peer to another peer - this will make all tracks from the publisher available to the subscriber. * Using this function only makes sense if subscribeMode is set to manual */ subscribePeer(roomId: RoomId, subscriberPeerId: PeerId, publisherPeerId: PeerId): Promise<void>; /** * Subscribe a peer to specific tracks from another peer - this will make only the specified tracks from the publisher available to the subscriber. * Using this function only makes sense if subscribeMode is set to manual */ subscribeTracks(roomId: RoomId, subscriberPeerId: PeerId, tracks: TrackId[]): Promise<void>; /** * Refresh the peer token for an already existing peer. * If an already created peer has not been connected to the room for more than 24 hours, the token will become invalid. This method can be used to generate a new peer token for the existing peer. * @returns refreshed peer token */ refreshPeerToken(roomId: RoomId, peerId: PeerId): Promise<string>; /** * Creates a livestream viewer token for the given room. * @returns a livestream viewer token */ createLivestreamViewerToken(roomId: RoomId): Promise<ViewerToken>; /** * Creates a livestream streamer token for the given room. * @returns a livestream streamer token */ createLivestreamStreamerToken(roomId: RoomId): Promise<StreamerToken>; } declare class MissingFishjamIdException extends Error { constructor(); } declare class FishjamBaseException extends Error { statusCode: number; axiosCode?: string; details?: string; constructor(error: axios.AxiosError<Record<string, string>>); } declare class BadRequestException extends FishjamBaseException { } declare class UnauthorizedException extends FishjamBaseException { } declare class ForbiddenException extends FishjamBaseException { } declare class RoomNotFoundException extends FishjamBaseException { } declare class FishjamNotFoundException extends FishjamBaseException { } declare class PeerNotFoundException extends FishjamBaseException { } declare class ServiceUnavailableException extends FishjamBaseException { } declare class UnknownException extends FishjamBaseException { } export { type AgentCallbacks, type AgentEvents, type AgentTrack, type AudioCodecParameters, BadRequestException, type Brand, type CloseEventHandler, type ErrorEventHandler, type ExpectedAgentEvents, type ExpectedEvents, FishjamAgent, FishjamBaseException, FishjamClient, type FishjamConfig, FishjamNotFoundException, FishjamWSNotifier, ForbiddenException, type IncomingTrackData, MissingFishjamIdException, type NotificationEvents, type OutgoingTrackData, type Peer, type PeerAdded, type PeerConnected, type PeerCrashed, type PeerDeleted, type PeerDisconnected, type PeerId, type PeerMetadataUpdated, PeerNotFoundException, type PeerOptions, PeerStatus, type Room, type RoomConfig, RoomConfigRoomTypeEnum, RoomConfigVideoCodecEnum, type RoomCrashed, type RoomCreated, type RoomDeleted, type RoomId, RoomNotFoundException, ServerMessage, ServiceUnavailableException, type StreamConnected, type StreamDisconnected, type StreamerToken, type TrackAdded, type TrackId, type TrackMetadataUpdated, type TrackRemoved, type TrackType, UnauthorizedException, UnknownException, type ViewerConnected, type ViewerDisconnected, type ViewerToken };