opentok 4.1.0 → 4.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +30 -0
  3. data/.github/workflows/metrics.yml +17 -0
  4. data/CHANGES.md +171 -0
  5. data/README.md +62 -38
  6. data/lib/opentok/archive.rb +54 -4
  7. data/lib/opentok/archives.rb +115 -11
  8. data/lib/opentok/broadcast.rb +50 -3
  9. data/lib/opentok/broadcast_list.rb +14 -0
  10. data/lib/opentok/broadcasts.rb +178 -19
  11. data/lib/opentok/client.rb +251 -0
  12. data/lib/opentok/connections.rb +1 -1
  13. data/lib/opentok/constants.rb +1 -0
  14. data/lib/opentok/exceptions.rb +3 -1
  15. data/lib/opentok/opentok.rb +16 -10
  16. data/lib/opentok/render.rb +78 -0
  17. data/lib/opentok/render_list.rb +14 -0
  18. data/lib/opentok/renders.rb +101 -0
  19. data/lib/opentok/session.rb +4 -4
  20. data/lib/opentok/sip.rb +40 -2
  21. data/lib/opentok/streams.rb +49 -2
  22. data/lib/opentok/token_generator.rb +1 -0
  23. data/lib/opentok/version.rb +1 -1
  24. data/opentok.gemspec +2 -1
  25. data/sample/Broadcast/README.md +42 -0
  26. data/sample/Broadcast/broadcast_sample.rb +15 -0
  27. data/sample/Broadcast/views/all.erb +46 -0
  28. data/sample/Broadcast/views/index.erb +16 -1
  29. data/spec/cassettes/OpenTok_Archives/adds_a_stream_to_an_archive.yml +37 -0
  30. data/spec/cassettes/OpenTok_Archives/removes_a_stream_from_an_archive.yml +37 -0
  31. data/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_matching_multi_archive_tag_when_multiArchiveTag_is_specified.yml +50 -0
  32. data/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_multi_archive_tag_value_of_nil_when_multiArchiveTag_not_specified.yml +49 -0
  33. data/spec/cassettes/OpenTok_Archives/should_create_an_archives_with_a_specified_multiArchiveTag.yml +52 -0
  34. data/spec/cassettes/OpenTok_Archives/should_create_layout_archives_with_screenshare_layout_types.yml +50 -0
  35. data/spec/cassettes/OpenTok_Broadcasts/adds_a_stream_to_a_broadcast.yml +37 -0
  36. data/spec/cassettes/OpenTok_Broadcasts/for_many_broadcasts/should_return_all_broadcasts.yml +192 -0
  37. data/spec/cassettes/OpenTok_Broadcasts/for_many_broadcasts/should_return_broadcasts_with_an_offset.yml +117 -0
  38. data/spec/cassettes/OpenTok_Broadcasts/for_many_broadcasts/should_return_count_number_of_broadcasts.yml +92 -0
  39. data/spec/cassettes/OpenTok_Broadcasts/for_many_broadcasts/should_return_part_of_the_broadcasts_when_using_offset_and_count.yml +142 -0
  40. data/spec/cassettes/OpenTok_Broadcasts/for_many_broadcasts/should_return_session_broadcasts.yml +117 -0
  41. data/spec/cassettes/OpenTok_Broadcasts/removes_a_stream_from_a_broadcast.yml +37 -0
  42. data/spec/cassettes/OpenTok_Broadcasts/starts_a_broadcast_with_a_matching_multi_broadcast_tag_value_when_multiBroadcastTag_is_specified.yml +54 -0
  43. data/spec/cassettes/OpenTok_Broadcasts/starts_a_broadcast_with_a_multi_broadcast_tag_value_of_nil_when_multiBroadcastTag_not_specified.yml +53 -0
  44. data/spec/cassettes/OpenTok_Broadcasts/starts_a_broadcast_with_a_specified_multiBroadcastTag.yml +54 -0
  45. data/spec/cassettes/OpenTok_Renders/finds_an_Experience_Composer_render.yml +46 -0
  46. data/spec/cassettes/OpenTok_Renders/for_many_renders/should_return_all_renders.yml +108 -0
  47. data/spec/cassettes/OpenTok_Renders/for_many_renders/should_return_count_number_of_renders.yml +63 -0
  48. data/spec/cassettes/OpenTok_Renders/for_many_renders/should_return_part_of_the_renders_when_using_offset_and_count.yml +63 -0
  49. data/spec/cassettes/OpenTok_Renders/for_many_renders/should_return_renders_with_an_offset.yml +74 -0
  50. data/spec/cassettes/OpenTok_Renders/starts_an_Experience_Composer_render.yml +48 -0
  51. data/spec/cassettes/OpenTok_Renders/stops_an_Experience_Composer_render.yml +28 -0
  52. data/spec/cassettes/OpenTok_Sip/_play_dtmf_to_connection/returns_a_200_response_code_when_passed_a_valid_dtmf_digit_string.yml +39 -0
  53. data/spec/cassettes/OpenTok_Sip/_play_dtmf_to_session/returns_a_200_response_code_when_passed_a_valid_dtmf_digit_string.yml +39 -0
  54. data/spec/cassettes/OpenTok_Sip/receives_a_valid_response.yml +2 -2
  55. data/spec/cassettes/OpenTok_Streams/disables_the_mute_state_of_a_session.yml +37 -0
  56. data/spec/cassettes/OpenTok_Streams/forces_all_current_and_future_streams_in_a_session_to_be_muted.yml +39 -0
  57. data/spec/cassettes/OpenTok_Streams/forces_all_current_and_future_streams_in_a_session_to_be_muted_except_specified_excluded_streams.yml +39 -0
  58. data/spec/cassettes/OpenTok_Streams/forces_the_specified_stream_to_be_muted.yml +39 -0
  59. data/spec/opentok/archives_spec.rb +61 -0
  60. data/spec/opentok/broadcasts_spec.rb +157 -1
  61. data/spec/opentok/connection_spec.rb +1 -1
  62. data/spec/opentok/opentok_spec.rb +6 -0
  63. data/spec/opentok/renders_spec.rb +142 -0
  64. data/spec/opentok/sip_spec.rb +32 -1
  65. data/spec/opentok/streams_spec.rb +21 -1
  66. metadata +75 -7
  67. data/.travis.yml +0 -17
