The Stream resource represents a live audio stream during a live call.
Creating a Stream resource creates a unidirectional Media Stream. You can stop a unidirectional Media Stream by updating the status
of a Stream resource , regardless of whether the Stream was created via TwiML (with <Start><Stream>
) or via REST API (with the Stream resource).
Encoding type: application/x-www-form-urlencoded
Property name Type Required Description Child properties
Relative or absolute URL where WebSocket connection will be established.
The user-specified name of this Stream, if one was given when the Stream was created. This can be used to stop the Stream.
Track enum<string> Optional The tracks to be included in the Stream. Possible values are inbound_track
, outbound_track
, both_tracks
. Default value is inbound_track
.
Possible values: inbound_track
outbound_track
both_tracks
StatusCallback string<uri> Optional Absolute URL to which Twilio sends status callback HTTP requests.
StatusCallbackMethod enum<http-method> Optional The HTTP method Twilio uses when sending status_callback
requests. Possible values are GET
and POST
. Default is POST
.
Parameter1.Name string Optional Parameter1.Value string Optional Parameter2.Name string Optional Parameter2.Value string Optional Parameter3.Name string Optional Parameter3.Value string Optional Parameter4.Name string Optional Parameter4.Value string Optional Parameter5.Name string Optional Parameter5.Value string Optional Parameter6.Name string Optional Parameter6.Value string Optional Parameter7.Name string Optional Parameter7.Value string Optional Parameter8.Name string Optional Parameter8.Value string Optional Parameter9.Name string Optional Parameter9.Value string Optional Parameter10.Name string Optional Parameter10.Value string Optional Parameter11.Name string Optional Parameter11.Value string Optional Parameter12.Name string Optional Parameter12.Value string Optional Parameter13.Name string Optional Parameter13.Value string Optional Parameter14.Name string Optional Parameter14.Value string Optional Parameter15.Name string Optional Parameter15.Value string Optional Parameter16.Name string Optional Parameter16.Value string Optional Parameter17.Name string Optional Parameter17.Value string Optional Parameter18.Name string Optional Parameter18.Value string Optional Parameter19.Name string Optional Parameter19.Value string Optional Parameter20.Name string Optional Parameter20.Value string Optional Parameter21.Name string Optional Parameter21.Value string Optional Parameter22.Name string Optional Parameter22.Value string Optional Parameter23.Name string Optional Parameter23.Value string Optional Parameter24.Name string Optional Parameter24.Value string Optional Parameter25.Name string Optional Parameter25.Value string Optional Parameter26.Name string Optional Parameter26.Value string Optional Parameter27.Name string Optional Parameter27.Value string Optional Parameter28.Name string Optional Parameter28.Value string Optional Parameter29.Name string Optional Parameter29.Value string Optional Parameter30.Name string Optional Parameter30.Value string Optional Parameter31.Name string Optional Parameter31.Value string Optional Parameter32.Name string Optional Parameter32.Value string Optional Parameter33.Name string Optional Parameter33.Value string Optional Parameter34.Name string Optional Parameter34.Value string Optional Parameter35.Name string Optional Parameter35.Value string Optional Parameter36.Name string Optional Parameter36.Value string Optional Parameter37.Name string Optional Parameter37.Value string Optional Parameter38.Name string Optional Parameter38.Value string Optional Parameter39.Name string Optional Parameter39.Value string Optional Parameter40.Name string Optional Parameter40.Value string Optional Parameter41.Name string Optional Parameter41.Value string Optional Parameter42.Name string Optional Parameter42.Value string Optional Parameter43.Name string Optional Parameter43.Value string Optional Parameter44.Name string Optional Parameter44.Value string Optional Parameter45.Name string Optional Parameter45.Value string Optional Parameter46.Name string Optional Parameter46.Value string Optional Parameter47.Name string Optional Parameter47.Value string Optional Parameter48.Name string Optional Parameter48.Value string Optional Parameter49.Name string Optional Parameter49.Value string Optional Parameter50.Name string Optional Parameter50.Value string Optional Parameter51.Name string Optional Parameter51.Value string Optional Parameter52.Name string Optional Parameter52.Value string Optional Parameter53.Name string Optional Parameter53.Value string Optional Parameter54.Name string Optional Parameter54.Value string Optional Parameter55.Name string Optional Parameter55.Value string Optional Parameter56.Name string Optional Parameter56.Value string Optional Parameter57.Name string Optional Parameter57.Value string Optional Parameter58.Name string Optional Parameter58.Value string Optional Parameter59.Name string Optional Parameter59.Value string Optional Parameter60.Name string Optional Parameter60.Value string Optional Parameter61.Name string Optional Parameter61.Value string Optional Parameter62.Name string Optional Parameter62.Value string Optional Parameter63.Name string Optional Parameter63.Value string Optional Parameter64.Name string Optional Parameter64.Value string Optional Parameter65.Name string Optional Parameter65.Value string Optional Parameter66.Name string Optional Parameter66.Value string Optional Parameter67.Name string Optional Parameter67.Value string Optional Parameter68.Name string Optional Parameter68.Value string Optional Parameter69.Name string Optional Parameter69.Value string Optional Parameter70.Name string Optional Parameter70.Value string Optional Parameter71.Name string Optional Parameter71.Value string Optional Parameter72.Name string Optional Parameter72.Value string Optional Parameter73.Name string Optional Parameter73.Value string Optional Parameter74.Name string Optional Parameter74.Value string Optional Parameter75.Name string Optional Parameter75.Value string Optional Parameter76.Name string Optional Parameter76.Value string Optional Parameter77.Name string Optional Parameter77.Value string Optional Parameter78.Name string Optional Parameter78.Value string Optional Parameter79.Name string Optional Parameter79.Value string Optional Parameter80.Name string Optional Parameter80.Value string Optional Parameter81.Name string Optional Parameter81.Value string Optional Parameter82.Name string Optional Parameter82.Value string Optional Parameter83.Name string Optional Parameter83.Value string Optional Parameter84.Name string Optional Parameter84.Value string Optional Parameter85.Name string Optional Parameter85.Value string Optional Parameter86.Name string Optional Parameter86.Value string Optional Parameter87.Name string Optional Parameter87.Value string Optional Parameter88.Name string Optional Parameter88.Value string Optional Parameter89.Name string Optional Parameter89.Value string Optional Parameter90.Name string Optional Parameter90.Value string Optional Parameter91.Name string Optional Parameter91.Value string Optional Parameter92.Name string Optional Parameter92.Value string Optional Parameter93.Name string Optional Parameter93.Value string Optional Parameter94.Name string Optional Parameter94.Value string Optional Parameter95.Name string Optional Parameter95.Value string Optional Parameter96.Name string Optional Parameter96.Value string Optional Parameter97.Name string Optional Parameter97.Value string Optional Parameter98.Name string Optional Parameter98.Value string Optional Parameter99.Name string Optional Parameter99.Value string Optional Select from available examples
Create a Stream resource during a live call in order to start a new unidirectional Media Stream. Twilio sends the call's forked audio stream to the url
specified in this request.
A sample request is shown below.
_21 // Download the helper library from https://www.twilio.com/docs/node/install
_21 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21 // Find your Account SID and Auth Token at twilio.com/console
_21 // and set the environment variables. See http://twil.io/secure
_21 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21 const authToken = process.env.TWILIO_AUTH_TOKEN;
_21 const client = twilio(accountSid, authToken);
_21 async function createStream() {
_21 const stream = await client
_21 .calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_21 name: "My Media Stream",
_21 url: "wss://example.com/a-websocket-server",
_21 console.log(stream.sid);
_10 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10 "sid": "MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "name": "My Media Stream",
_10 "status": "in-progress",
_10 "date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
_10 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
You can also create a unidirectional Media Stream with custom parameters.
Twilio sends these custom parameters to your WebSocket server in the start
WebSocket message. Learn more on the WebSocket Messages page .
Use the parameter[x].name
and parameter[x].value
parameters to specify key-value pairs. For example, parameter1.name
is the key and parameter1.value
is the value of a key-value pair. You can provide up to 99 key-value pairs (parameter99.name
and parameter99.value
).
An example request is shown below.
_25 // Download the helper library from https://www.twilio.com/docs/node/install
_25 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_25 // Find your Account SID and Auth Token at twilio.com/console
_25 // and set the environment variables. See http://twil.io/secure
_25 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_25 const authToken = process.env.TWILIO_AUTH_TOKEN;
_25 const client = twilio(accountSid, authToken);
_25 async function createStream() {
_25 const stream = await client
_25 .calls("CAXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_25 name: "My Media Stream",
_25 "parameter1.name": "agent_name",
_25 "parameter1.value": "Mary",
_25 "parameter2.name": "Department",
_25 "parameter2.value": "sales",
_25 url: "wss://example.com/a-websocket-server",
_25 console.log(stream.sid);
_10 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "call_sid": "CAXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_10 "sid": "MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "name": "My Media Stream",
_10 "status": "in-progress",
_10 "date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
_10 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
Encoding type: application/x-www-form-urlencoded
Property name Type Required Description Child properties
Status enum<string> required The status of the Stream you wish to stop. Only possible value is stopped
.
Select from available examples
An example request is shown below.
_19 // Download the helper library from https://www.twilio.com/docs/node/install
_19 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19 // Find your Account SID and Auth Token at twilio.com/console
_19 // and set the environment variables. See http://twil.io/secure
_19 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19 const authToken = process.env.TWILIO_AUTH_TOKEN;
_19 const client = twilio(accountSid, authToken);
_19 async function updateStream() {
_19 const stream = await client
_19 .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19 .update({ status: "stopped" });
_19 console.log(stream.sid);
_10 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
_10 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
You can also use the Stream name
(if provided when creating the Stream) to stop the Stream. The example below shows how to stop a Stream with a name
of myStream
.
_19 // Download the helper library from https://www.twilio.com/docs/node/install
_19 const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19 // Find your Account SID and Auth Token at twilio.com/console
_19 // and set the environment variables. See http://twil.io/secure
_19 const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19 const authToken = process.env.TWILIO_AUTH_TOKEN;
_19 const client = twilio(accountSid, authToken);
_19 async function updateStream() {
_19 const stream = await client
_19 .calls("CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19 .update({ status: "stopped" });
_19 console.log(stream.sid);
_10 "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "call_sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_10 "date_updated": "Thu, 30 Jul 2015 20:00:00 +0000",
_10 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams/MZaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"