opentok 3.0.3 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/metrics.yml +17 -0
  3. data/.travis.yml +3 -1
  4. data/CODE_OF_CONDUCT.md +128 -0
  5. data/README.md +312 -28
  6. data/lib/opentok/archive.rb +45 -4
  7. data/lib/opentok/archives.rb +73 -5
  8. data/lib/opentok/broadcast.rb +118 -0
  9. data/lib/opentok/broadcasts.rb +149 -0
  10. data/lib/opentok/client.rb +212 -7
  11. data/lib/opentok/connections.rb +28 -0
  12. data/lib/opentok/constants.rb +1 -1
  13. data/lib/opentok/exceptions.rb +6 -0
  14. data/lib/opentok/opentok.rb +44 -10
  15. data/lib/opentok/session.rb +5 -0
  16. data/lib/opentok/signals.rb +47 -0
  17. data/lib/opentok/sip.rb +33 -0
  18. data/lib/opentok/stream.rb +46 -0
  19. data/lib/opentok/stream_list.rb +18 -0
  20. data/lib/opentok/streams.rb +79 -0
  21. data/lib/opentok/version.rb +1 -1
  22. data/opentok.gemspec +9 -8
  23. data/sample/Broadcast/Gemfile +4 -0
  24. data/sample/Broadcast/README.md +201 -0
  25. data/sample/Broadcast/broadcast_sample.rb +97 -0
  26. data/sample/Broadcast/public/css/sample.css +64 -0
  27. data/sample/Broadcast/public/js/host.js +185 -0
  28. data/sample/Broadcast/public/js/participant.js +85 -0
  29. data/sample/Broadcast/views/host.erb +82 -0
  30. data/sample/Broadcast/views/index.erb +32 -0
  31. data/sample/Broadcast/views/layout.erb +29 -0
  32. data/sample/Broadcast/views/participant.erb +27 -0
  33. data/sample/HelloWorld/public/js/helloworld.js +4 -10
  34. data/sample/HelloWorld/views/index.erb +1 -3
  35. data/spec/cassettes/OpenTok_Archives/calls_layout_on_archive_object.yml +47 -0
  36. data/spec/cassettes/OpenTok_Archives/changes_the_layout_of_an_archive.yml +38 -0
  37. data/spec/cassettes/OpenTok_Archives/http_client_errors/.yml +34 -0
  38. data/spec/cassettes/OpenTok_Archives/should_create_archives.yml +3 -1
  39. data/spec/cassettes/OpenTok_Archives/should_create_audio_only_archives.yml +3 -1
  40. data/spec/cassettes/OpenTok_Archives/should_create_custom_layout_archives.yml +50 -0
  41. data/spec/cassettes/OpenTok_Archives/should_create_hd_archives.yml +54 -0
  42. data/spec/cassettes/OpenTok_Archives/should_create_individual_archives.yml +3 -1
  43. data/spec/cassettes/OpenTok_Archives/should_create_named_archives.yml +3 -1
  44. data/spec/cassettes/OpenTok_Archives/should_delete_an_archive_by_id.yml +3 -1
  45. data/spec/cassettes/OpenTok_Archives/should_find_archives_by_id.yml +3 -1
  46. data/spec/cassettes/OpenTok_Archives/should_find_archives_with_unknown_properties.yml +3 -1
  47. data/spec/cassettes/OpenTok_Archives/should_find_expired_archives.yml +3 -1
  48. data/spec/cassettes/OpenTok_Archives/should_find_paused_archives_by_id.yml +3 -1
  49. data/spec/cassettes/OpenTok_Archives/should_stop_archives.yml +3 -1
  50. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_all_archives.yml +3 -1
  51. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_archives_with_an_offset.yml +3 -1
  52. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_count_number_of_archives.yml +3 -1
  53. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_part_of_the_archives_when_using_offset_and_count.yml +3 -1
  54. data/spec/cassettes/OpenTok_Archives/when_many_archives_are_created/should_return_session_archives.yml +3 -1
  55. data/spec/cassettes/OpenTok_Broadcasts/calls_layout_on_broadcast_object.yml +57 -0
  56. data/spec/cassettes/OpenTok_Broadcasts/changes_the_layout_of_a_broadcast.yml +38 -0
  57. data/spec/cassettes/OpenTok_Broadcasts/fetches_a_hls_broadcast_url.yml +52 -0
  58. data/spec/cassettes/OpenTok_Broadcasts/finds_a_broadcast.yml +57 -0
  59. data/spec/cassettes/OpenTok_Broadcasts/starts_a_rtmp_broadcast.yml +61 -0
  60. data/spec/cassettes/OpenTok_Broadcasts/stops_a_broadcast.yml +47 -0
  61. data/spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml +38 -0
  62. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_always_archived_sessions.yml +3 -1
  63. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_default_sessions.yml +3 -1
  64. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions.yml +3 -1
  65. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_for_invalid_media_modes.yml +3 -1
  66. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_relayed_media_sessions_with_a_location_hint.yml +3 -1
  67. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions.yml +3 -1
  68. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_routed_media_sessions_with_a_location_hint.yml +3 -1
  69. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/_create_session/creates_sessions_with_a_location_hint.yml +3 -1
  70. data/spec/cassettes/OpenTok_OpenTok/when_initialized_properly/with_an_addendum_to_the_user_agent_string/should_append_the_addendum_to_the_user_agent_header.yml +3 -1
  71. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_a_connection.yml +39 -0
  72. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_all_connections.yml +39 -0
  73. data/spec/cassettes/OpenTok_Sip/receives_a_valid_response.yml +3 -1
  74. data/spec/cassettes/OpenTok_Streams/get_all_streams_information.yml +55 -0
  75. data/spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml +44 -0
  76. data/spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml +38 -0
  77. data/spec/opentok/archives_spec.rb +84 -1
  78. data/spec/opentok/broadcasts_spec.rb +171 -0
  79. data/spec/opentok/client_spec.rb +51 -0
  80. data/spec/opentok/connection_spec.rb +38 -0
  81. data/spec/opentok/opentok_spec.rb +21 -0
  82. data/spec/opentok/signal_spec.rb +50 -0
  83. data/spec/opentok/streams_spec.rb +75 -0
  84. data/spec/spec_helper.rb +2 -0
  85. metadata +84 -22
