opentok 3.0.3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +249 -14
  3. data/lib/opentok/archive.rb +45 -4
  4. data/lib/opentok/archives.rb +62 -5
  5. data/lib/opentok/broadcast.rb +118 -0
  6. data/lib/opentok/broadcasts.rb +149 -0
  7. data/lib/opentok/client.rb +206 -3
  8. data/lib/opentok/connections.rb +28 -0
  9. data/lib/opentok/exceptions.rb +6 -0
  10. data/lib/opentok/opentok.rb +40 -8
  11. data/lib/opentok/session.rb +5 -0
  12. data/lib/opentok/signals.rb +47 -0
  13. data/lib/opentok/sip.rb +35 -0
  14. data/lib/opentok/stream.rb +46 -0
  15. data/lib/opentok/stream_list.rb +18 -0
  16. data/lib/opentok/streams.rb +79 -0
  17. data/lib/opentok/version.rb +1 -1
  18. data/spec/cassettes/OpenTok_Archives/calls_layout_on_archive_object.yml +45 -0
  19. data/spec/cassettes/OpenTok_Archives/changes_the_layout_of_an_archive.yml +36 -0
  20. data/spec/cassettes/OpenTok_Archives/should_create_hd_archives.yml +52 -0
  21. data/spec/cassettes/OpenTok_Broadcasts/calls_layout_on_broadcast_object.yml +55 -0
  22. data/spec/cassettes/OpenTok_Broadcasts/changes_the_layout_of_a_broadcast.yml +36 -0
  23. data/spec/cassettes/OpenTok_Broadcasts/fetches_a_hls_broadcast_url.yml +50 -0
  24. data/spec/cassettes/OpenTok_Broadcasts/finds_a_broadcast.yml +55 -0
  25. data/spec/cassettes/OpenTok_Broadcasts/starts_a_rtmp_broadcast.yml +59 -0
  26. data/spec/cassettes/OpenTok_Broadcasts/stops_a_broadcast.yml +45 -0
  27. data/spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml +36 -0
  28. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_a_connection.yml +37 -0
  29. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_all_connections.yml +37 -0
  30. data/spec/cassettes/OpenTok_Streams/get_all_streams_information.yml +53 -0
  31. data/spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml +42 -0
  32. data/spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml +36 -0
  33. data/spec/opentok/archives_spec.rb +73 -0
  34. data/spec/opentok/broadcasts_spec.rb +171 -0
  35. data/spec/opentok/connection_spec.rb +38 -0
  36. data/spec/opentok/signal_spec.rb +50 -0
  37. data/spec/opentok/streams_spec.rb +75 -0
  38. metadata +48 -3
@@ -0,0 +1,28 @@
1
+ module OpenTok
2
+ # A class for working with OpenTok connections.
3
+ class Connections
4
+ # @private
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # Force a client to disconnect from an OpenTok session.
10
+ #
11
+ # A client must be actively connected to the OpenTok session for you to disconnect it.
12
+ #
13
+ # @param [String] session_id The session ID of the OpenTok session.
14
+ # @param [String] connection_id The connection ID of the client in the session.
15
+ #
16
+ # @raise [ArgumentError] The connection_id or session_id is invalid.
17
+ # @raise [OpenTokAuthenticationError] You are not authorized to disconnect the connection. Check your authentication credentials.
18
+ # @raise [OpenTokConnectionError] The client specified by the connection_id property is not connected to the session.
19
+ #
20
+ def forceDisconnect(session_id, connection_id )
21
+ raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
22
+ raise ArgumentError, "connection_id not provided" if connection_id.to_s.empty?
23
+ response = @client.forceDisconnect(session_id, connection_id)
24
+ (200..300).include? response.code
25
+ end
26
+
27
+ end
28
+ end
@@ -8,5 +8,11 @@ module OpenTok
8
8
  class OpenTokSipError < OpenTokError; end
9
9
  # Defines errors raised when you attempt an operation using an invalid OpenTok API key or secret.
10
10
  class OpenTokAuthenticationError < OpenTokError; end
11
+ # Defines errors raised when you attempt a force disconnect a client and it is not connected to the session.
12
+ class OpenTokConnectionError < OpenTokError; end
13
+ # Defines errors raised when you attempt set layout classes to a stream.
14
+ class OpenTokStreamLayoutError < OpenTokError; end
15
+ # Defines errors raised when you perform Broadcast operations.
16
+ class OpenTokBroadcastError < OpenTokError; end
11
17
 