@@ -39,22 +39,42 @@ module OpenTok
39
39
  # (a video track is included). If you set both <code>has_audio</code> and
40
40
  # <code>has_video</code> to <code>false</code>, the call to the <code>create()</code>
41
41
  # method results in an error.
42
+ # @option options [String] :multiArchiveTag (Optional) Set this to support recording multiple archives for the same session simultaneously.
43
+ # Set this to a unique string for each simultaneous archive of an ongoing session. You must also set this option when manually starting an archive
44
+ # that is {https://tokbox.com/developer/guides/archiving/#automatic automatically archived}. Note that the `multiArchiveTag` value is not included
45
+ # in the response for the methods to {https://tokbox.com/developer/rest/#listing_archives list archives} and
46
+ # {https://tokbox.com/developer/rest/#retrieve_archive_info retrieve archive information}. If you do not specify a unique `multiArchiveTag`,
47
+ # you can only record one archive at a time for a given session.
48
+ # {https://tokbox.com/developer/guides/archiving/#simultaneous-archives See Simultaneous archives}.
42
49
  # @option options [String] :output_mode Whether all streams in the archive are recorded
43
50
  # to a single file (<code>:composed</code>, the default) or to individual files
44
51
  # (<code>:individual</code>). For more information on archiving and the archive file
45
52
  # formats, see the {https://tokbox.com/opentok/tutorials/archiving OpenTok archiving}
46
53
  # 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.
54
+ # @option options [String] :resolution The resolution of the archive, either "640x480" (SD landscape,
55
+ # the default), "1280x720" (HD landscape), "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280"
56
+ # (HD portrait), or "1080x1920" (FHD portrait). This property only applies to composed archives. If you set
57
+ # this property and set the outputMode property to "individual", a call to the method
58
+ # results in an error.
59
+ # @option options [String] :streamMode (Optional) Whether streams included in the archive are selected
60
+ # automatically ("auto", the default) or manually ("manual"). When streams are selected automatically ("auto"),
61
+ # all streams in the session can be included in the archive. When streams are selected manually ("manual"),
62
+ # you specify streams to be included based on calls to the {Archives#add_stream} method. You can specify whether a
63
+ # stream's audio, video, or both are included in the archive.
64
+ # In composed archives, in both automatic and manual modes, the archive composer includes streams based
65
+ # on {https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules stream prioritization rules}.
66
+ # Important: this feature is currently available in the Standard environment only.
51
67
  # @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),
