WebSocket

Represents a WebSocket instance that provides the API for creating and managing an outgoing or incoming WebSocket connection, as well as for sending and…

View as Markdown

Represents a WebSocket instance that provides the API for creating and managing an outgoing or incoming WebSocket connection, as well as for sending and receiving data to/from it.

Constructor

1new WebSocket(url: string, parameters?: WebSocketParameters)

Parameters

url
stringRequired
parameters
WebSocketParameters
1new WebSocket(url: string, parameters?: WebSocketParameters)

Parameters

url
stringRequired
parameters
WebSocketParameters

Methods

addEventListener

Adds a handler for the specified WebSocketEvents event. Use only functions as handlers; anything except a function leads to the error and scenario termination when a handler is called.

1addEventListener(event: WebSocketEvents | T, callback: (event: _WebSocketEvents[T]) => any): void

Parameters

event
WebSocketEvents | TRequired
callback
(event: _WebSocketEvents[T]) => anyRequired

clearMediaBuffer

Clears the media buffer.

1clearMediaBuffer(parameters?: ClearMediaBufferParameters): void

Parameters

parameters
ClearMediaBufferParameters

close

Closes the WebSocket connection or connection attempt.

1close(): void

id

Returns the WebSocket’s id.

1id(): string

removeEventListener

Removes a handler for the specified WebSocketEvents event.

1removeEventListener(event: WebSocketEvents | T, callback?: (event: _WebSocketEvents[T]) => any): void

Parameters

event
WebSocketEvents | TRequired
callback
(event: _WebSocketEvents[T]) => any

send

Enqueues the specified data to be transmitted over the WebSocket connection.

1send(data: string): void

Parameters

data
stringRequired

sendMediaTo

Starts sending media from the websocket to the media unit. WebSocket works in real time and the recommended duration of one audio chunk is 20 milliseconds.

1sendMediaTo(mediaUnit: VoxMediaUnit, parameters?: SendMediaParameters): void

Parameters

mediaUnit
VoxMediaUnitRequired
parameters
SendMediaParameters

stopMediaTo

Stops sending media from the websocket to the media unit.

1stopMediaTo(mediaUnit: VoxMediaUnit, parameters?: SendMediaParameters): void

Parameters

mediaUnit
VoxMediaUnitRequired
parameters
SendMediaParameters

Properties

onclose
((event: _WebSocketCloseEvent) => any) | null

Event handler to call when the connection is closed.

oncreated
((event: _WebSocketCreatedEvent) => any) | null

Event handler to call when the connection is created.

onerror
((event: _WebSocketErrorEvent) => any) | null

Event handler to call when an error occurs.

onmediaended
((event: _WebSocketMediaEndedEvent) => any) | null

Event handler to call after the end of the audio stream.

onmediastarted
((event: _WebSocketMediaStartedEvent) => any) | null

Event handler to call when the audio stream is started playing.

onmessage
((event: _WebSocketMessageEvent) => any) | null

Event handler to call when a message is received.

onopen
((event: _WebSocketOpenEvent) => any) | null

Event handler to call when the connection is open (ready to send and receive data).

readyState
WebSocketReadyState

readonly

Returns the current state of the WebSocket connection.

url
string

readonly

Returns the absolute URL of the WebSocket. For outgoing connection, it is the URL to which to connect; for incoming, it is the WebSocket session URL.