@@ -54,8 +54,8 @@ module OpenTok
54
54
  # * "started" -- The archive started and is in the process of being recorded.
55
55
  # * "stopped" -- The archive stopped recording.
56
56
  # * "uploaded" -- The archive is available for download from the the upload target
57
- # Amazon S3 bucket or Windows Azure container you set at the OpenTok dashboard
58
- # (https://dashboard.tokbox.com).
57
+ # Amazon S3 bucket or Windows Azure container you set for your
58
+ # {https://tokbox.com/account OpenTok project}.
59
59
  #
60
60
  # @attr [string] url
61
61
  # The download URL of the available MP4 file. This is only set for an archive with the status set to
@@ -71,14 +71,14 @@ module OpenTok
71
71
  @json = json
72
72
  end
73
73
 
74
- # A JSON encoded string representation of the archive
74
+ # A JSON-encoded string representation of the archive.
75
75
  def to_json
76
76
  @json.to_json
77
77
  end
78
78
 
79
79
  # Stops an OpenTok archive that is being recorded.
80
80
  #
81
- # Archives automatically stop recording after 90 minutes or when all clients have disconnected
81
+ # Archives automatically stop recording after 120 minutes or when all clients have disconnected
82
82
  # from the session being archived.
83
83
  def stop
84
84
  # TODO: validate returned json fits schema
@@ -95,6 +95,47 @@ module OpenTok
95
95
  @json = @interface.delete_by_id @json['id']
96
96
  end
97
97
 