12
18
  end
@@ -2,17 +2,24 @@ require "opentok/constants"
2
2
  require "opentok/session"
3
3
  require "opentok/client"
4
4
  require "opentok/token_generator"
5
+ require "opentok/connections"
5
6
  require "opentok/archives"
6
7
  require "opentok/sip"
8
+ require "opentok/streams"
9
+ require "opentok/signals"
10
+ require "opentok/broadcasts"
7
11
 
8
12
  require "resolv"
9
13
  require "set"
10
14
 
11
15
  module OpenTok
12
- # Contains methods for creating OpenTok sessions, generating tokens, and working with archives.
16
+ # Contains methods for creating OpenTok sessions and generating tokens. It also includes
17
+ # methods for returning object that let you work with archives, work with live streaming
18
+ # broadcasts, using SIP interconnect, sending signals to sessions, disconnecting clients from
19
+ # sessions, and setting the layout classes for streams.
13
20
  #
14
21
  # To create a new OpenTok object, call the OpenTok constructor with your OpenTok API key
15
- # and the API secret from the OpenTok dashboard (https://dashboard.tokbox.com). Do not
22
+ # and the API secret for your {https://tokbox.com/account OpenTok project}. Do not
16
23
  # publicly share your API secret. You will use it with the OpenTok constructor (only on your web
17
24
  # server) to create OpenTok sessions.
18
25
  #
@@ -20,7 +27,7 @@ module OpenTok
20
27
  # @attr_reader [String] api_key @private The OpenTok API key.
21
28
  #
22
29
  #
23
- # @!method generate_token(options)
30
+ # @!method generate_token(session_id, options)
24
31
  # Generates a token for a given session.
25
32
  #
26
33
  # @param [String] session_id The session ID of the session to be accessed by the client using
@@ -45,6 +52,11 @@ module OpenTok
45
52
  # end-user. For example, you can pass the user ID, name, or other data describing the
46
53
  # end-user. The length of the string is limited to 1000 characters. This data cannot be
47
54
  # updated once it is set.
55
+ # @option options [Array] :initial_layout_class_list
56
+ # An array of class names (strings) to be used as the initial layout classes for streams
57
+ # published by the client. Layout classes are used in customizing the layout of videos in
58
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/ live streaming broadcasts}
59
+ # and {https://tokbox.com/developer/guides/archiving/layout-control.html composed archives}.
48
60
  # @return [String] The token string.
49
61
  class OpenTok
50
62
 
@@ -62,8 +74,8 @@ module OpenTok
62
74
  ##
63
75
  # Create a new OpenTok object.
64
76
  #
65
- # @param [String] api_key Your OpenTok API key. See the OpenTok dashboard
66
- # (https://dashboard.tokbox.com).
77
+ # @param [String] api_key The OpenTok API key for your
78
+ # {https://tokbox.com/account OpenTok project}.
67
79
  # @param [String] api_secret Your OpenTok API key.
68
80
  # @option opts [Symbol] :api_url Do not set this parameter. It is for internal use by TokBox.
69
81
  # @option opts [Symbol] :ua_addendum Do not set this parameter. It is for internal use by TokBox.
@@ -89,8 +101,8 @@ module OpenTok
89
101
  # Check the error message for details.
90
102
  #
91
103
  # You can also create a session using the OpenTok REST API (see
92
- # http://www.tokbox.com/opentok/api/#session_id_production) or the OpenTok dashboard
93
- # (see https://dashboard.tokbox.com/projects).
104
+ # http://www.tokbox.com/opentok/api/#session_id_production) or at your
105
+ # {https://tokbox.com/account OpenTok account page}.
94
106
  #
95
107
  # @param [Hash] opts (Optional) This hash defines options for the session.
96
108
  #
@@ -173,12 +185,32 @@ module OpenTok
173
185
  @archives ||= Archives.new client
174
186
  end
175
187
 
188
+ # A Broadcasts object, which lets you work with OpenTok live streaming broadcasts.
189
+ def broadcasts
190
+ @broadcasts ||= Broadcasts.new client
191
+ end
192
+
193
+ # A Sip object, which lets you use the OpenTok SIP gateway.
176
194
  def sip
177
195
  @sip ||= Sip.new client
178
196
  end
179
197
 
180
- protected
198
+ # A Streams object, which lets you work with OpenTok live streaming broadcasts.
199
+ def streams
200
+ @streams ||= Streams.new client
201
+ end
181
202
 
