Skip to navigation

Call (interface)

Web SDK v5 API reference
View as Markdown

Call

Interface that represents a call and provides the API to manage it.

Methods

addEventListener

addEventListener(eventName: CallEvent, listener: (event: AnyCallEvent) => void | Promise<void>, options: ListenerOptions): void

Registers a handler for the specified event.

One event can have more than one handler; handlers are executed in order of their registration.

Parameters

ParameterTypeRequirementDescription
eventNameCallEventRequiredEvent name
listener(event: AnyCallEvent) => void | Promise<void>RequiredHandler function that is triggered when an event of the specified type occurs
optionsListenerOptionsRequiredObject that specifies characteristics about the event listener

Returns: void

addStream

addStream(stream: LocalStream): Promise<void>

Starts sending an audio or video stream to the call.

If a video stream is added to a call that was originally started as audio only, the remote participant receives the CallEvent.CallUpgrade event and can accept or reject the request to switch the call to video.

Returns a promise that is resolved when the operation is completed.

Parameters

ParameterTypeRequirementDescription
streamLocalStreamRequiredAudio or video stream

Returns: Promise<void>

Throws

answer

answer(settings?: CallSettings): Promise<void>

Answers the call. This method should be used only for incoming calls.

Calling this method initiates the connection process. One of the following events is triggered as a result:

Returns a promise that is resolved if the call connection process has started successfully. A resolved promise does not mean that the call is connected. You should subscribe to CallEvent.Connected to be notified that the call is established.

Parameters

ParameterTypeRequirementDescription
settingsCallSettingsOptionalCall settings with additional call parameters, such as the preferred video codec, custom data, extra headers, etc.

Returns: Promise<void>

Throws

hangup

hangup(headers?: Record<string, string>): void

Terminates the call.

The following events are triggered depending on the call state:

Parameters

ParameterTypeRequirementDescription
headersRecord<string, string>OptionalOptional set of headers to send to the Voximplant Cloud. Names should begin with “X-” to be processed by the SDK.

Returns: void

hold

hold(enable: boolean): Promise<void>

Holds or unholds the call.

Returns a promise that is resolved when the operation is completed.

Parameters

ParameterTypeRequirementDescription
enablebooleanRequiredWhether to hold or unhold the call

Returns: Promise<void>

Throws

muteMicrophone

muteMicrophone(): void

Mutes the audio in the call.

Returns: void

reject

reject(rejectMode: RejectMode, headers?: Record<string, string>): void

Rejects an incoming call.

Calling this method terminates the incoming call attempt. The following events are triggered as a result:

Parameters

ParameterTypeRequirementDescription
rejectModeRejectModeRequiredCall rejection mode
headersRecord<string, string>OptionalOptional set of headers to send to the Voximplant Cloud. Names should begin with “X-” to be processed by the SDK.

Returns: void

Throws

CallWrongDirectionError If the method is called for an outgoing call.

removeEventListener

removeEventListener(eventName: CallEvent, listener: (event: AnyCallEvent) => void | Promise<void>): void

Removes a previously registered handler for the specified event.

Parameters

ParameterTypeRequirementDescription
eventNameCallEventRequiredEvent name
listener(event: AnyCallEvent) => void | Promise<void>RequiredHandler function to remove from the event target

Returns: void

removeStream

removeStream(stream: LocalStream): Promise<void>

Stops sending audio or video stream to the call.

Returns a promise that is resolved when the operation is completed.

Parameters

ParameterTypeRequirementDescription
streamLocalStreamRequired

Returns: Promise<void>

Throws

replaceStream

replaceStream(stream: LocalStream, oldStream?: LocalStream): Promise<void>

Replaces the local audio or video stream that is currently being sent to the call with another local audio or video stream.

Returns a promise that is resolved when the operation is completed.

Parameters

ParameterTypeRequirementDescription
streamLocalStreamRequiredNew local stream
oldStreamLocalStreamOptionalStream to replace

Returns: Promise<void>

