Skip to content
Last updated

connectStream

Important!

This feature is in closed beta - Please, contact Sinch sales for more details.

Determines how to route a call to a Stream/websocket server.

Available to use in a response to an Incoming Call Event callback.

Use cases

  • Connect inbound calls via one of the standard voice channels (PSTN, SIP or IN-App) to the new Stream channel
    • Reply ICE with connectStream() action.
  • Connect outbound calls via one of the standard voice channels into a conference room, and add a stream channel into the same conference, to combine 2 or more outbound calls with a stream outbound call.
    • Initiate a conferenceCallout to connect a standard voice channel (PSTN, SIP or In-App) into a conference room
    • Initiate a customCallout to connect a stream outbound call leg.

ConnectStream Action example code


{
  "action": {
    "name": "connectStream",
    "destination": {
      "type": "Websocket",
      "endpoint": "wss://yourcompany.com/websocket-server"
    },
    "streamingOptions": {
      "version": 1,
      "sampleRate": 44100
    },
    "maxDuration": 3000,
    "callHeaders": [
      {
        "key": "foo",
        "value": "bar"
      },
      {
        "key": "baz",
        "value": "qux"
      }
    ]
  }
}

Schema

namestringrequired

The name property. Must have the value connectStream.

Default "connectStream"
ValueDescription
connectStream

The connectStream action.

destinationobject(destinationWebSocket)required

Specifies where to route the Stream call.

destination.​typestringrequired

This attribute defines the streaming protocol - currently only Websocket is supported.

ValueDescription
Websocket

Use websocket stream protocol

Example: "Websocket"
destination.​endpointstringrequired

The Stream/Websocket server address.

Example: "wss://yourcompany.com/websocket-server"
streamingOptionsobject

Optional parameters for the WebSocket stream.

maxDurationinteger

The max duration of the call in seconds (max 14400 seconds). If the call is still connected at that time, it will be automatically disconnected.

Example: 3600
callHeadersArray of objects(callHeader)

These custom parameters (headers/messages) are sent to your WebSocket server in the initial message when the ConnectStream is established.

Note:

After the server response is received Sinch will start to send binary messages and expects to receive binary messages back, encoded with the same CODEC received.

Voice API Websocket connection flow

Sinch PlatformCustomer Websocket ServerAudio exchangeMessage exchangeClear buffer (VAD / barge-in)Send to keep channel open. ie: every 30 secsWS Connection request1WS Accepted2WS text message (command:connect)3WS text message (command:answer)4WS binary message : audio5WS binary message : audio6WS text message (command:clear)7WS text message (command:heartbeat)8Sinch PlatformCustomer Websocket Server

The websocket connection request does not contain any headers. The client is expected to either accept the connection (200 OK) or decline (non-successful HTTP response). If declined, the call is hung up.

If the connection is accepted, the server immediately sends a connect command message, containing all the information.

The client is expected to send a command message back to indicate whether the call should be answered or hung up. If answered, the audio streams start.

This flow introduces an extra message with a payload that might be considered to be cleaner. Compared to the previous flow, the customer header names are preserved (not prepended with X-).

The websocket close message, sent from either side, indicates a hangup. This message can contain code and reason.

Connect message:

{
    "command": "connect",
    "CallId": "...",
    "ApplicationId": "...",
    "Headers": {
        "Header1": "Value1",
        "ApplicationId": "dsfkjhgdfkjghsdfkjg"
    }
}

Customer message:

{
    "command": "answer"
}
-or-
{
    "command": "busy"
}
-or-
{
    "command": "reject"
}
Note:

Info about Close message and how audio is streamed if the Close message is sent.

Sinch PlatformCustomer Websocket ServerStream endedalt[Decline]Contains callHeaders, callId, AppKey, etc.Stream endedStream endedalt[Send BUSY signal][Reject the call]Audio exchangeMessage exchangeClear buffer (VAD / barge-in)Send to keep channel open. If no audio is sent on the channel ie: every 30 secsEnding the callStream endedStream endedalt[Customer ends call][Sinch ends call]WS Connection requestWS Accepted (200 ok)WS Respponse (Any other code)WS text message (command:connect)WS text message (command:answer)WS text message (command:busy)WS text message (command:reject)WS binary message : audioWS binary message : audioWS text message (command:clear)WS text message (command:heartbeat)Websocket close()Websocket close()Sinch PlatformCustomer Websocket Server