203
+ # A Signals object, which lets you send signals to OpenTok sessions.
204
+ def signals
205
+ @signals ||= Signals.new client
206
+ end
207
+
208
+ # A Connections object, which lets disconnect clients from an OpenTok session.
209
+ def connections
210
+ @connections ||= Connections.new client
211
+ end
212
+
213
+ protected
182
214
  def client
183
215
  @client ||= Client.new api_key, api_secret, api_url, ua_addendum
184
216
  end
@@ -42,6 +42,11 @@ module OpenTok
42
42
  # end-user. For example, you can pass the user ID, name, or other data describing the
43
43
  # end-user. The length of the string is limited to 1000 characters. This data cannot be
44
44
  # updated once it is set.
45
+ # @option options [Array] :initial_layout_class_list
46
+ # An array of class names (strings) to be used as the initial layout classes for streams
47
+ # published by the client. Layout classes are used in customizing the layout of videos in
48
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/ live streaming broadcasts}
49
+ # and {https://tokbox.com/developer/guides/archiving/layout-control.html composed archives}.
45
50
  # @return [String] The token string.
46
51
  class Session
47
52
 
@@ -0,0 +1,47 @@
1
+ module OpenTok
2
+ # A class for working with OpenTok signals.
3
+ class Signals
4
+ # @private
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # Sends a signal to clients connected to an OpenTok session.
10
+ #
11
+ # You can send a signal to all valid connections in a session or to a specific connection of
12
+ # a session.
13
+ #
14
+ # For more information on signaling, see
15
+ # {https://tokbox.com/developer/rest/#send_signal}.
16
+ #
17
+ # @param [String] session_id The session ID of the OpenTok session.
18
+ #
19
+ # @param [String] connection_id
20
+ # When a connection_id is specified, only that connection recieves the signal.
21
+ # Otherwise, the signal is sent to all clients connected to the session.
22
+ #
23
+ # @option options [String] :type This is the type of the signal. You can use this
24
+ # field to group and filter signals. It is a property of the Signal object received by
25
+ # the client(s).
26
+ #
27
+ # @option options [String] :data This is the data within the signal or the payload.
28
+ # Contains the main information to be sent in the signal. It is a property of the Signal object
29
+ # received by the client(s).
30
+ #
31
+ # @raise [ArgumentError]
32
+ # One of the signal properties — data, type, session_id, or connection_id — is invalid.
33
+ # @raise [OpenTokAuthenticationError]
34
+ # You are not authorized to send the signal. Check your authentication credentials.
35
+ # @raise [OpenTokError]
36
+ # The client specified by the connection_id property is not connected to the session.
37
+ # @raise [OpenTokError]
38
+ # The type string exceeds the maximum length (128 bytes), or the data string exceeds
39
+ # the maximum size (8 kB).
40
+ def send(session_id, connectionId = "", options = {})
41
+ raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
42
+ response = @client.signal(session_id, connectionId, options)
43
+ (200..300).include? response.code
44
+ end
45
+
46
+ end
47
+ end
@@ -1,7 +1,42 @@
1
1
  require "opentok/client"
2
2
 
3
+ # An object that lets you use the OpenTok SIP gateway.
3
4
  module OpenTok
4
5
  class Sip
6
+ # Dials a SIP gateway to input an audio-only stream into your OpenTok session.
7
+ # See the {https://tokbox.com/developer/guides/sip/ OpenTok SIP developer guide}.
8
+ #
9
+ # @example
10
+ # opts = { "from" => "14155550101@example.com",
11
+ # "auth" => { "username" => sip_username,
12
+ # "password" => sip_password },
13
+ # "headers" => { "X-KEY1" => "value1",
14
+ # "X-KEY1" => "value2" },
15
+ # "secure" => "true"
16
+ # }
17
+ # response = opentok.sip.dial(session_id, token, "sip:+15128675309@acme.pstn.example.com;transport=tls", opts)
18
+ # @param [String] session_id The session ID corresponding to the session to which
19
+ # the SIP gateway will connect.
20
+ # @param [String] token The token for the session ID with which the SIP user
21
+ # will use to connect.
22
+ # @param [String] sip_uri The SIP URI the OpenTok SIP gateway will dial.
23
+ # @param [Hash] opts A hash defining options for the SIP call. For example:
24
+ # @option opts [String] :from The number or string that will be sent to the final
25
+ # SIP number as the caller. It must be a string in the form of "from@example.com",
26
+ # where from can be a string or a number. If from is set to a number
27
+ # (for example, "14155550101@example.com"), it will show up as the incoming
28
+ # number on PSTN phones. If from is undefined or set to a string (for example,
29
+ # "joe@example.com"), +00000000 will show up as the incoming number on
30
+ # PSTN phones.
31
+ # @option opts [Hash] :headers This hash defines custom headers to be added
32
+ # to the SIP ​INVITE​ request initiated from OpenTok to the your SIP platform.
33
+ # Each of the custom headers must start with the ​"X-"​ prefix, or the call
34
+ # will result in a Bad Request (400) response.
35
+ # @option opts [Hash] :auth This object contains the username and password
36
+ # to be used in the the SIP INVITE​ request for HTTP digest authentication,
37
+ # if it is required by your SIP platform.
38
+ # @option opts [true, false] :secure Wether the media must be transmitted
39
+ # encrypted (​true​) or not (​false​, the default).
5
40
  def dial(session_id, token, sip_uri, opts)