Throws

sendDTMF

sendDTMF(tones: string): void

Sends DTMF(s) within the call.

Parameters

ParameterTypeRequirementDescription
tonesstringRequiredDTMF(s)

Returns: void

Throws

InvalidArgumentsError if the tones parameter is an empty string

sendInfo

sendInfo(mimeType: ${string}/${string}, body: string, headers?: Record<string, string>): void

Sends an INFO message within the call.

Parameters

ParameterTypeRequirementDescription
mimeType${string}/${string}RequiredMIME type of the info
bodystringRequiredCustom string data
headersRecord<string, string>OptionalOptional set of headers to be sent with the message. Names should begin with “X-” to be processed by the SDK.

Returns: void

Throws

InvalidMimeTypeError if the provided mimeType is in an invalid format

sendMessage

sendMessage(message: string): void

Sends a message within the call.

Implemented atop of SIP INFO for communication between the call endpoint and the Voximplant Cloud.

Parameters

ParameterTypeRequirementDescription
messagestringRequiredMessage text

Returns: void

start

start(): Promise<void>

Starts the call. This method should be used only for outgoing calls.

Calling this method initiates the call setup. The following events may be triggered as a result:

Returns a promise that is resolved if the call connection process has started successfully. A resolved promise does not mean that the call is connected. You should subscribe to CallEvent.Connected to be notified that the call is established.

Returns: Promise<void>

Throws

startScreenSharing

startScreenSharing(stream: LocalScreenSharingStream[]): Promise<void>

Starts sending a screen sharing stream to the call.

Returns a promise that is resolved when the operation is completed.

Parameters

ParameterTypeRequirementDescription
streamLocalScreenSharingStream[]RequiredArray of screen sharing streams

Returns: Promise<void>

Throws

stopScreenSharing

stopScreenSharing(): Promise<void>

Stops sending a screen sharing stream to the call.

Returns a promise that is resolved when the operation is completed.

Returns: Promise<void>

Throws

toggleMicrophone

toggleMicrophone(): boolean

Toggles the audio mute status in the call.

Returns: boolean

unmuteMicrophone

unmuteMicrophone(): void

Unmutes the audio in the call.

Returns: void

Properties

destination

destination: string

Destination that the call has been created with.

direction

direction: CallDirection

Call direction.

duration

duration: number

Call duration in milliseconds.

hasScreenSharing

hasScreenSharing: ReadonlyWatchable<boolean>

Watchable property that allows getting the screen sharing sending status and observing its changes.

id

id: string

Call id.

isMicrophoneMuted

isMicrophoneMuted: ReadonlyWatchable<boolean>

Watchable property that allows getting the audio mute status and observing its changes.

isOnHold

isOnHold: ReadonlyWatchable<boolean>

Watchable property that allows getting whether the call is on hold.

isVideoEnabled

isVideoEnabled: ReadonlyWatchable<boolean>

Watchable property that indicates whether the video is enabled and allows observing its changes.

localStreams

localStreams: ReadonlyWatchable<Set<LocalStream>>

Watchable property that allows getting the array of the local audio and video streams that are currently being sent.

remoteDisplayName

remoteDisplayName: ReadonlyWatchable<null | string>

Watchable property that allows getting the call participant user display name and observing its changes.

Null for outgoing calls until the CallEvent.Connected event is triggered.

remoteSipUri

remoteSipUri: ReadonlyWatchable<null | string>

Watchable property that allows getting the call participant sip URI and observing its changes.

Null for outgoing calls until the CallEvent.Connected event is triggered.

remoteStreams

remoteStreams: ReadonlyWatchable<Set<RemoteStream>>

Watchable property that allows getting the array of the remote audio and video streams that are currently being received.

state

Watchable property that allows getting the current call state and observing its changes.

videoSendingStatus

Watchable property indicating the current sending status of the local video stream.

This property holds one of the following values:

The initial status when the call is connected is available in the CallEvent.Connected event payload.

Since: 5.2.0