Call (interface)
Interface that represents a call and provides the API to manage it.
Methods
- addEventListener
- addStream
- answer
- hangup
- hold
- muteMicrophone
- reject
- removeEventListener
- removeStream
- replaceStream
- sendDTMF
- sendInfo
- sendMessage
- start
- startScreenSharing
- stopScreenSharing
- toggleMicrophone
- unmuteMicrophone
Properties
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
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
Returns: Promise<void>
Throws
- CallWrongStateError — if the call is in the CallState.Failed, CallState.Disconnecting, or CallState.Disconnected state
- StreamTypeMismatchError — if the stream is of the StreamType.ScreenVideo type
- CallOnHoldError — if the call is currently on hold
- InactiveStreamError — if the stream is not active
- StreamUpdateFailedError — if the operation has failed
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:
- CallEvent.Connected is triggered when the call connects successfully.
- CallEvent.Failed is triggered if the call fails to connect.
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
Returns: Promise<void>
Throws
- CallWrongDirectionError — if the method is called for an outgoing call
- CallWrongStateError — if the call is in a state different from CallState.Created or CallState.Reconnecting
- CallInternalError — if the operation has failed
hangup
hangup(headers?: Record<string, string>): void
Terminates the call.
The following events are triggered depending on the call state:
- CallEvent.Disconnected is triggered on this call.
- CallEvent.Disconnected is triggered on the remote participant side if the call has connected.
- CallEvent.Disconnected is triggered on the callee side if an outgoing call is still connecting.
- CallEvent.Failed is triggered on the caller side if an incoming call has not been answered.
Parameters
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
Returns: Promise<void>
Throws
- CallWrongStateError — if the call is not in the CallState.Connected state
- CallOnHoldError on the attempt to hold the call that is already on hold
- CallNotOnHoldError on the attempt to resume the call that is currently not on hold
- CallInternalError — if the operation has failed
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:
- CallEvent.Disconnected is triggered on the callee side.
- CallEvent.Failed is triggered on the caller side.
Parameters
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
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
Returns: Promise<void>
Throws
- CallWrongStateError — if the call is in the CallState.Failed, CallState.Disconnecting, or CallState.Disconnected state
- StreamTypeMismatchError — if the stream is of the StreamType.ScreenAudio or StreamType.ScreenVideo type
- CallOnHoldError — if the call is currently on hold
- StreamUpdateFailedError — if the operation has failed
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
Returns: Promise<void>
Throws
- CallWrongStateError — if the call is in the CallState.Failed, CallState.Disconnecting, or CallState.Disconnected state
- StreamTypeMismatchError — if the stream is of StreamType.ScreenAudio or StreamType.ScreenVideo type
- InactiveStreamError — if the stream is not active
- StreamUpdateFailedError — if the operation has failed
sendDTMF
sendDTMF(tones: string): void
Sends DTMF(s) within the call.
Parameters
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
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
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:
- CallEvent.StartRinging is triggered when the remote participant’s device starts ringing.
- CallEvent.Connected is triggered when the call connects successfully.
- CallEvent.Failed is triggered if the call fails to connect, including when the callee rejects the call.
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
- CallWrongDirectionError — if the method is called for an incoming call
- CallWrongStateError — if the call is in a state different from CallState.Created or CallState.Reconnecting
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
Returns: Promise<void>
Throws
- CallWrongStateError — if the call is not in the CallState.Connected state
- CallOnHoldError — if the call is currently on hold
- InactiveStreamError — if the stream is not active
- StreamUpdateFailedError — if the operation has failed or the screen sharing is already being sent to the call
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
- CallWrongStateError — if the call is not in the CallState.Connected state
- CallOnHoldError — if the call is currently on hold
- StreamUpdateFailedError — if the operation has failed or the screen sharing is not currently being sent
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
state: ReadonlyWatchable<CallState>
Watchable property that allows getting the current call state and observing its changes.
videoSendingStatus
videoSendingStatus: ReadonlyWatchable<VideoSendingStatus>
Watchable property indicating the current sending status of the local video stream.
This property holds one of the following values:
- VideoSendingStatus.Sending: A local video stream is being sent.
- VideoSendingStatus.NotSending: No local video is being sent.
- VideoSendingStatus.Pending: A video stream is currently being added, removed, or replaced via the Call.addStream, Call.removeStream, or Call.replaceStream API.
The initial status when the call is connected is available in the CallEvent.Connected event payload.
Since: 5.2.0