98
+ # Sets the layout type for a composed archive. For a description of layout types, see
99
+ # {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
100
+ # the video layout for composed archives}.
101
+ #
102
+ # @option options [String] :type
103
+ # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
104
+ # "horizontalPresentation", "focus", or "custom".
105
+ #
106
+ # @option options [String] :stylesheet
107
+ # The stylesheet for a custom layout. Set this parameter
108
+ # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
109
+ #
110
+ # @raise [ArgumentError] The archive_id or options parameter is empty. Or the "custom"
111
+ # type was specified without a stylesheet option. Or a stylesheet was passed in for a
112
+ # type other than custom. Or an invalid type was passed in.
113
+ #
114
+ # @raise [OpenTokAuthenticationError]
115
+ # Authentication failed.
116
+ #
117
+ # @raise [ArgumentError]
118
+ # The archive_id or options parameter is empty.
119
+ #
120
+ # @raise [ArgumentError]
121
+ # The "custom" type was specified without a stylesheet option.
122
+ #
123
+ # @raise [ArgumentError]
124
+ # A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
125
+ #
126
+ # @raise [ArgumentError]
127
+ # An invalid layout type was passed in.
128
+ #
129
+ # @raise [OpenTokError]
130
+ # OpenTok server error.
131
+ #
132
+ # @raise [OpenTokArchiveError]
133
+ # Setting the layout failed.
134
+ def layout(opts= {})
135
+ # TODO: validate returned json fits schema
136
+ @json = @interface.layout(@json['id'], opts)
137
+ end
138
+
98
139
  # @private ignore
99
140
  def method_missing(method, *args, &block)
100
141
  camelized_method = method.to_s.camelize(:lower)
@@ -24,8 +24,8 @@ module OpenTok
24
24
  # {https://tokbox.com/opentok/tutorials/archiving OpenTok archiving} programming guide.
25
25
  #
26
26
  # @param [String] session_id The session ID of the OpenTok session to archive.
27
- # @param [Hash] options A hash with the key 'name', 'has_audio', and 'has_video' (or
28
- # :name.
27
+ # @param [Hash] options A hash with the keys 'name', 'has_audio', 'has_video',
28
+ # and 'output_mode'.
29
29
  # @option options [String] :name This is the name of the archive. You can use this name
30
30
  # to identify the archive. It is a property of the Archive object, and it is a property
31
31
  # of archive-related events in the OpenTok client SDKs.
@@ -44,6 +44,21 @@ module OpenTok
44
44
  # (<code>:individual</code>). For more information on archiving and the archive file
45
45
  # formats, see the {https://tokbox.com/opentok/tutorials/archiving OpenTok archiving}
46
46
  # programming guide.
47
+ # @option options [String] :resolution The resolution of the archive, either "640x480" (SD, the
48
+ # default) or "1280x720" (HD). This property only applies to composed archives. If you set
49
+ # this property and set the outputMode property to "individual", the call the method
50
+ # results in an error.
51
+ # @option options [Hash] :layout Specify this to assign the initial layout type for
52
+ # the archive. This applies only to composed archives. This is a hash containing two keys:
53
+ # <code>:type</code> and <code>:stylesheet<code>. Valid values for <code>:type</code> are
54
+ # "bestFit" (best fit), "custom" (custom), "horizontalPresentation" (horizontal presentation),
55
+ # "pip" (picture-in-picture), and "verticalPresentation" (vertical presentation)).
56
+ # If you specify a "custom" layout type, set the <code>:stylesheet</code> key to the
57
+ # stylesheet (CSS). (For other layout types, do not set the <code>:stylesheet</code> key.)
58
+ # If you do not specify an initial layout type, the archive uses the best fit
59
+ # layout type. For more information, see
60
+ # {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
61
+ # the video layout for composed archives}.
47
62
  #
48
63
  # @return [Archive] The Archive object, which includes properties defining the archive,
49
64
  # including the archive ID.
@@ -58,9 +73,11 @@ module OpenTok
58
73
  # @raise [OpenTokArchiveError] The archive could not be started.
59
74
  def create(session_id, options = {})
60
75
  raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
76
+ raise ArgumentError,
77
+ "Resolution cannot be supplied for individual output mode" if options.key?(:resolution) and options[:output_mode] == :individual
61
78
 
