Class: Vonage::Video::WebSocket

Inherits:
Namespace
  • Object
show all
Defined in:
lib/vonage/video/web_socket.rb

Instance Method Summary collapse

Instance Method Details

#connect(session_id:, token:, websocket:) ⇒ Response

Start an audio connector websocket connection

Examples:

response = client.video.web_socket.connect(
 session_id: "12312312-3811-4726-b508-e41a0f96c68f",
 token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJp...",
 websocket: {
    uri: 'wss://example.com/ws-endpoint',
    streams: ["8b732909-0a06-46a2-8ea8-074e64d43422"],
    headers: { property1: 'foo', property2: 'bar' },
    audio_rate: 16000
  }
)

Parameters:

  • :token (required, String)

    A valid Vonage Video token for the Audio Connector connection to the Vonage Video Session.

    • You can add additional data to the JWT to identify that the connection is the Audio Connector endpoint or for any other identifying data.

  • websocket (Hash)

    a customizable set of options

Options Hash (websocket:):

  • :uri (required, String)

    A publicly reachable WebSocket URI to be used for the destination of the audio stream

  • :streams (optional, String)

    An array of stream IDs for the Vonage Video streams you want to include in the WebSocket audio.

    • If you omit this property, all streams in the session will be included.

  • :headers (optional, Hash)

    An object of key-value pairs of headers to be sent to your WebSocket server with each message, with a maximum length of 512 bytes.

  • :audio_rate (optional, Integer)

    A number representing the audio sampling rate in Hz

    • Must be one of: 8000, 16000

Returns:

Raises:

  • (ArgumentError)

See Also:

  • Add document link here


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vonage/video/web_socket.rb', line 46

def connect(session_id:, token:, websocket:)
  raise ArgumentError, 'websocket must be a Hash' unless websocket.is_a?(Hash)
  raise ArgumentError, 'websocket must contain a uri' unless websocket.key?(:uri)
  
  request(
    '/v2/project/' + @config.application_id + '/connect',
    params: {
      sessionId: session_id,
      token: token,
      websocket: camelcase(websocket)
    },
    type: Post
  )
end