Class: OpenTok::Connections

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

Overview

A class for working with OpenTok connections.

Instance Method Summary collapse

Instance Method Details

#forceDisconnect(session_id, connection_id) ⇒ Object

Force a client to disconnect from an OpenTok session.

A client must be actively connected to the OpenTok session for you to disconnect it.

Parameters:

  • session_id (String)

    The session ID of the OpenTok session.

  • connection_id (String)

    The connection ID of the client in the session.

Raises:

  • (ArgumentError)

    The connection_id or session_id is invalid.

  • (OpenTokAuthenticationError)

    You are not authorized to disconnect the connection. Check your authentication credentials.

  • (OpenTokConnectionError)

    The client specified by the connection_id property is not connected to the session.



41
42
43
44
45
46
# File 'lib/opentok/connections.rb', line 41

def forceDisconnect(session_id, connection_id)
  raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
  raise ArgumentError, "connection_id not provided" if connection_id.to_s.empty?
  response = @client.forceDisconnect(session_id, connection_id)
  (200..300).include? response.code
end

#list(session_id, options = {}) ⇒ ConnectionList

Returns a ConnectionList, which is an array of connections that are active in a session, for your API key.

Parameters:

  • session_id (String)

    The session ID of the OpenTok session.

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

    A hash with keys defining which range of connections to retrieve.

Options Hash (options):

  • :offset (integer)

    Optional. The index offset of the first connection. If you do not specify an offset, 0 is used.

  • :count (integer)

    Optional. The number of connections to be returned. The maximum number of connections returned is 1000. If you do not specify a count, 50 is used.

Returns:

  • (ConnectionList)

    A ConnectionList object, which is an array of Connection objects.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
# File 'lib/opentok/connections.rb', line 23

def list(session_id, options = {})
  raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
  raise ArgumentError, "count must be between 1 and 1000" if options[:count] && (options[:count] < 1 || options[:count] > 1000)
  connections_list_json = @client.list_connections(session_id, options[:offset], options[:count])
  ConnectionList.new self, connections_list_json
end