68
+ # the archive. This applies only to composed archives. This is a hash containing three keys:
69
+ # <code>:type</code>, <code>:stylesheet<code> and <code>:screenshare_type</code>.
70
+ # Valid values for <code>:type</code> are "bestFit" (best fit), "custom" (custom),
71
+ # "horizontalPresentation" (horizontal presentation),
55
72
  # "pip" (picture-in-picture), and "verticalPresentation" (vertical presentation)).
56
73
  # If you specify a "custom" layout type, set the <code>:stylesheet</code> key to the
57
74
  # stylesheet (CSS). (For other layout types, do not set the <code>:stylesheet</code> key.)
75
+ # Valid values for <code>:screenshare_type</code> are "bestFit", "pip",
76
+ # "verticalPresentation", "horizontalPresentation". This property is optional.
77
+ # If it is specified, then the <code>:type</code> property **must** be set to "bestFit".
58
78
  # If you do not specify an initial layout type, the archive uses the best fit
59
79
  # layout type. For more information, see
60
80
  # {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
@@ -167,10 +187,10 @@ module OpenTok
167
187
  # {https://tokbox.com/developer/guides/archiving/layout-control.html Customizing
168
188
  # the video layout for composed archives}.
169
189
  #
170
- # @param [String] archive_id
190
+ # @param [String] archive_id
171
191
  # The archive ID.
172
192
  #
173
- # @option options [String] :type
193
+ # @option options [String] :type
174
194
  # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
175
195
  # "horizontalPresentation", "focus", or "custom".
176
196
  #
@@ -178,6 +198,11 @@ module OpenTok
178
198
  # The stylesheet for a custom layout. Set this parameter
179
199
  # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
180
200
  #
201
+ # @option options [String] :screenshare_type
202
+ # The screenshare layout type. Set this to "bestFit", "pip", "verticalPresentation" or
203
+ # "horizonalPresentation". If this is defined, then the <code>type</code> parameter
204
+ # must be set to <code>"bestFit"</code>.
205
+ #
181
206
  # @raise [ArgumentError]
182
207
  # The archive_id or options parameter is empty. Or the "custom"
183
208
  # type was specified without a stylesheet option. Or a stylesheet was passed in for a
@@ -208,11 +233,90 @@ module OpenTok
208
233
  raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty?
209
234
  type = options[:type]
210
235
  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
236
+ valid_non_custom_layouts = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""]
237
+ valid_non_custom_type = valid_non_custom_layouts.include? type
238
+ raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom")
213
239
  raise ArgumentError, "type is not valid or stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
240
+ raise ArgumentError, "screenshare_type is not valid" if options[:screenshare_type] && !valid_non_custom_layouts.include?(options[:screenshare_type])
241
+ raise ArgumentError, "type must be set to 'bestFit' if screenshare_type is defined" if options[:screenshare_type] && type != 'bestFit'
214
242
  response = @client.layout_archive(archive_id, options)
215
243
  (200..300).include? response.code
216
244
  end