6
41
  response = @client.dial(session_id, token, sip_uri, opts)
7
42
  end
@@ -0,0 +1,46 @@
1
+ require "active_support/inflector"
2
+
3
+ module OpenTok
4
+ # Represents information about a stream in an OpenTok session.
5
+ #
6
+ # @attr [string] id
7
+ # The stream ID.
8
+ #
9
+ # @attr [string] name
10
+ # The name of the stream.
11
+
12
+ # @attr [string] videoType
13
+ # The videoType property is either "camera" or "screen".
14
+ #
15
+ # @attr [array] layoutClassList
16
+ # An array of the layout classes for the stream.
17
+ class Stream
18
+
19
+ # @private
20
+ def initialize(json)
21
+ # TODO: validate json fits schema
22
+ @json = json
23
+ end
24
+
25
+ # A JSON-encoded string representation of the stream.
26
+ def to_json
27
+ @json.to_json
28
+ end
29
+
30
+
31
+ # @private ignore
32
+ def method_missing(method, *args, &block)
33
+ camelized_method = method.to_s.camelize(:lower)
34
+ if @json.has_key? camelized_method and args.empty?
35
+ # TODO: convert create_time method call to a Time object
36
+ if camelized_method == 'outputMode'
37
+ @json[camelized_method].to_sym
38
+ else
39
+ @json[camelized_method]
40
+ end
41
+ else
42
+ super method, *args, &block
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ require "opentok/stream"
2
+
3
+
4
+ module OpenTok
5
+ # A class for accessing a list of Stream objects.
6
+ class StreamList < Array
7
+
8
+ # The total number streams.
9
+ attr_reader :total
10
+
11
+ # @private
12
+ def initialize(json)
13
+ @total = json['count']
14
+ super json['items'].map { |item| Stream.new item }
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,79 @@
1
+ require 'opentok/client'
2
+ require 'opentok/stream'
3
+ require 'opentok/stream_list'
4
+
5
+ module OpenTok
6
+ # A class for working with OpenTok streams. It includes methods for getting info
7
+ # about OpenTok streams and for setting layout classes for streams.
8
+ class Streams
9
+ # @private
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ # Use this method to get information on an OpenTok stream.
15
+ #
16
+ # For example, you can call this method to get information about layout classes used by an OpenTok stream.
17
+ # The layout classes define how the stream is displayed in the layout of a broadcast stream.
18
+ # For more information, see {https://tokbox.com/developer/guides/broadcast/live-streaming/#assign-layout-classes-to-streams Assigning layout classes to streams in live streaming broadcasts}
19
+ # and {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing the video layout for composed archives}.
20
+ #
21
+ # @param [String] session_id The session ID of the OpenTok session.
22
+ # @param [String] stream_id The stream ID within the session.
23
+ # @return [Stream] The Stream object.
24
+ # @raise [ArgumentError] stream_id or session_id is invalid.
25
+ # @raise [OpenTokAuthenticationError] You are not authorized to fetch the stream information. Check your authentication credentials.
26
+ # @raise [OpenTokError] An OpenTok server error.
27
+ #
28
+ def find(session_id, stream_id)
29
+ raise ArgumentError, 'session_id not provided' if session_id.to_s.empty?
30
+ raise ArgumentError, 'stream_id not provided' if session_id.to_s.empty?
31
+ stream_json = @client.info_stream(session_id, stream_id)
32
+ Stream.new stream_json
33
+ end
34
+
35
+ # Use this method to get information on all OpenTok streams in a session.
36
+ #
37
+ # For example, you can call this method to get information about layout classes used by OpenTok streams.
38
+ # The layout classes define how the stream is displayed in the layout of a live streaming
39
+ # broadcast or a composed archive. For more information, see
40
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#assign-layout-classes-to-streams Assigning layout classes to streams in live streaming broadcasts}
41
+ # and {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing the video layout for composed archives}.
42
+ #
43
+ # @param [String] session_id The session ID of the OpenTok session.
44
+ # @return [StreamList] The StreamList of Stream objects.
45
+ # @raise [ArgumentError] The stream_id or session_id is invalid.
46
+ # @raise [OpenTokAuthenticationError] You are not authorized to fetch the stream information. Check your authentication credentials.
47
+ # @raise [OpenTokError] An OpenTok server error.
48
+ #
49
+ def all(session_id)
50
+ raise ArgumentError, 'session_id not provided' if session_id.to_s.empty?
51
+ response_json = @client.info_stream(session_id, '')
52
+ StreamList.new response_json
53
+ end
54
+
55
+ # Use this method to set the layout of a composed (archive or broadcast) OpenTok stream.
56
+ #
57
+ # For example, you can call this method to set the layout classes of an OpenTok stream.
58
+ # The layout classes define how the stream is displayed in the layout of a live streaming
59
+ # broadcast or a composed archive. For more information, see
60
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#assign-layout-classes-to-streams Assigning layout classes to streams in live streaming broadcasts}
61
+ # and {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing the video layout for composed archives}.
62
+ #
63
+ # @param [String] session_id The session ID of the OpenTok session.
64
+ # @param [Hash] opts A hash with one key <code>items</code> and value as array of objects having <code>stream_id</code> and <code>layoutClassList</code> properties.
65
+ # For more information, see Layout{https://tokbox.com/developer/rest/#change-stream-layout-classes-composed}
66
+ # @raise [ArgumentError] The session_id is invalid.
67
+ # @raise [OpenTokAuthenticationError] You are not authorized to fetch the stream information. Check your authentication credentials.
68
+ # @raise [OpenTokStreamLayoutError] The layout operation could not be performed due to incorrect layout values.
69
+ # @raise [OpenTokError] An OpenTok server error.
70
+ #
71
+ def layout(session_id, opts)
72
+ raise ArgumentError, 'session_id not provided' if session_id.to_s.empty?
73
+ raise ArgumentError, 'opts is empty' if opts.empty?
74
+ response = @client.layout_streams(session_id, opts)
75
+ (200..300).include? response.code
76
+ end
77
+
78
+ end
79
+ end
@@ -1,4 +1,4 @@
1
1
  module OpenTok
