Stream
The <Stream>
instruction starts streaming the media from a call to a specific WebSocket address in near-real-time. Audio will be delivered as base64-encoded RTP payloads (no headers), wrapped in JSON payloads.
Attributes
ATTRIBUTE | DESCRIPTION | OPTIONS | DEFAULT |
---|---|---|---|
url | The destination WebSocket address where the stream is going to be delivered. | - | |
track | Specifies which track should be streamed. | inbound_track , outbound_track , both_tracks | inbound_track |
name | Specifies custom name for the stream instance | - | |
codec | Specifies the codec to be used for the streamed audio. When set to 'default' or when transcoding is not possible, the codec from the call will be used. Currently, transcoding is only supported between PCMU and PCMA codecs. | PCMU , PCMA , G722 , OPUS , AMR-WB , default | default |
bidirectionalMode | Bidirectional streaming mode | mp3 , rtp | mp3 |
bidirectionalCodec | Bidirectional streaming codec, used only with bidirectionalMode=rtp | PCMU , PCMA , G722 , OPUS , AMR-WB | PCMU |
Examples
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Start>
<Stream url="wss://yourdomain.com/stream" track="both_tracks" />
</Start>
</Response>
Expected callbacks
stream-started
{
"CallSid": "v2:7V3r4VFCGLTzKLOveE0-7vM9dX17-NRQgU1byo-uuOIX9JcDadLLKw",
"Timestamp": "2023-09-06T09:05:14.080710Z",
"AccountSid": "19a75cea-02c6-4b9a-84fa-c9bc8341feb8",
"StreamName": "stream name",
"StreamEvent": "stream-started"
}
stream-stopped
{
"CallSid": "v2:7V3r4VFCGLTzKLOveE0-7vM9dX17-NRQgU1byo-uuOIX9JcDadLLKw",
"Timestamp": "2023-09-06T09:05:14.080710Z",
"AccountSid": "19a75cea-02c6-4b9a-84fa-c9bc8341feb8",
"StreamName": "stream name",
"StreamEvent": "stream-stopped"
}
stream-failed
{
"CallSid": "v2:7V3r4VFCGLTzKLOveE0-7vM9dX17-NRQgU1byo-uuOIX9JcDadLLKw",
"Timestamp": "2023-09-06T09:05:14.080710Z",
"AccountSid": "19a75cea-02c6-4b9a-84fa-c9bc8341feb8",
"StreamName": "stream name",
"StreamEvent": "stream-failed"
}
#### Status callback HTTP attributes
<table class="table">
<tbody>
<tr>
<td>ATTRIBUTE</td>
<td>DESCRIPTION</td>
</tr>
<tr>
<td><code>Timestamp</code></td>
<td>The timestamp when the event was fired, given as UTC in <a href="https://www.php.net/manual/en/class.datetime.php#datetime.constants.rfc2822">RFC 2822</a> format.</td>
</tr>
<tr>
<td><code>CallSid</code></td>
<td>A unique identifier for this call, generated by Telnyx.</td>
</tr>
<tr>
<td><code>AccountSid</code></td>
<td>A unique identifier for the account generating this call.</td>
</tr>
<tr>
<td><code>StreamName</code></td>
<td>The name of the stream</td>
</tr>
<tr>
<td><code>StreamEvent</code></td>
<td>The event name. Possible values: <code>stream-started</code>, <code>stream-stopped</code>, <code>stream-failed</code></td>
</tr>
</tbody>
</table>