245
+
246
+ # Adds a stream to currently running composed archive that was started with the
247
+ # streamMode set to "manual". For a description of the feature, see
248
+ # {https://tokbox.com/developer/rest/#selecting-archive-streams}.
249
+ #
250
+ # @param [String] archive_id
251
+ # The archive ID.
252
+ #
253
+ # @param [String] stream_id
254
+ # The ID for the stream to be added to the archive
255
+ #
256
+ # @option opts [true, false] :has_audio
257
+ # (Boolean, optional) — Whether the composed archive should include the stream's
258
+ # audio (true, the default) or not (false).
259
+ #
260
+ # @option opts [true, false] :has_video
261
+ # (Boolean, optional) — Whether the composed archive should include the stream's
262
+ # video (true, the default) or not (false).
263
+ #
264
+ # You can call the method repeatedly with add_stream set to the same stream ID, to
265
+ # toggle the stream's audio or video in the archive. If you set both has_audio and
266
+ # has_video to false, you will get error response.
267
+ #
268
+ # @raise [ArgumentError]
269
+ # The archive_id parameter is empty.
270
+ #
271
+ # @raise [ArgumentError]
272
+ # The stream_id parameter is empty.
273
+ #
274
+ # @raise [ArgumentError]
275
+ # The has_audio and has_video properties of the options parameter are both set to "false"
276
+ #
277
+ def add_stream(archive_id, stream_id, options)
278
+ raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty?
279
+ raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty?
280
+ if options.has_key?(:has_audio) && options.has_key?(:has_video)
281
+ has_audio = options[:has_audio]
282
+ has_video = options[:has_video]
283
+ raise ArgumentError, "has_audio and has_video can't both be false" if audio_and_video_options_both_false?(has_audio, has_video)
284
+ end
285
+ options['add_stream'] = stream_id
286
+
287
+ @client.select_streams_for_archive(archive_id, options)
288
+ end
289
+
290
+ # Removes a stream from a currently running composed archive that was started with the
291
+ # streamMode set to "manual". For a description of the feature, see
292
+ # {https://tokbox.com/developer/rest/#selecting-archive-streams}.
293
+ #
294
+ # @param [String] archive_id
295
+ # The archive ID.
296
+ #
297
+ # @param [String] stream_id
298
+ # The ID for the stream to be removed from the archive
299
+ #
300
+ # @raise [ArgumentError]
301
+ # The archive_id parameter id is empty.
302
+ #
303
+ # @raise [ArgumentError]
304
+ # The stream_id parameter is empty.
305
+ #
306
+ def remove_stream(archive_id, stream_id)
307
+ raise ArgumentError, "archive_id not provided" if archive_id.to_s.empty?
308
+ raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty?
309
+ options = {}
310
+ options['remove_stream'] = stream_id
311
+
312
+ @client.select_streams_for_archive(archive_id, options)
313
+ end
314
+
315
+ private
316
+
317
+ def audio_and_video_options_both_false?(has_audio, has_video)
318
+ has_audio == false && has_video == false
319
+ end
320
+
217
321
  end
218
322
  end
@@ -20,7 +20,13 @@ module OpenTok
20
20
  # For this start method, this timestamp matches the createdAt timestamp.
21
21
  #
22
22
  # @attr [string] resolution
23
- # The resolution of the broadcast: either "640x480" (SD, the default) or "1280x720" (HD). This property is optional.
23
+ # The resolution of the broadcast: either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
24
+ # "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920" (FHD portrait).
25
+ # You may want to use a portrait aspect ratio for broadcasts that include video streams from mobile devices (which often use the portrait aspect ratio).
26
+ # This property is optional.
27
+ #
28
+ # @attr [string] streamMode
29
+ # Whether streams included in the broadcast are selected automatically ("auto", the default) or manually ("manual").
24
30
  #
25
31
  # @attr [Hash] broadcastUrls is defined as follows:
26
32
  # This object defines the types of broadcast streams you want to start (both HLS and RTMP).
@@ -40,12 +46,13 @@ module OpenTok
40
46
  # * "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
47
  # * "error" -- There is an error in the OpenTok platform.
42
48
  class Broadcast
43
-
49
+ attr_reader :multi_broadcast_tag
44
50
  # @private
45
51
  def initialize(interface, json)
46
52
  @interface = interface
47
53
  # TODO: validate json fits schema
48
54
  @json = json
55
+ @multi_broadcast_tag = @json['multiBroadcastTag']
49
56
  end
50
57
 
51
58
  # A JSON-encoded string representation of the broadcast.
@@ -65,7 +72,7 @@ module OpenTok
65
72
  # For more information, see
66
73
  # {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
74
  #
68
- # @option options [String] :type
75
+ # @option options [String] :type
69
76
  # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
70
77
  # "horizontalPresentation", "focus", or "custom".
71
78
  #
@@ -100,6 +107,46 @@ module OpenTok
100
107
  @json = @interface.layout(@json['id'], opts)
