import { Publisher, Subscriber, TrackPublishOptions } from './rtc'; import { CallState } from './store'; import { ScopedLogger } from './logger'; import type { AcceptCallResponse, BlockUserResponse, CallRingEvent, CallSettingsResponse, CollectUserFeedbackRequest, CollectUserFeedbackResponse, DeleteCallRequest, DeleteCallResponse, DeleteRecordingResponse, DeleteTranscriptionResponse, EndCallResponse, GetCallReportResponse, GetCallResponse, GetCallSessionParticipantStatsDetailsResponse, GetOrCreateCallRequest, GetOrCreateCallResponse, GoLiveRequest, GoLiveResponse, JoinCallResponse, KickUserRequest, KickUserResponse, ListRecordingsResponse, ListTranscriptionsResponse, MuteUsersResponse, PinRequest, PinResponse, QueryCallMembersRequest, QueryCallMembersResponse, QueryCallParticipantsRequest, QueryCallParticipantsResponse, QueryCallSessionParticipantStatsResponse, QueryCallSessionParticipantStatsTimelineResponse, QueryCallStatsMapResponse, RejectCallResponse, RequestPermissionRequest, RequestPermissionResponse, RingCallRequest, RingCallResponse, SendCallEventResponse, SendReactionRequest, SendReactionResponse, StartClosedCaptionsRequest, StartClosedCaptionsResponse, StartFrameRecordingRequest, StartFrameRecordingResponse, StartHLSBroadcastingResponse, StartRTMPBroadcastsRequest, StartRTMPBroadcastsResponse, StartTranscriptionRequest, StartTranscriptionResponse, StopAllRTMPBroadcastsResponse, StopClosedCaptionsRequest, StopClosedCaptionsResponse, StopFrameRecordingResponse, StopHLSBroadcastingResponse, StopLiveRequest, StopLiveResponse, StopRecordingResponse, StopRTMPBroadcastsResponse, StopTranscriptionResponse, UnblockUserResponse, UnpinRequest, UnpinResponse, UpdateCallMembersRequest, UpdateCallMembersResponse, UpdateCallRequest, UpdateCallResponse, UpdateUserPermissionsRequest, UpdateUserPermissionsResponse } from './gen/coordinator'; import { AudioTrackType, CallConstructor, CallLeaveOptions, CallRecordingType, ClientPublishOptions, ClosedCaptionsSettings, JoinCallData, StartCallRecordingFnType, TrackMuteType, VideoTrackType } from './types'; import { ClientCapability, TrackType, VideoDimension } from './gen/video/sfu/models/models'; import { Tracer } from './stats'; import { DynascaleManager } from './helpers/DynascaleManager'; import { PermissionsContext } from './permissions'; import { StreamClient } from './coordinator/connection/client'; import { AllCallEvents, CallEventListener, RejectReason } from './coordinator/connection/types'; import { CameraManager, MicrophoneManager, ScreenShareManager, SpeakerManager } from './devices'; import { GetCallStatsResponse } from './gen/shims'; /** * An object representation of a `Call`. */ export declare class Call { /** * The type of the call. */ readonly type: string; /** * The ID of the call. */ readonly id: string; /** * The call CID. */ readonly cid: string; /** * The state of this call. */ readonly state: CallState; /** * Flag indicating whether this call is "watched" and receives * updates from the backend. */ watching: boolean; /** * Device manager for the camera */ readonly camera: CameraManager; /** * Device manager for the microphone. */ readonly microphone: MicrophoneManager; /** * Device manager for the speaker. */ readonly speaker: SpeakerManager; /** * Device manager for the screen. */ readonly screenShare: ScreenShareManager; /** * The DynascaleManager instance. */ readonly dynascaleManager: DynascaleManager; subscriber?: Subscriber; publisher?: Publisher; /** * Flag telling whether this call is a "ringing" call. */ private readonly ringingSubject; /** * The permissions context of this call. */ readonly permissionsContext: PermissionsContext; readonly tracer: Tracer; readonly logger: ScopedLogger; /** * The event dispatcher instance dedicated to this Call instance. * @private */ private readonly dispatcher; private clientPublishOptions?; private currentPublishOptions?; private statsReportingIntervalInMs; private statsReporter?; private sfuStatsReporter?; private dropTimeout; private readonly clientStore; readonly streamClient: StreamClient; private sfuClient?; private sfuClientTag; private unifiedSessionId?; private readonly reconnectConcurrencyTag; private reconnectAttempts; private reconnectStrategy; private reconnectReason; private fastReconnectDeadlineSeconds; private disconnectionTimeoutSeconds; private lastOfflineTimestamp; private networkAvailableTask; private trackPublishOrder; private joinResponseTimeout?; private rpcRequestTimeout?; private joinCallData?; private hasJoinedOnce; private deviceSettingsAppliedOnce; private credentials?; private initialized; private readonly acceptRejectConcurrencyTag; private readonly joinLeaveConcurrencyTag; /** * A list hooks/functions to invoke when the call is left. * A typical use case is to clean up some global event handlers. * @private */ private readonly leaveCallHooks; private readonly streamClientBasePath; private streamClientEventHandlers; /** * A list of capabilities that the client supports and are enabled. */ private clientCapabilities; /** * Constructs a new `Call` instance. * * NOTE: Don't call the constructor directly, instead * Use the [`StreamVideoClient.call`](./StreamVideoClient.md/#call) * method to construct a `Call` instance. */ constructor({ type, id, streamClient, members, ownCapabilities, sortParticipantsBy, clientStore, ringing, watching, }: CallConstructor); /** * Sets up the call instance. * * @internal an internal method and should not be used outside the SDK. */ setup: () => Promise; private registerEffects; private handleRingingCall; private handleOwnCapabilitiesUpdated; /** * You can subscribe to WebSocket events provided by the API. To remove a subscription, call the `off` method. * Please note that subscribing to WebSocket events is an advanced use-case. * For most use-cases, it should be enough to watch for state changes. * * @param eventName the event name. * @param fn the event handler. */ on: (eventName: E, fn: CallEventListener) => () => void; /** * Remove subscription for WebSocket events that were created by the `on` method. * * @param eventName the event name. * @param fn the event handler. */ off: (eventName: E, fn: CallEventListener) => void; /** * Leave the call and stop the media streams that were published by the call. */ leave: ({ reject, reason, message }?: CallLeaveOptions) => Promise; /** * A flag indicating whether the call is "ringing" type of call. */ get ringing(): boolean; /** * Retrieves the current user ID. */ get currentUserId(): string | undefined; /** * A flag indicating whether the call was created by the current user. */ get isCreatedByMe(): boolean | "" | undefined; /** * Update from the call response from the "call.ring" event * @internal */ updateFromRingingEvent: (event: CallRingEvent) => Promise; /** * Loads the information about the call. * * @param params.ring if set to true, a `call.ring` event will be sent to the call members. * @param params.notify if set to true, a `call.notification` event will be sent to the call members. * @param params.members_limit the total number of members to return as part of the response. * @param params.video if set to true, in a ringing scenario, mobile SDKs will show "incoming video call", audio only otherwise. */ get: (params?: { ring?: boolean; notify?: boolean; members_limit?: number; video?: boolean; }) => Promise; /** * Loads the information about the call and creates it if it doesn't exist. * * @param data the data to create the call with. */ getOrCreate: (data?: GetOrCreateCallRequest) => Promise; /** * Creates a call * * @param data the data to create the call with. */ create: (data?: GetOrCreateCallRequest) => Promise; /** * Deletes the call. */ delete: (data?: DeleteCallRequest) => Promise; /** * Sends a ring notification to the provided users who are not already in the call. * All users should be members of the call. */ ring: (data?: RingCallRequest) => Promise; /** * A shortcut for {@link Call.get} with `notify` parameter set to `true`. * Will send a `call.notification` event to the call members. */ notify: () => Promise; /** * Marks the incoming call as accepted. * * This method should be used only for "ringing" call flows. * {@link Call.join} invokes this method automatically for you when joining a call. * Unless you are implementing a custom "ringing" flow, you should not use this method. */ accept: () => Promise; /** * Marks the incoming call as rejected. * * This method should be used only for "ringing" call flows. * {@link Call.leave} invokes this method automatically for you when you leave or reject this call. * Unless you are implementing a custom "ringing" flow, you should not use this method. * * @param reason the reason for rejecting the call. */ reject: (reason?: RejectReason) => Promise; /** * Will start to watch for call related WebSocket events and initiate a call session with the server. * * @returns a promise which resolves once the call join-flow has finished. */ join: ({ maxJoinRetries, joinResponseTimeout, rpcRequestTimeout, ...data }?: JoinCallData & { maxJoinRetries?: number; joinResponseTimeout?: number; rpcRequestTimeout?: number; }) => Promise; /** * Will make a single attempt to watch for call related WebSocket events * and initiate a call session with the server. * * @returns a promise which resolves once the call join-flow has finished. */ private doJoin; /** * Prepares Reconnect Details object. * @internal */ private getReconnectDetails; /** * Prepares the preferred codec for the call. * This is an experimental client feature and subject to change. * @internal */ private getPreferredPublishOptions; /** * Prepares the preferred options for subscribing to tracks. * This is an experimental client feature and subject to change. * @internal */ private getPreferredSubscribeOptions; /** * Performs an ICE restart on both the Publisher and Subscriber Peer Connections. * Uses the provided SFU client to restore the ICE connection. * * This method can throw an error if the ICE restart fails. * This error should be handled by the reconnect loop, * and a new reconnection shall be attempted. * * @internal */ private restoreICE; /** * Initializes the Publisher and Subscriber Peer Connections. * @internal */ private initPublisherAndSubscriber; /** * Retrieves credentials for joining the call. * * @internal * * @param data the join call data. */ doJoinRequest: (data?: JoinCallData) => Promise; /** * Handles the closing of the SFU signal connection. * * @internal * @param sfuClient the SFU client instance that was closed. * @param reason the reason for the closure. */ private handleSfuSignalClose; /** * Handles the reconnection flow. * * @internal * * @param strategy the reconnection strategy to use. * @param reason the reason for the reconnection. */ private reconnect; /** * Initiates the reconnection flow with the "fast" strategy. * @internal */ private reconnectFast; /** * Initiates the reconnection flow with the "rejoin" strategy. * @internal */ private reconnectRejoin; /** * Initiates the reconnection flow with the "migrate" strategy. * @internal */ private reconnectMigrate; /** * Registers the various event handlers for reconnection. * * @internal */ private registerReconnectHandlers; /** * Restores the published tracks after a reconnection. * @internal */ private restorePublishedTracks; /** * Restores the subscribed tracks after a reconnection. * @internal */ private restoreSubscribedTracks; /** * Starts publishing the given video stream to the call. * @deprecated use `call.publish()`. */ publishVideoStream: (videoStream: MediaStream) => Promise; /** * Starts publishing the given audio stream to the call. * @deprecated use `call.publish()` */ publishAudioStream: (audioStream: MediaStream) => Promise; /** * Starts publishing the given screen-share stream to the call. * @deprecated use `call.publish()` */ publishScreenShareStream: (screenShareStream: MediaStream) => Promise; /** * Publishes the given media stream. * * @param mediaStream the media stream to publish. * @param trackType the type of the track to announce. * @param options the publish options. */ publish: (mediaStream: MediaStream, trackType: TrackType, options?: TrackPublishOptions) => Promise; /** * Stops publishing the given track type to the call, if it is currently being published. * * @param trackTypes the track types to stop publishing. */ stopPublish: (...trackTypes: TrackType[]) => Promise; /** * Updates the call state with the new stream. * * @param mediaStream the new stream to update the call state with. * If undefined, the stream will be removed from the call state. * @param trackTypes the track types to update the call state with. */ private updateLocalStreamState; /** * Updates the preferred publishing options * * @internal * @param options the options to use. */ updatePublishOptions: (options: ClientPublishOptions) => void; /** * Notifies the SFU that a noise cancellation process has started. * * @internal */ notifyNoiseCancellationStarting: () => Promise | undefined>; /** * Notifies the SFU that a noise cancellation process has stopped. * * @internal */ notifyNoiseCancellationStopped: () => Promise | undefined>; /** * Notifies the SFU about the mute state of the given track types. * @internal */ notifyTrackMuteState: (muted: boolean, ...trackTypes: TrackType[]) => Promise; /** * Will enhance the reported stats with additional participant-specific information (`callStatsReport$` state [store variable](./StreamVideoClient.md/#readonlystatestore)). * This is usually helpful when detailed stats for a specific participant are needed. * * @param sessionId the sessionId to start reporting for. */ startReportingStatsFor: (sessionId: string) => void | undefined; /** * Opposite of `startReportingStatsFor`. * Will turn off stats reporting for a specific participant. * * @param sessionId the sessionId to stop reporting for. */ stopReportingStatsFor: (sessionId: string) => void | undefined; /** * Sets the frequency of the call stats reporting. * * @param intervalInMs the interval in milliseconds to report the stats. */ setStatsReportingIntervalInMs: (intervalInMs: number) => void; /** * Resets the last sent reaction for the user holding the given `sessionId`. This is a local action, it won't reset the reaction on the backend. * * @param sessionId the session id. */ resetReaction: (sessionId: string) => void; /** * Sets the list of criteria to sort the participants by. * * @param criteria the list of criteria to sort the participants by. */ setSortParticipantsBy: CallState['setSortParticipantsBy']; /** * Sends a reaction to the other call participants. * * @param reaction the reaction to send. */ sendReaction: (reaction: SendReactionRequest) => Promise; /** * Blocks the user with the given `userId`. * * @param userId the id of the user to block. */ blockUser: (userId: string) => Promise; /** * Unblocks the user with the given `userId`. * * @param userId the id of the user to unblock. */ unblockUser: (userId: string) => Promise; /** * Kicks the user with the given `userId`. * @param data the kick request. */ kickUser: (data: KickUserRequest) => Promise; /** * Mutes the current user. * * @param type the type of the mute operation. */ muteSelf: (type: TrackMuteType) => Promise | undefined; /** * Mutes all the other participants. * * @param type the type of the mute operation. */ muteOthers: (type: TrackMuteType) => Promise | undefined; /** * Mutes the user with the given `userId`. * * @param userId the id of the user to mute. * @param type the type of the mute operation. */ muteUser: (userId: string | string[], type: TrackMuteType) => Promise; /** * Will mute all users in the call. * * @param type the type of the mute operation. */ muteAllUsers: (type: TrackMuteType) => Promise; /** * Starts recording the call */ startRecording: StartCallRecordingFnType; /** * Stops recording the call */ stopRecording: (type?: CallRecordingType) => Promise; /** * Starts the transcription of the call. * * @param request the request data. */ startTranscription: (request?: StartTranscriptionRequest) => Promise; /** * Stops the transcription of the call. */ stopTranscription: () => Promise; /** * Starts the closed captions of the call. */ startClosedCaptions: (options?: StartClosedCaptionsRequest) => Promise; /** * Stops the closed captions of the call. */ stopClosedCaptions: (options?: StopClosedCaptionsRequest) => Promise; /** * Updates the closed caption settings. * * @param config the closed caption settings to apply */ updateClosedCaptionSettings: (config: Partial) => void; /** * Sends a `call.permission_request` event to all users connected to the call. * The call settings object contains information about which permissions can be requested during a call * (for example, a user might be allowed to request permission to publish audio, but not video). */ requestPermissions: (data: RequestPermissionRequest) => Promise; /** * Allows you to grant certain permissions to a user in a call. * The permissions are specific to the call experience and do not survive the call itself. * * Supported permissions that can be granted are: * - `send-audio` * - `send-video` * - `screenshare` * * @param userId the id of the user to grant permissions to. * @param permissions the permissions to grant. */ grantPermissions: (userId: string, permissions: string[]) => Promise; /** * Allows you to revoke certain permissions from a user in a call. * The permissions are specific to the call experience and do not survive the call itself. * * Supported permissions that can be revoked are: * - `send-audio` * - `send-video` * - `screenshare` * * @param userId the id of the user to revoke permissions from. * @param permissions the permissions to revoke. */ revokePermissions: (userId: string, permissions: string[]) => Promise; /** * Allows you to grant or revoke a specific permission to a user in a call. The permissions are specific to the call experience and do not survive the call itself. * When revoking a permission, this endpoint will also mute the relevant track from the user. This is similar to muting a user with the difference that the user will not be able to unmute afterwards. * Supported permissions that can be granted or revoked: `send-audio`, `send-video` and `screenshare`. * * `call.permissions_updated` event is sent to all members of the call. */ updateUserPermissions: (data: UpdateUserPermissionsRequest) => Promise; /** * Starts the livestreaming of the call. * * @param data the request data. * @param params the request params. */ goLive: (data?: GoLiveRequest, params?: { notify?: boolean; }) => Promise; /** * Stops the livestreaming of the call. */ stopLive: (data?: StopLiveRequest) => Promise; /** * Starts the broadcasting of the call. */ startHLS: () => Promise; /** * Stops the broadcasting of the call. */ stopHLS: () => Promise; /** * Starts the RTMP-out broadcasting of the call. */ startRTMPBroadcasts: (data: StartRTMPBroadcastsRequest) => Promise; /** * Stops all RTMP-out broadcasting of the call. */ stopAllRTMPBroadcasts: () => Promise; /** * Stops the RTMP-out broadcasting of the call specified by it's name. */ stopRTMPBroadcast: (name: string) => Promise; /** * Starts frame by frame recording. * Sends call.frame_recording_started events */ startFrameRecording: (data: StartFrameRecordingRequest) => Promise; /** * Stops frame recording. */ stopFrameRecording: () => Promise; /** * Updates the call settings or custom data. * * @param updates the updates to apply to the call. */ update: (updates: UpdateCallRequest) => Promise; /** * Ends the call. Once the call is ended, it cannot be re-joined. */ endCall: () => Promise; /** * Pins the given session to the top of the participants list. * * @param sessionId the sessionId to pin. */ pin: (sessionId: string) => void; /** * Unpins the given session from the top of the participants list. * * @param sessionId the sessionId to unpin. */ unpin: (sessionId: string) => void; /** * Pins the given session to the top of the participants list for everyone * in the call. * You can execute this method only if you have the `pin-for-everyone` capability. * * @param request the request object. */ pinForEveryone: (request: PinRequest) => Promise; /** * Unpins the given session from the top of the participants list for everyone * in the call. * You can execute this method only if you have the `pin-for-everyone` capability. * * @param request the request object. */ unpinForEveryone: (request: UnpinRequest) => Promise; /** * Query call members with filter query. The result won't be stored in call state. * @param request * @returns */ queryMembers: (request?: Omit) => Promise; /** * Query call participants with optional filters. * * @param data the request data. * @param params optional query parameters. */ queryParticipants: (data?: QueryCallParticipantsRequest, params?: { limit?: number; }) => Promise; /** * Will update the call members. * * @param data the request data. */ updateCallMembers: (data: UpdateCallMembersRequest) => Promise; /** * Schedules an auto-drop timeout based on the call settings. * Applicable only for ringing calls. */ private scheduleAutoDrop; /** * Cancels a scheduled auto-drop timeout. */ private cancelAutoDrop; /** * Retrieves the list of recordings for the current call or call session. * * If `callSessionId` is provided, it will return the recordings for that call session. * Otherwise, all recordings for the current call will be returned. * * @param callSessionId the call session id to retrieve recordings for. * @deprecated use {@link listRecordings} instead. */ queryRecordings: (callSessionId?: string) => Promise; /** * Retrieves the list of recordings for the current call or call session. * * If `callSessionId` is provided, it will return the recordings for that call session. * Otherwise, all recordings for the current call will be returned. * * @param callSessionId the call session id to retrieve recordings for. */ listRecordings: (callSessionId?: string) => Promise; /** * Deletes a recording for the given call session. * * @param callSessionId the call session id that the recording belongs to. * @param filename the recording filename. */ deleteRecording: (callSessionId: string, filename: string) => Promise; /** * Deletes a transcription for the given call session. * * @param callSessionId the call session id that the transcription belongs to. * @param filename the transcription filename. */ deleteTranscription: (callSessionId: string, filename: string) => Promise; /** * Retrieves the list of transcriptions for the current call. * * @returns the list of transcriptions. * @deprecated use {@link listTranscriptions} instead. */ queryTranscriptions: () => Promise; /** * Retrieves the list of transcriptions for the current call. * * @returns the list of transcriptions. */ listTranscriptions: () => Promise; /** * Retrieve call statistics for a particular call session (historical). * Here `callSessionID` is mandatory. * * @param callSessionID the call session ID to retrieve statistics for. * @returns The call stats. * @deprecated use `call.getCallReport` instead. * @internal */ getCallStats: (callSessionID: string) => Promise; /** * Retrieve call report. If the `callSessionID` is not specified, then the * report for the latest call session is retrieved. If it is specified, then * the report for that particular session is retrieved if it exists. * * @param callSessionID the optional call session ID to retrieve statistics for * @returns the call report */ getCallReport: (callSessionID?: string) => Promise; /** * Loads the call participant stats for the given parameters. */ getCallParticipantsStats: (opts: { sessionId?: string; userId?: string; userSessionId?: string; kind?: "timeline" | "details"; }) => Promise; /** * Submit user feedback for the call * * @param rating Rating between 1 and 5 denoting the experience of the user in the call * @param reason The reason/description for the rating * @param custom Custom data */ submitFeedback: (rating: number, { reason, custom, }?: Pick) => Promise; /** * Retrieves the call stats for the current call session in a format suitable * for displaying in map-like UIs. */ getCallStatsMap: (params?: { start_time?: Date | string; end_time?: Date | string; exclude_publishers?: boolean; exclude_subscribers?: boolean; exclude_sfus?: boolean; }, callSessionId?: string | undefined) => Promise; /** * Sends a custom event to all call participants. * * @param payload the payload to send. */ sendCustomEvent: (payload: { [key: string]: any; }) => Promise; /** * Applies the device configuration from the backend. * * @internal */ applyDeviceConfig: (settings: CallSettingsResponse, publish: boolean, skipSpeakerApply: boolean) => Promise; /** * Will begin tracking the given element for visibility changes within the * configured viewport element (`call.setViewport`). * * @param element the element to track. * @param sessionId the session id. * @param trackType the video mode. */ trackElementVisibility: (element: T, sessionId: string, trackType: VideoTrackType) => () => void; /** * Sets the viewport element to track bound video elements for visibility. * * @param element the viewport element. */ setViewport: (element: T) => () => void; /** * Binds a DOM