62
79
  # normalize opts so all keys are symbols and only include valid_opts
63
- valid_opts = [ :name, :has_audio, :has_video, :output_mode ]
80
+ valid_opts = [ :name, :has_audio, :has_video, :output_mode, :resolution, :layout ]
64
81
  opts = options.inject({}) do |m,(k,v)|
65
82
  if valid_opts.include? k.to_sym
66
83
  m[k.to_sym] = v
@@ -97,7 +114,7 @@ module OpenTok
97
114
  # @option options [integer] :count Optional. The number of archives to be returned. The maximum
98
115
  # number of archives returned is 1000.
99
116
  # @option options [String] :session_id Optional. The session ID that archives belong to. This is
100
- # useful when listing multiple archives for an {https://tokbox.com/developer/guides/archiving/#automatic-archives automatically archived session}
117
+ # useful when listing multiple archives for an {https://tokbox.com/developer/guides/archiving/#automatic-archives automatically archived session}.
101
118
  #
102
119
  # @return [ArchiveList] An ArchiveList object, which is an array of Archive objects.
103
120
  def all(options = {})
@@ -108,7 +125,7 @@ module OpenTok
108
125
 
109
126
  # Stops an OpenTok archive that is being recorded.
110
127
  #
111
- # Archives automatically stop recording after 90 minutes or when all clients have disconnected
128
+ # Archives automatically stop recording after 120 minutes or when all clients have disconnected
112
129
  # from the session being archived.
113
130
  #
114
131
  # @param [String] archive_id The archive ID of the archive you want to stop recording.
@@ -146,5 +163,56 @@ module OpenTok
146
163
  (200..300).include? response.code
147
164
  end
148
165
 
166
+ # Sets the layout type for a composed archive. For a description of layout types, see
167
+ # {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
168
+ # the video layout for composed archives}.
169
+ #
170
+ # @param [String] archive_id
171
+ # The archive ID.
172
+ #
173
+ # @option options [String] :type
174
+ # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
175
+ # "horizontalPresentation", "focus", or "custom".
176
+ #
177
+ # @option options [String] :stylesheet
178
+ # The stylesheet for a custom layout. Set this parameter
179
+ # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
180
+ #
181
+ # @raise [ArgumentError]
182
+ # The archive_id or options parameter is empty. Or the "custom"
183
+ # type was specified without a stylesheet option. Or a stylesheet was passed in for a
184
+ # type other than custom. Or an invalid type was passed in.
185
+ #
186
+ # @raise [OpenTokAuthenticationError]
187
+ # Authentication failed.
188
+ #
189
+ # @raise [ArgumentError]
190
+ # The archive_id or options parameter is empty.
191
+ #
192
+ # @raise [ArgumentError]
193
+ # The "custom" type was specified without a stylesheet option.
194
+ #
195
+ # @raise [ArgumentError]
196
+ # A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
197
+ #
198
+ # @raise [ArgumentError]
199
+ # An invalid layout type was passed in.
200
+ #
201
+ # @raise [OpenTokError]
202
+ # OpenTok server error.
203
+ #
204
+ # @raise [OpenTokArchiveError]
205
+ # Setting the layout failed.
206
+ def layout(archive_id, options = {})
207
+ raise ArgumentError, "option parameter is empty" if options.empty?
208
+ raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty?
209
+ type = options[:type]
210
+ raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!options.key? :stylesheet)
211
+ valid_non_custom_type = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""].include? type
212
+ raise ArgumentError, "type is not valid or stylesheet not needed" if !valid_non_custom_type
213
+ raise ArgumentError, "type is not valid or stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
214
+ response = @client.layout_archive(archive_id, options)
215
+ (200..300).include? response.code
216
+ end
149
217
  end
150
218
  end