101
108
  end
102
109
 
110
+ # Adds a stream to currently running broadcast that was started with the
111
+ # streamMode set to "manual". For a description of the feature, see
112
+ # {https://tokbox.com/developer/rest/#selecting-broadcast-streams}.
113
+ #
114
+ # @param [String] stream_id
115
+ # The ID for the stream to be added to the broadcast
116
+ #
117
+ # @option opts [true, false] :has_audio
118
+ # (Boolean, optional) — Whether the broadcast should include the stream's
119
+ # audio (true, the default) or not (false).
120
+ #
121
+ # @option opts [true, false] :has_video
122
+ # (Boolean, optional) — Whether the broadcast should include the stream's
123
+ # video (true, the default) or not (false).
124
+ #
125
+ # @raise [OpenTokBroadcastError]
126
+ # The streamMode for the broadcast is not set to "manual".
127
+ #
128
+ # You can call the method repeatedly with add_stream set to the same stream ID, to
129
+ # toggle the stream's audio or video in the broadcast. If you set both has_audio and
130
+ # has_video to false, you will get error response.
131
+ def add_stream(stream_id, opts = {})
132
+ raise OpenTokBroadcastError, "stream_mode must be manual in order to add a stream" unless @json['streamMode'] == 'manual'
133
+ @interface.add_stream(@json['id'], stream_id, opts)
134
+ end
135
+
136
+ # Removes a stream to currently running broadcast that was started with the
137
+ # streamMode set to "manual". For a description of the feature, see
138
+ # {https://tokbox.com/developer/rest/#selecting-broadcast-streams}.
139
+ #
140
+ # @param [String] stream_id
141
+ # The ID for the stream to be removed from the broadcast
142
+ #
143
+ # @raise [OpenTokBroadcastError]
144
+ # The streamMode for the broadcast is not set to "manual".
145
+ def remove_stream(stream_id)
146
+ raise OpenTokBroadcastError, "stream_mode must be manual in order to add a stream" unless @json['streamMode'] == 'manual'
147
+ @interface.remove_stream(@json['id'], stream_id)
148
+ end
149
+
103
150
  # @private ignore
104
151
  def method_missing(method, *args, &block)
105
152
  camelized_method = method.to_s.camelize(:lower)
@@ -0,0 +1,14 @@
1
+ require "opentok/broadcast"
2
+
3
+ module OpenTok
4
+ # A class for accessing an array of Broadcast objects.
5
+ class BroadcastList < Array
6
+ # The total number of broadcasts.
7
+ attr_reader :total
8
+
9
+ def initialize(interface, json)
10
+ @total = json["count"]
11
+ super json["items"].map { |item| ::OpenTok::Broadcast.new interface, item }
12
+ end
13
+ end
14
+ end
@@ -1,6 +1,6 @@
1
1
  require "opentok/client"
2
2
  require "opentok/broadcast"
3
-
3
+ require "opentok/broadcast_list"
4
4
 
5
5
  module OpenTok
6
6
  # A class for working with OpenTok live streaming broadcasts.
@@ -22,42 +22,96 @@ module OpenTok
22
22
  # @param [String] session_id The session ID of the OpenTok session to broadcast.
23
23
  #
24
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.
25
+ #
26
+ # @option options [Hash] :layout Specify this to assign the initial layout type for
27
+ # the broadcast. This is a hash containing three keys:
28
+ # <code>:type</code>, <code>:stylesheet<code> and <code>:screenshare_type</code>.
29
+ # Valid values for <code>:type</code> are "bestFit" (best fit), "custom" (custom),
30
+ # "horizontalPresentation" (horizontal presentation),
31
+ # "pip" (picture-in-picture), and "verticalPresentation" (vertical presentation)).
32
+ # If you specify a "custom" layout type, set the <code>:stylesheet</code> key to the
33
+ # stylesheet (CSS). (For other layout types, do not set the <code>:stylesheet</code> key.)
34
+ # Valid values for <code>:screenshare_type</code> are "bestFit", "pip",
35
+ # "verticalPresentation", "horizontalPresentation". This property is optional.
36
+ # If it is specified, then the <code>:type</code> property **must** be set to "bestFit".
37
+ # If you do not specify an initial layout type, the broadcast uses the best fit
38
+ # layout type.
39
+ #
40
+ # @option options [String] :multiBroadcastTag (Optional) Set this to support multiple broadcasts for the same session simultaneously.
41
+ # Set this to a unique string for each simultaneous broadcast of an ongoing session. Note that the `multiBroadcastTag` value is *not* included
42
+ # in the response for the methods to {https://tokbox.com/developer/rest/#list_broadcasts list live streaming broadcasts} and
43
+ # {https://tokbox.com/developer/rest/#get_info_broadcast get information about a live streaming broadcast}.
44
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming#simultaneous-broadcasts See Simultaneous broadcasts}.
32
45
  #
