Skip to main content

WebSocket Messages

When streaming a call, JSON messages are sent by both parties on the stream (CarrierX and your application). There are 6 types of messages:

note

The connected, start, and stop events are only sent by CarrierX and cannot be sent by your application.

Fields on the objects below are marked in three ways:

  • read only - A field sent only by CarrierX.
  • write only - A field sent only by your application.
  • read-write - A field sent by both CarrierX and your application.

Connected Event​

CarrierX sends the connected event once a WebSocket connection is established, and is the first message your WebSocket server receives.

Connected Event Object​

AttributeData TypeDescription
event
read only
stringconnected
protocol
read only
stringCall
version
read only
stringThe version of the Call protocol.

Example Connected Event​

{
"event": "connected",
"protocol": "Call",
"version": "0.2.0"
}

Start Event​

The start message contains metadata about the stream and any custom Parameters. The start event is sent once immediately after the Connected Event.

Start Event Object​

AttributeData TypeDescription
event
read only
stringstart
sequenceNumber
read only
integerThe sequenceNumber is a sequential integer to help reorder messages delivered out of order. sequenceNumber will always be 1 in the start event.
start
read only
objectThe Start Message Object containing call metadata and custom Parameter key/value pairs.

Example Start Event​

{
"event": "start",
"sequenceNumber": 1,
"start": {
"callId": "7a9a4e28-1631-11ef-a79b-d4ce64f0cdf9",
"tracks": [
"inbound",
"outbound"
],
"mediaFormat": {
"encoding": "audio/x-mulaw",
"sampleRate": 8000
},
"customParameters": {
"RemoteParty": "Bob",
"FirstName": "Jane",
"LastName":"Doe"
}
}
}

Start Message Object​

The Start Message Object contains call metadata and custom Parameter key/value pairs.

AttributeData TypeDescription
callId
read only
stringThe secure ID of the call is unique per call and will be consistent across all subsequent events.
customParameters
read only
objectAn object defined by the Parameter tags included in the Stream. See the example on the right.
mediaFormat
read only
objectThe Media Format Object is the encoding and sample rate of the media being streamed.
tracks
read only
array of stringsThe tracks that will be streamed as Media Events, and can be any of inbound, outbound, or mixed.

Media Format Object​

The Media Format Object describes the encoding and sample rate of the media being streamed.

AttributeData TypeDescription
encoding
read only
stringThe MIME type describing the encoding of the media stream, for instance audio/x-mulaw.
sampleRate
read only
integerThe sample rate, or number of samples per second, of the media stream.

Media Event​

The media message contains the actual stream content. The media message is used to send audio to the call.

Media Event Object​

AttributeData TypeDescription
event
read-write
stringmedia
media
read-write
objectThe Media Message Object containing a slice of call content.
sequenceNumber
read only
integerThe sequenceNumber is a sequential integer to help reorder messages delivered out of order. sequenceNumber will increment with every message.

Example Media Event Object​

{
"event":"media",
"sequenceNumber":1495,
"media":{
"callId":"80e6178c-1701-11ef-927b-e6b664f0cdf9",
"track":"outbound",
"timestamp":14712,
"chunk":736,
"payload":"sUhORChD6K6nr6aqpq3CP0yxra/ePPDeNmj7fL65qq/vNSxaVi0nSaqurdnHuG++uFhCy7GyWzQtw7dOO2atu9s7N0s4M0U7O8m8trziatqsyDtQQj8sMUZZt2hassFtSdP2PTw5TE85MkvE1UDbv9jOLzT2OTAtP1W0sb2qrtpYu2Q6LzpOOzswWb+/607Gy7t1Oc05JzBHUTE+urHOuQ=="
}
}

Media Message Object​

AttributeData TypeDescription
callId
read-write
stringThe secure ID of the call is unique per call and will be consistent across all subsequent events.
chunk
read only
integerSimilar to sequenceNumber, chunk is the sequential integer indicating the order of the media chunks or slices. However, chunk is within the particular track.
payload
read-write
stringBase64 encoded string of the bytes of the chunk of audio. Concatenating all of the decoded bytes, ordered by chunk for a particular track will render the audio, encoded as identified in the Start Event Object.
timestamp
read only
integerThe timestamp of the audio chunk, in milliseconds. The timestamp can be relative or absolute and is defined by <Stream timestampStart="">. Relative timestamps start at 0. Absolute timestamps start at the epoch (1970-01-01T00:00:00).
track
read only
stringThe track the media belongs to, and is one of inbound, outbound, or mixed.

Clear Event​

Your application may send the clear message in bidirectional streams to delete any sent, but unplayed media payload, clearing all buffered audio.

Clear Event Object​

AttributeData TypeDescription
event
write only
stringclear

Example Clear Event Object:​

{
"event": "clear"
}

Mark Eventbeta​

The mark message is used to request notification when all audio previously sent to CarrierX has been played to the caller. The mark message is only supported in bidirectional streams.

Mark Event Object​

AttributeData TypeDescription
callId
read-write
stringThe secure ID of the call is unique per call and will be consistent across all subsequent events.
event
read-write
stringmark
mark
read-write
objectThe Mark Message Object containing details about the mark event.
sequenceNumber
read only
integerThe sequenceNumber is a sequential integer to help reorder messages delivered out of order. sequenceNumber will increment with every message.

Mark Message Object​

AttributeData TypeDescription
name
read-write
stringWhen you send a mark event, you can set the name to any string. When CarrierX returns the mark event, it is sent with the same name you supplied.
status
read only
stringThe outcome of the mark. Values are:
  • completed: all audio sent before the mark was played to the caller. This is the normal case, and the only status that means the caller heard the audio.
  • cleared: a clear message arrived while the mark was pending. The queued audio was deleted and never played to the caller. All pending marks are returned with the cleared status at the same time.
  • limit: the mark was refused because too many marks were already pending. The current limit is 1000 pending marks. The mark is returned immediately without being queued, and the audio position it refers to is not tracked.

Example Mark Event Object Sent by Your Application​

{
"event": "mark",
"callId": "cb8b371e-b203-11f1-9d31-ebf7282e1005",
"mark": {
"name": "intro:0"
}
}

Example Mark Event Object Reply Received from CarrierX:​

{
"event": "mark",
"sequenceNumber": 41,
"callId": "cb8b371e-b203-11f1-9d31-ebf7282e1005",
"mark": {
"name": "intro:0",
"status": "completed"
}
}

Stop Event​

The stop event is sent once per call, is the last message sent, and represents the end of all streamed tracks.

Stop Event Object​

AttributeData TypeDescription
callId
read only
stringThe secure ID of the call is unique per call and will be consistent across all subsequent events.
event
read only
stringstop
sequenceNumber
read only
integerThe sequenceNumber is a sequential integer to help reorder messages delivered out of order. sequenceNumber will increment with every message.

Example Stop Event Object​

{
"event":"stop",
"sequenceNumber":433,
"callId":"f68c10b6-1708-11ef-9daa-27d264f0cdf9"
}