@@ -0,0 +1,118 @@
1
+ require "active_support/inflector"
2
+
3
+ module OpenTok
4
+ # Represents a live streaming broadcast of an OpenTok session.
5
+ # See {https://tokbox.com/developer/guides/broadcast/live-streaming/ Live streaming broadcasts}.
6
+ #
7
+ # @attr [string] id
8
+ # The broadcast ID.
9
+ #
10
+ # @attr [string] session_id
11
+ # The session ID of the OpenTok session associated with this broadcast.
12
+ #
13
+ # @attr [string] project_id
14
+ # The API key associated with the broadcast.
15
+ #
16
+ # @attr [int] created_at
17
+ # The time at which the broadcast was created, in milliseconds since the UNIX epoch.
18
+ #
19
+ # @attr [int] updated_at
20
+ # For this start method, this timestamp matches the createdAt timestamp.
21
+ #
22
+ # @attr [string] resolution
23
+ # The resolution of the broadcast: either "640x480" (SD, the default) or "1280x720" (HD). This property is optional.
24
+ #
25
+ # @attr [Hash] broadcastUrls is defined as follows:
26
+ # This object defines the types of broadcast streams you want to start (both HLS and RTMP).
27
+ # You can include HLS, RTMP, or both as broadcast streams. If you include RTMP streaming,
28
+ # you can specify up to five target RTMP streams (or just one).
29
+ # The (<code>:hls</code>) property is set to an empty [Hash] object. The HLS URL is returned in the response.
30
+ # The (<code>:rtmp</code>) property is set to an [Array] of Rtmp [Hash] properties.
31
+ # For each RTMP stream, specify (<code>:serverUrl</code>) for the RTMP server URL,
32
+ # (<code>:streamName</code>) such as the YouTube Live stream name or the Facebook stream key),
33
+ # and (optionally) (<code>:id</code>), a unique ID for the stream.
34
+ #
35
+ # @attr [string] status The status of the RTMP stream.
36
+ # * "connecting" -- The OpenTok platform is in the process of connecting to the remote RTMP server.
37
+ # This is the initial state, and it is the status if you start when there are no streams published in the session.
38
+ # It changes to "live" when there are streams (or it changes to one of the other states).
39
+ # * "live -- The OpenTok platform has successfully connected to the remote RTMP server, and the media is streaming.
40
+ # * "offline" -- The OpenTok platform could not connect to the remote RTMP server. This is due to an unreachable server or an error in the RTMP handshake. Causes include rejected RTMP connections, non-existing RTMP applications, rejected stream names, authentication errors, etc. Check that the server is online, and that you have provided the correct server URL and stream name.
41
+ # * "error" -- There is an error in the OpenTok platform.
42
+ class Broadcast
43
+
44
+ # @private
45
+ def initialize(interface, json)
46
+ @interface = interface
47
+ # TODO: validate json fits schema
48
+ @json = json
49
+ end
50
+
51
+ # A JSON-encoded string representation of the broadcast.
52
+ def to_json
53
+ @json.to_json
54
+ end
55
+
56
+ # Stops the OpenTok broadcast.
57
+ def stop
58
+ # TODO: validate returned json fits schema
59
+ @json = @interface.stop @json['id']
60
+ end
61
+
62
+ # Sets the layout of the OpenTok broadcast.
63
+ #
64
+ # You can dynamically change the layout type of a broadcast while it is being broadcast.
65
+ # For more information, see
66
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts Configuring video layout for OpenTok live streaming broadcasts}.
67
+ #
68
+ # @option options [String] :type
69
+ # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
70
+ # "horizontalPresentation", "focus", or "custom".
71
+ #
72
+ # @option options [String] :stylesheet
73
+ # The stylesheet for a custom layout. Set this parameter
74
+ # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
75
+ #
76
+ # @raise [OpenTokBroadcastError]
77
+ # The broadcast layout could not be updated.
78
+ #
79
+ # @raise [OpenTokAuthenticationError]
80
+ # Authentication failed. Invalid API key or secret.
81
+ #
82
+ # @raise [OpenTokError]
83
+ # OpenTok server error.
84
+ #
85
+ # @raise [ArgumentError]
86
+ # The broadcast_id or options parameter is empty.
87
+ #
88
+ # @raise [ArgumentError]
89
+ # The "custom" type was specified without a stylesheet option.
90
+ #
91
+ # @raise [ArgumentError]
92
+ # A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
93
+ #
94
+ # @raise [ArgumentError]
95
+ # An invalid layout type was passed in.
96
+ # Refer to {https://tokbox.com/developer/rest/#change_composed_archive_layout}
97
+
98
+ def layout(opts = {})
99
+ # TODO: validate returned json fits schema
100
+ @json = @interface.layout(@json['id'], opts)
101
+ end
102
+
103
+ # @private ignore
104
+ def method_missing(method, *args, &block)
105
+ camelized_method = method.to_s.camelize(:lower)
106
+ if @json.has_key? camelized_method and args.empty?
107
+ # TODO: convert create_time method call to a Time object
108
+ if camelized_method == 'outputMode'
109
+ @json[camelized_method].to_sym
110
+ else
111
+ @json[camelized_method]
112
+ end
113
+ else
114
+ super method, *args, &block
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,149 @@
1
+ require "opentok/client"
2
+ require "opentok/broadcast"
3
+
4
+
5
+ module OpenTok
6
+ # A class for working with OpenTok live streaming broadcasts.
7
+ # See {https://tokbox.com/developer/guides/broadcast/live-streaming/ Live streaming broadcasts}.
8
+ class Broadcasts
9
+
10
+ # @private
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ # Starts a live streaming broadcast of an OpenTok session.
16
+ #
17
+ # Clients must be actively connected to the OpenTok session for you to successfully start
18
+ # a broadcast.
19
+ #
20
+ # This broadcasts the session to an HLS (HTTP live streaming) or to RTMP streams.
21
+ #
22
+ # @param [String] session_id The session ID of the OpenTok session to broadcast.
23
+ #
24
+ # @param [Hash] options A hash defining options for the broadcast.
25
+ # @option options [Hash] :layout Specify this to assign the initial layout for the broadcast.
26
+ # Valid values for the layout (<code>:type</code>) property are "bestFit" (best fit), "custom" (custom),
27
+ # "horizontalPresentation" (horizontal presentation), "pip" (picture-in-picture), and
28
+ # "verticalPresentation" (vertical presentation)).
29
+ # If you specify a (<code>:custom</code>) layout type, set the (<code>:stylesheet</code>) property of the layout object
30
+ # to the stylesheet. (For other layout types, do not set a stylesheet property.)
31
+ # If you do not specify an initial layout type, the broadcast stream uses the Best Fit layout type.
32
+ #
33
+ # @option options [int] maxDuration
34
+ # The maximum duration for the broadcast, in seconds. The broadcast will automatically stop when
35
+ # the maximum duration is reached. You can set the maximum duration to a value from 60 (60 seconds) to 36000 (10 hours).
36
+ # The default maximum duration is 2 hours (7200 seconds).
37
+ #
38
+ # @option options [Hash] outputs
39
+ # This object defines the types of broadcast streams you want to start (both HLS and RTMP).
40
+ # You can include HLS, RTMP, or both as broadcast streams. If you include RTMP streaming,
41
+ # you can specify up to five target RTMP streams (or just one).
42
+ # The (<code>:hls</code>) property is set to an empty [Hash] object. The HLS URL is returned in the response.
43
+ # The (<code>:rtmp</code>) property is set to an [Array] of Rtmp [Hash] properties.
44
+ # For each RTMP , specify (<code>:serverUrl</code>) for the RTMP server URL,
45
+ # (<code>:streamName</code>) such as the YouTube Live stream name or the Facebook stream key),
46
+ # and (optionally) (<code>:id</code>), a unique ID for the stream.
47
+ #
48
+ # @option options [string] resolution
49
+ # The resolution of the broadcast: either "640x480" (SD, the default) or "1280x720" (HD).
50
+ #
51
+ # @return [Broadcast] The broadcast object, which includes properties defining the broadcast,
52
+ # including the broadcast ID.
53
+ #
54
+ # @raise [OpenTokBroadcastError] The broadcast could not be started. The request was invalid or broadcast already started
55
+ # @raise [OpenTokAuthenticationError] Authentication failed while starting an archive.
56
+ # Invalid API key.
57
+ # @raise [OpenTokError] OpenTok server error.
58
+ def create(session_id, options = {})
59
+ raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
60
+ raise ArgumentError, "options cannot be empty" if options.empty?
61
+ broadcast_json = @client.start_broadcast(session_id, options)
62
+ Broadcast.new self, broadcast_json
63
+ end
64
+
65
+ # Gets a Broadcast object for the given broadcast ID.
66
+ #
67
+ # @param [String] broadcast_id The broadcast ID.
68
+ #
69
+ # @return [Broadcast] The broadcast object, which includes properties defining the broadcast.
70
+ #
71
+ # @raise [OpenTokBroadcastError] No matching broadcast found.
72
+ # @raise [OpenTokAuthenticationError] Authentication failed.
73
+ # Invalid API key.
74
+ # @raise [OpenTokError] OpenTok server error.
75
+ def find(broadcast_id)
76
+ raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
77
+ broadcast_json = @client.get_broadcast(broadcast_id.to_s)
78
+ Broadcast.new self, broadcast_json
79
+ end
80
+
81
+
82
+ # Stops an OpenTok broadcast
83
+ #
84
+ # Note that broadcasts automatically stop after 120 minute
85
+ #
86
+ # @param [String] broadcast_id The broadcast ID.
87
+ #
88
+ # @return [Broadcast] The broadcast object, which includes properties defining the broadcast.
89
+ #
90
+ # @raise [OpenTokBroadcastError] The broadcast could not be stopped. The request was invalid.
91
+ # @raise [OpenTokAuthenticationError] Authentication failed.
92
+ # Invalid API key.
93
+ # @raise [OpenTokError] OpenTok server error.
94
+ def stop(broadcast_id)
95
+ raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
96
+ broadcast_json = @client.stop_broadcast(broadcast_id)
97
+ Broadcast.new self, broadcast_json
98
+ end
99
+
100
+ # Dynamically alters the layout an OpenTok broadcast. For more information, see
101
+ # For more information, see
102
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts Configuring video layout for OpenTok live streaming broadcasts}.
103
+ #
104
+ # @param [String] broadcast_id
105
+ # The broadcast ID.
106
+ #
107
+ # @option options [String] :type
108
+ # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
109
+ # "horizontalPresentation", "focus", or "custom".
110
+ #
111
+ # @option options [String] :stylesheet
112
+ # The stylesheet for a custom layout. Set this parameter
113
+ # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
114
+ #
115
+ # @raise [OpenTokBroadcastError]
116
+ # The broadcast layout could not be updated.
117
+ #
118
+ # @raise [OpenTokAuthenticationError]
119
+ # Authentication failed. Invalid API key or secret.
120
+ #
121
+ # @raise [OpenTokError]
122
+ # OpenTok server error.
123
+ #
124
+ # @raise [ArgumentError]
125
+ # The broadcast_id or options parameter is empty.
126
+ #
127
+ # @raise [ArgumentError]
128
+ # The "custom" type was specified without a stylesheet option.
129
+ #
130
+ # @raise [ArgumentError]
131
+ # A stylesheet was passed in for a type other than custom. Or an invalid type was passed in.
132
+ #
133
+ # @raise [ArgumentError]
134
+ # An invalid layout type was passed in.
135
+ def layout(broadcast_id, options = {})
136
+ raise ArgumentError, "option parameter is empty" if options.empty?
137
+ raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
138
+ type = options[:type]
139
+ raise ArgumentError, "custom type must have a stylesheet" if (type.eql? "custom") && (!options.key? :stylesheet)
140
+ valid_non_custom_type = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""].include? type
141
+ raise ArgumentError, "type is not valid" if !valid_non_custom_type
142
+ raise ArgumentError, "stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
143
+ response = @client.layout_broadcast(broadcast_id, options)
144
+ (200..300).include? response.code
145
+ end
146
+
147
+
148
+ end
149
+ end