33
46
  # @option options [int] maxDuration
34
47
  # The maximum duration for the broadcast, in seconds. The broadcast will automatically stop when
35
48
  # 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).
49
+ # The default maximum duration is 4 hours (14,400 seconds).
37
50
  #
38
- # @option options [Hash] outputs
51
+ # @option options [Hash] outputs (Required)
39
52
  # This object defines the types of broadcast streams you want to start (both HLS and RTMP).
40
53
  # You can include HLS, RTMP, or both as broadcast streams. If you include RTMP streaming,
41
54
  # 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,
55
+ #
56
+ # For multiple RTMP streams, the (<code>:rtmp</code>) property is set to an [Array] of Rtmp [Hash] objects.
57
+ # For each RTMP hash, specify (<code>:serverUrl</code>) for the RTMP server URL,
45
58
  # (<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.
59
+ # and (optionally) (<code>:id</code>), a unique ID for the stream. If you specify an ID, it will be
60
+ # included in the (<code>broadcast_json</code>) response from the Client#start_broadcast method call,
61
+ # and is also available in the (<code>broadcast_json</code>) response from the Broadcasts#find method.
62
+ # Vonage streams the session to each RTMP URL you specify. Note that OpenTok live streaming
63
+ # supports RTMP and RTMPS.
64
+ # If you need to support only one RTMP URL, you can set a Rtmp [Hash] object (instead of an array of
65
+ # objects) for the (<code>:rtmp</code>) property value in the (<code>:outputs</code>) [Hash].
66
+ #
67
+ # For HLS, the (<code>:hls</code>) property in the (<code>:outputs</code>) [Hash] is set to a HLS [Hash]
68
+ # object. This object includes the following optional properties:
69
+ # - (<code>:dvr</code>) (Boolean). Whether to enable
70
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#dvr DVR functionality}
71
+ # (rewinding, pausing, and resuming)
72
+ # in players that support it (true), or not (false, the default). With DVR enabled, the HLS URL will
73
+ # include a ?DVR query string appended to the end.
74
+ # - (<code>:low_latency</code>) (Boolean). Whether to enable
75
+ # {https://tokbox.com/developer/guides/broadcast/live-streaming/#low-latency low-latency mode}
76
+ # for the HLSstream.
77
+ # Some HLS players do not support low-latency mode. This feature is incompatible with DVR mode HLS
78
+ # broadcasts (both can't be set to true). This is a beta feature.
79
+ # The HLS URL is included in the (<code>broadcast_json</code>) response from the Client#start_broadcast
80
+ # method call, and is also available in the (<code>broadcast_json</code>) response from the
81
+ # Broadcasts#find method.
47
82
  #
48
83
  # @option options [string] resolution
49
- # The resolution of the broadcast: either "640x480" (SD, the default) or "1280x720" (HD).
84
+ # The resolution of the broadcast: either "640x480" (SD landscape, the default), "1280x720" (HD landscape),
85
+ # "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920"
86
+ # (FHD portrait).
87
+ #
88
+ # @option options [String] :streamMode (Optional) Whether streams included in the broadcast are selected
89
+ # automatically ("auto", the default) or manually ("manual"). When streams are selected automatically ("auto"),
90
+ # all streams in the session can be included in the broadcast. When streams are selected manually ("manual"),
91
+ # you specify streams to be included based on calls to the
92
+ # {Broadcasts#add_stream} method. You can specify whether a
93
+ # stream's audio, video, or both are included in the broadcast.
94
+ # For both automatic and manual modes, the broadcast composer includes streams based
95
+ # on {https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules stream prioritization rules}.
96
+ # Important: this feature is currently available in the Standard environment only.
50
97
  #
