Class: OpenTok::WebSocket

Inherits:
Object
  • Object
show all
Defined in:
lib/opentok/websocket.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ WebSocket

Returns a new instance of WebSocket.



33
34
35
# File 'lib/opentok/websocket.rb', line 33

def initialize(client)
  @client = client
end

Instance Method Details

#connect(session_id, token, websocket_uri, opts = {}) ⇒ Object

Starts an Audio Connector WebSocket connection to send audio from a Vonage Video API session to a WebSocket URI. See the / OpenTok Audio Connector developer guide.

Examples:

opts = {
  "streams" => ["STREAMID1", "STREAMID2"],
  "headers" => {
    "key1" => "val1",
    "key2" => "val2"
  }
}
response = opentok.websocket.connect(SESSIONID, TOKEN, "ws://service.com/wsendpoint", opts)

Parameters:

  • session_id (String)

    (required) The OpenTok session ID that includes the OpenTok streams you want to include in the WebSocket stream.

  • token (String)

    (required) The OpenTok token to be used for the Audio Connector connection to the. OpenTok session.

  • websocket_uri (String)

    (required) A publicly reachable WebSocket URI to be used for the destination of the audio stream (such as “wss://service.com/ws-endpoint”).

  • opts (Hash) (defaults to: {})

    (optional) A hash defining options for the Audio Connector WebSocket connection. For example:

Options Hash (opts):

  • :streams (Array) — default: optional

    An array of stream IDs for the OpenTok streams you want to include in the WebSocket stream. If you omit this property, all streams in the session will be included.

  • :headers (Hash) — default: optional

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



29
30
31
# File 'lib/opentok/websocket.rb', line 29

def connect(session_id, token, websocket_uri, opts  = {})
  response = @client.connect_websocket(session_id, token, websocket_uri, opts)
end