Skip to content

Commit db5c00d

Browse files
authored
Add new stream attributes (#546)
* Add new stream attributes * fix link
1 parent a695c6f commit db5c00d

File tree

2 files changed

+41
-20
lines changed
  • website/docs/main/compatibility-api

2 files changed

+41
-20
lines changed

website/docs/main/compatibility-api/cxml/voice/stream.mdx

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ puts response
112112
| Attribute | |
113113
| --------------------------------------------------------------------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
114114
| `url` <span className="required-arg">required</span> | Absolute or relative URL. A WebSocket connection to the url will be established and audio will start flowing towards the Websocket server. The only supported protocol is `wss`. For security reasons `ws` is NOT supported. |
115+
| `authBearerToken` <span className="optional-arg">optional</span> | A authentication Bearer token that can be supplied when starting a stream. The remote server can then authenticate the websocket connection request from the supplied token. More information can be found in the [WebSocket connection](#websocket-connection) section. |
115116
| `codec` <span className="optional-arg">optional</span> | The codecs attribute allows you to control the set codec to be used on the stream. **Possible Values**: `L16@24000h` & `L16@16000h` |
116117
| `name` <span className="optional-arg">optional</span> | Unique name for the Stream, per Call. It is used to stop a Stream by name. |
118+
| `realtime` <span className="optional-arg">optional</span> | If `true`, and the stream is [`bidirectional`](/compatibility-api/cxml/voice/connect#bidirectional-media-stream), the stream offers a realtime experience to the call parties by managing packet delays and bursts. If `false`, the use benefits from buffered audio, which can be played out with delay. Default: `false` |
117119
| `track` <span className="optional-arg">optional</span> | This attribute can be one of: `inbound_track`, `outbound_track`, `both_tracks` . Defaults to `inbound_track`. For `both_tracks` there will be both `inbound_track` and `outbound_track` events. |
118120
| `statusCallback` <span className="optional-arg">optional</span> | Absolute or relative URL. SignalWire will make a HTTP GET or POST request to this URL when a Stream is started, stopped or there is an error. |
119121
| `statusCallbackMethod` <span className="optional-arg">optional</span> | GET or POST. The type of HTTP request to use when requesting a statusCallback. Default is POST. |
@@ -133,6 +135,7 @@ You can utilize our REST API to both [start][stream_start] and [stop][stream_sto
133135
| `url` <span className="required-arg">required</span> | Absolute or relative URL. A WebSocket connection to the url will be established and audio will start flowing towards the Websocket server. The only supported protocol is `wss`. For security reasons `ws` is NOT supported. |
134136
| `codec` <span className="optional-arg">optional</span> | The codecs attribute allows you to control the set codec to be used on the stream. **Possible Values**: `L16@24000h` & `L16@16000h` |
135137
| `name` <span className="required-arg">required</span> | Unique name for the Stream, per Call. It is used to stop a Stream by name. |
138+
| `realtime` <span className="optional-arg">optional</span> | If `true`, and the stream is [`bidirectional`](/compatibility-api/cxml/voice/connect#bidirectional-media-stream), the stream offers a realtime experience to the call parties by managing packet delays and bursts. If `false`, the use benefits from buffered audio, which can be played out with delay. Default: `false` |
136139
| `track` <span className="optional-arg">optional</span> | This attribute can be one of: `inbound_track`, `outbound_track`, `both_tracks` . Defaults to `inbound_track`. For `both_tracks` there will be both `inbound_track` and `outbound_track` events. |
137140
| `statusCallback` <span className="optional-arg">optional</span> | Absolute or relative URL. SignalWire will make a HTTP GET or POST request to this URL when a Stream is started, stopped or there is an error. |
138141
| `statusCallbackMethod` <span className="optional-arg">optional</span> | GET or POST. The type of HTTP request to use when requesting a statusCallback. Default is POST. |
@@ -148,7 +151,7 @@ You can utilize our REST API to [create][conference_create] and [update][confere
148151
</TabItem>
149152
</Tabs>
150153

151-
## `StatusCallback` Parameters
154+
## `StatusCallback` parameters
152155

153156
For a `statusCallback`, SignalWire will send a request with the following parameters:
154157

@@ -162,14 +165,32 @@ For a `statusCallback`, SignalWire will send a request with the following parame
162165
| `StreamError` <span className="optional-arg">string</span> | If an error has occurred, this will contain a detailed error message. |
163166
| `Timestamp` <span className="optional-arg">string</span> | The time of the event in ISO 8601 format. |
164167

165-
## WebSocket Messages
166168

167-
There are 5 separate types of events that occur during the Stream's life cycle.
168-
These events are represented via WebSocket Messages: `Connected`, `Start`, `Media`, `DTMF` and `Stop`.
169-
Each message sent is a JSON string.
170-
The type of event which is occurring can be identified by using the `event` property of every JSON object.
171169

172-
### Connected Message
170+
## WebSocket connection
171+
172+
When establishing a stream, SignalWire initiates a WebSocket connection to your specified URL endpoint. The connection begins with an HTTP upgrade request containing the following headers:
173+
174+
| Header | Description |
175+
| :----| :----- |
176+
| Host | The destination server hosting the WebSocket endpoint (e.g., "example.com") |
177+
| Upgrade | Protocol upgrade request indicating a switch to WebSocket (value: "websocket") |
178+
| Connection | Connection type for the upgrade (value: "Upgrade") |
179+
| Sec-WebSocket-Key | Base64-encoded random value used for the WebSocket handshake |
180+
| Sec-WebSocket-Version | WebSocket protocol version (value: "13") |
181+
| Authorization | Bearer token for authentication if `authBearerToken` attribute is provided (format: "Bearer token_here") |
182+
183+
Once the WebSocket connection is established, SignalWire will send various events throughout the stream's lifecycle.
184+
These events are delivered as JSON-formatted WebSocket messages, each containing an `event` property that identifies the message type.
185+
186+
The stream supports five distinct event types:
187+
- **Connected** - Initial handshake message confirming the connection
188+
- **Start** - Stream metadata and configuration details
189+
- **Media** - Audio data packets
190+
- **DTMF** - Touch-tone digit events
191+
- **Stop** - Stream termination notification
192+
193+
### Connected message
173194

174195
The first message sent once a WebSocket connection is established is the Connected event.
175196
This message describes the protocol to expect in the following messages.
@@ -180,7 +201,7 @@ This message describes the protocol to expect in the following messages.
180201
| protocol | Defines the protocol for the WebSocket connections lifetime. eg: "Call" |
181202
| version | Semantic version of the protocol. |
182203

183-
Example Connected Message
204+
Example Connected message
184205

185206
```json
186207
{
@@ -190,7 +211,7 @@ Example Connected Message
190211
}
191212
```
192213

193-
### Start Message
214+
### Start message
194215

195216
This message contains important information about the Stream and is sent immediately after the `Connected` message.
196217
It is only sent once at the start of the Stream.
@@ -210,7 +231,7 @@ It is only sent once at the start of the Stream.
210231
| start.mediaFormat.sampleRate | The Sample Rate in Hertz of the upcoming audio data. Default value is 8000, which is the rate of PCMU. |
211232
| start.mediaFormat.channels | The number of channels in the input audio data. Default value is 1. For `both_tracks` it will be 2. |
212233

213-
Example Start Message
234+
Example Start message
214235

215236
```json
216237
{
@@ -235,7 +256,7 @@ Example Start Message
235256
}
236257
```
237258

238-
### Media Message
259+
### Media message
239260

240261
This message type encapsulates the raw audio data.
241262

@@ -249,7 +270,7 @@ This message type encapsulates the raw audio data.
249270
| media.timestamp | Presentation Timestamp in Milliseconds from the start of the stream. |
250271
| media.payload | Raw audio encoded in base64. |
251272

252-
Example Media Messages
273+
Example media messages
253274

254275
Outbound
255276

@@ -280,11 +301,11 @@ Inbound
280301
}
281302
```
282303

283-
### Stop Message
304+
### Stop message
284305

285306
A stop message will be sent when the Stream is either stopped or the Call has ended.
286307

287-
Example Stop Message
308+
Example stop message
288309

289310
```json
290311
{
@@ -298,7 +319,7 @@ Example Stop Message
298319
| event | The string value of `stop`. |
299320
| sequenceNumber | Number used to keep track of message sending order. First message starts with number "1" and then is incremented for each message. |
300321

301-
### DTMF Message
322+
### DTMF message
302323

303324
A DTMF message will be sent when the Stream receives a DTMF tone.
304325

@@ -311,7 +332,7 @@ A DTMF message will be sent when the Stream receives a DTMF tone.
311332
| dtmf.duration | The duration of the DTMF in milliseconds. |
312333
| dtmf.digit | The digit, as a string, that corresponds to the DTMF. |
313334

314-
Example DTMF Message
335+
Example DTMF message
315336

316337
```json
317338
{
@@ -325,7 +346,7 @@ Example DTMF Message
325346
}
326347
```
327348

328-
### Clear Message
349+
### Clear message
329350

330351
Send the clear event message if you would like to interrupt the audio that has been sent various media event messages. This will empty all buffered audio.
331352

@@ -334,7 +355,7 @@ Send the clear event message if you would like to interrupt the audio that has b
334355
| event | The string value of `clear`. |
335356
| streamSid | The unique identifier of the stream as a string. |
336357

337-
Example Clear Message
358+
Example Clear message
338359
```json
339360
{
340361
"event": "clear",
@@ -410,7 +431,7 @@ This can be done by using the nested `<Parameter>` cXML noun. These parameters w
410431
</Response>
411432
```
412433

413-
## Notes on Usage
434+
## Notes on usage
414435

415436
- The url does not support query string parameters. To pass custom key value pairs to the WebSocket, make use of Custom Parameters instead.
416437
- There is a one to one mapping of a stream to a websocket connection, therefore there will be at most one call being streamed over a single websocket connection. Information will be provided so that you can handle handle multiple inbound connections and manage the association between the unique stream identifier (StreamSid) and the connection.

website/docs/main/compatibility-api/guides/voice/python/utilizing-websockets-and-call-streams/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Then we can use asyncio to create a non-blocking for loop that iterates over the
5555
Finally, we will parse our messages based on their `event` designation.
5656

5757
The `start` event provides details such as the callSid, streamSid, the tracks we can expect, and more. We will only use the `callSid` to name and organize our recordings.
58-
A full example of what a `start` even returns can be found in our `<stream>` documentation [here](/compatibility-api/cxml/voice/stream#websocket-messages).
58+
A full example of what a `start` even returns can be found in our `<stream>` documentation [here](/compatibility-api/cxml/voice/stream#websocket-connection).
5959

6060
The `media` events hold the base64-encoded audio that we will use to compile our wave files. We can do this by decoding the base64 and appending the decoded payload to the appropriate list.
6161

0 commit comments

Comments
 (0)