51
98
  # @return [Broadcast] The broadcast object, which includes properties defining the broadcast,
52
99
  # including the broadcast ID.
53
100
  #
54
101
  # @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.
102
+ # @raise [OpenTokAuthenticationError] Authentication failed while starting an broadcast.
56
103
  # Invalid API key.
57
104
  # @raise [OpenTokError] OpenTok server error.
58
105
  def create(session_id, options = {})
59
106
  raise ArgumentError, "session_id not provided" if session_id.to_s.empty?
60
107
  raise ArgumentError, "options cannot be empty" if options.empty?
108
+ raise ArgumentError, "outputs property is required in options" unless options.has_key?(:outputs)
109
+ raise ArgumentError, "outputs must be a Hash" unless options[:outputs].is_a? Hash
110
+ if options[:outputs].has_key?(:hls)
111
+ dvr = options[:outputs][:hls][:dvr]
112
+ low_latency = options[:outputs][:hls][:low_latency]
113
+ raise ArgumentError, "dvr and low_latency can't both be true for HLS" if hls_dvr_and_low_latency_options_both_true?(dvr, low_latency)
114
+ end
61
115
  broadcast_json = @client.start_broadcast(session_id, options)
62
116
  Broadcast.new self, broadcast_json
63
117
  end
@@ -78,6 +132,25 @@ module OpenTok
78
132
  Broadcast.new self, broadcast_json
79
133
  end
80
134
 
135
+ # Returns a BroadcastList, which is an array of broadcasts that are completed and in-progress,
136
+ # for your API key.
137
+ #
138
+ # @param [Hash] options A hash with keys defining which range of broadcasts to retrieve.
139
+ # @option options [integer] :offset Optional. The index offset of the first broadcast. 0 is offset
140
+ # of the most recently started broadcast. 1 is the offset of the broadcast that started prior to
141
+ # the most recent broadcast. If you do not specify an offset, 0 is used.
142
+ # @option options [integer] :count Optional. The number of broadcasts to be returned. The maximum
143
+ # number of broadcasts returned is 1000.
144
+ # @option options [String] :session_id Optional. The session ID that broadcasts belong to.
145
+ # https://tokbox.com/developer/rest/#list_broadcasts
146
+ #
147
+ # @return [BroadcastList] An BroadcastList object, which is an array of Broadcast objects.
148
+ def all(options = {})
149
+ raise ArgumentError, "Limit is invalid" unless options[:count].nil? || (0..1000).include?(options[:count])
150
+
151
+ broadcast_list_json = @client.list_broadcasts(options[:offset], options[:count], options[:sessionId])
152
+ BroadcastList.new self, broadcast_list_json
153
+ end
81
154
 
82
155
  # Stops an OpenTok broadcast
83
156
  #
@@ -104,7 +177,7 @@ module OpenTok
104
177
  # @param [String] broadcast_id
105
178
  # The broadcast ID.
106
179
  #
107
- # @option options [String] :type
180
+ # @option options [String] :type
108
181
  # The layout type. Set this to "bestFit", "pip", "verticalPresentation",
109
182
  # "horizontalPresentation", "focus", or "custom".
110
183
  #
@@ -112,6 +185,11 @@ module OpenTok
112
185
  # The stylesheet for a custom layout. Set this parameter
113
186
  # if you set <code>type</code> to <code>"custom"</code>. Otherwise, leave it undefined.
114
187
  #
188
+ # @option options [String] :screenshare_type
189
+ # The screenshare layout type. Set this to "bestFit", "pip", "verticalPresentation" or
190
+ # "horizonalPresentation". If this is defined, then the <code>type</code> parameter
191
+ # must be set to <code>"bestFit"</code>.
192
+ #
115
193
  # @raise [OpenTokBroadcastError]
116
194
  # The broadcast layout could not be updated.
117
195
  #
@@ -137,13 +215,94 @@ module OpenTok
137
215
  raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
138
216
  type = options[:type]
139
217
  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