2
2
  # @private
3
- VERSION = '3.0.3'
3
+ VERSION = '3.1.0'
4
4
  end
@@ -0,0 +1,45 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.opentok.com/v2/project/123456/archive/f6e7ee58-d6cf-4a59-896b-6d56b158ec71
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzdCI6InByb2plY3QifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.Oh_JHhtEUKK1pPV4s6neXJj_RXI8EcEpJRRpG_2c9U0
14
+ response:
15
+ status:
16
+ code: 200
17
+ message: OK
18
+ headers:
19
+ Server:
20
+ - nginx
21
+ Date:
22
+ - Wed, 26 Sep 2018 18:07:55 GMT
23
+ Content-Type:
24
+ - application/json
25
+ Connection:
26
+ - keep-alive
27
+ body:
28
+ encoding: UTF-8
29
+ string: |-
30
+ {
31
+ "createdAt" : 1395187836000,
32
+ "duration" : 62,
33
+ "id" : "f6e7ee58-d6cf-4a59-896b-6d56b158ec71",
34
+ "name" : "",
35
+ "partnerId" : 123456,
36
+ "reason" : "",
37
+ "sessionId" : "SESSIONID",
38
+ "size" : 8347554,
39
+ "status" : "available",
40
+ "url" : "http://tokbox.com.archive2.s3.amazonaws.com/123456%2Ff6e7ee58-d6cf-4a59-896b-6d56b158ec71%2Farchive.mp4?Expires=1395194362&AWSAccessKeyId=AKIAI6LQCPIXYVWCQV6Q&Signature=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
41
+ "notarealproperty" : "not a real value"
42
+ }
43
+ http_version:
44
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
45
+ recorded_with: VCR 2.8.0