218
+ valid_non_custom_layouts = ["bestFit","horizontalPresentation","pip", "verticalPresentation", ""]
219
+ valid_non_custom_type = valid_non_custom_layouts.include? type
220
+ raise ArgumentError, "type is not valid" if !valid_non_custom_type && !(type.eql? "custom")
142
221
  raise ArgumentError, "stylesheet not needed" if valid_non_custom_type and options.key? :stylesheet
222
+ raise ArgumentError, "screenshare_type is not valid" if options[:screenshare_type] && !valid_non_custom_layouts.include?(options[:screenshare_type])
223
+ raise ArgumentError, "type must be set to 'bestFit' if screenshare_type is defined" if options[:screenshare_type] && type != 'bestFit'
143
224
  response = @client.layout_broadcast(broadcast_id, options)
144
225
  (200..300).include? response.code
145
226
  end
146
227
 
228
+ # Adds a stream to currently running broadcast that was started with the
229
+ # streamMode set to "manual". For a description of the feature, see
230
+ # {https://tokbox.com/developer/rest/#selecting-broadcast-streams}.
231
+ #
232
+ # @param [String] broadcast_id
233
+ # The broadcast ID.
234
+ #
235
+ # @param [String] stream_id
236
+ # The ID for the stream to be added to the broadcast
237
+ #
238
+ # @option opts [true, false] :has_audio
239
+ # (Boolean, optional) — Whether the broadcast should include the stream's
240
+ # audio (true, the default) or not (false).
241
+ #
242
+ # @option opts [true, false] :has_video
243
+ # (Boolean, optional) — Whether the broadcast should include the stream's
244
+ # video (true, the default) or not (false).
245
+ #
246
+ # You can call the method repeatedly with add_stream set to the same stream ID, to
247
+ # toggle the stream's audio or video in the broadcast. If you set both has_audio and
248
+ # has_video to false, you will get error response.
249
+ #
250
+ # @raise [ArgumentError]
251
+ # The broadcast_id parameter is empty.
252
+ #
253
+ # @raise [ArgumentError]
254
+ # The stream_id parameter is empty.
255
+ #
256
+ # @raise [ArgumentError]
257
+ # The has_audio and has_video properties of the options parameter are both set to "false"
258
+ #
259
+ def add_stream(broadcast_id, stream_id, options)
260
+ raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
261
+ raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty?
262
+ if options.has_key?(:has_audio) && options.has_key?(:has_video)
263
+ has_audio = options[:has_audio]
264
+ has_video = options[:has_video]
265
+ raise ArgumentError, "has_audio and has_video can't both be false" if audio_and_video_options_both_false?(has_audio, has_video)
266
+ end
267
+ options['add_stream'] = stream_id
268
+
269
+ @client.select_streams_for_broadcast(broadcast_id, options)
270
+ end
271
+
272
+ # Removes a stream from a currently running broadcast that was started with the
273
+ # streamMode set to "manual". For a description of the feature, see
274
+ # {https://tokbox.com/developer/rest/#selecting-broadcast-streams}.
275
+ #
276
+ # @param [String] broadcast_id
277
+ # The broadcast ID.
278
+ #
279
+ # @param [String] stream_id
280
+ # The ID for the stream to be removed from the broadcast
281
+ #
282
+ # @raise [ArgumentError]
283
+ # The broadcast_id parameter id is empty.
284
+ #
285
+ # @raise [ArgumentError]
286
+ # The stream_id parameter is empty.
287
+ #
288
+ def remove_stream(broadcast_id, stream_id)
289
+ raise ArgumentError, "broadcast_id not provided" if broadcast_id.to_s.empty?
290
+ raise ArgumentError, "stream_id not provided" if stream_id.to_s.empty?
291
+ options = {}
292
+ options['remove_stream'] = stream_id
293
+
294
+ @client.select_streams_for_broadcast(broadcast_id, options)
295
+ end
296
+
297
+ private
298
+
299
+ def audio_and_video_options_both_false?(has_audio, has_video)
300
+ has_audio == false && has_video == false
301
+ end
302
+
303
+ def hls_dvr_and_low_latency_options_both_true?(dvr, low_latency)
304
+ dvr == true && low_latency == true
305
+ end
147
306
 
148
307
  end
149
308
  end