opentok 4.1.0 → 4.5.1

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 (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
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/play-dtmf
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"digits":"0123456789*#p"}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Mon, 01 Nov 2021 12:35:08 GMT
29
+ Content-Type:
30
+ - application/xml
31
+ Content-Length:
32
+ - '177'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: ""
38
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
39
+ recorded_with: VCR 6.0.0
@@ -5,7 +5,7 @@ http_interactions:
5
5
  uri: https://api.opentok.com/v2/project/123456/dial
6
6
  body:
7
7
  encoding: UTF-8
8
- string: '{"sessionId":"SESSIONID","token":"TOKENID","sip":{"uri":"sip:+15128675309@acme.pstn.example.com;transport=tls","auth":{"username":"bob","password":"abc123"},"secure":"true"}}'
8
+ string: '{"sessionId":"SESSIONID","token":"TOKENID","sip":{"uri":"sip:+15128675309@acme.pstn.example.com;transport=tls","auth":{"username":"bob","password":"abc123"},"secure":"true","video":"true","observeForceMute":"true"}}'
9
9
  headers:
10
10
  User-Agent:
11
11
  - OpenTok-Ruby-SDK/<%= version %>
@@ -35,6 +35,6 @@ http_interactions:
35
35
  body:
36
36
  encoding: UTF-8
37
37
  string: '{"id":"2299ba24-a6de-417c-88f7-28da54a441cf","projectId":"123456","sessionId":"SESSIONID","connectionId":"833a7182-61a5-49d4-baae-c324b09953af","streamId":"b1963d15-537f-459a-be89-e00fc310b82b","createdAt":1492468803946,"updatedAt":1492468803946}'
38
- http_version:
38
+ http_version:
39
39
  recorded_at: Mon, 17 Apr 2017 22:40:01 GMT
40
40
  recorded_with: VCR 2.8.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"active":"false"}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Thu, 13 Jan 2022 15:37:24 GMT
29
+ Content-Length:
30
+ - '0'
31
+ Connection:
32
+ - close
33
+ body:
34
+ encoding: UTF-8
35
+ string: ''
36
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
37
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"active":"true"}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Fri, 29 Oct 2021 11:48:19 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '0'
33
+ Connection:
34
+ - close
35
+ body:
36
+ encoding: UTF-8
37
+ string: ''
38
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
39
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/mute
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"excludedStreams":["b1963d15-537f-459a-be89-e00fc310b82b"],"active":"true"}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Fri, 29 Oct 2021 12:01:42 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '0'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: ''
38
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
39
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/stream/STREAMID/mute
6
+ body:
7
+ encoding: UTF-8
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJpc3QiOiJwcm9qZWN0IiwiYWxnIjoiSFMyNTYifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.BplMVhJWx4ld7KLKXqEmow6MjNPPFw9W8IHCMfeb120
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Accept:
19
+ - "*/*"
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Fri, 29 Oct 2021 11:01:54 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '0'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: ''
38
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
39
+ recorded_with: VCR 6.0.0
@@ -42,6 +42,27 @@ describe OpenTok::Archives do
42
42
  expect(archive.name).to eq archive_name
43
43
  end
44
44
 
45
+ it "should create an archives with a specified multiArchiveTag", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
46
+ archive_tag = 'archive-1'
47
+ archive = archives.create session_id, :multiArchiveTag => archive_tag
48
+ expect(archive).to be_an_instance_of OpenTok::Archive
49
+ expect(archive.session_id).to eq session_id
50
+ expect(archive.multiArchiveTag).to eq archive_tag
51
+ end
52
+
53
+ it "should create an archive with matching multi_archive_tag when multiArchiveTag is specified", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
54
+ archive_tag = 'archive-1'
55
+ archive = archives.create session_id, :multiArchiveTag => archive_tag
56
+ expect(archive).to be_an_instance_of OpenTok::Archive
57
+ expect(archive.multi_archive_tag).to eq archive_tag
58
+ end
59
+
60
+ it "should create an archive with multi_archive_tag value of nil when multiArchiveTag not specified", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
61
+ archive = archives.create session_id
62
+ expect(archive).to be_an_instance_of OpenTok::Archive
63
+ expect(archive.multi_archive_tag).to be_nil
64
+ end
65
+
45
66
  it "should create audio only archives", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
46
67
  archive = archives.create session_id, :has_video => false
47
68
  expect(archive).to be_an_instance_of OpenTok::Archive
@@ -67,6 +88,16 @@ describe OpenTok::Archives do
67
88
  expect(archive.session_id).to eq session_id
68
89
  end
69
90
 
91
+ it "should create layout archives with screenshare layout types", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
92
+ screenshare_layout = {
93
+ :type => "bestFit",
94
+ :screenshare_type => "verticalPresentation"
95
+ }
96
+ archive = archives.create session_id, :layout => screenshare_layout
97
+ expect(archive).to be_an_instance_of OpenTok::Archive
98
+ expect(archive.session_id).to eq session_id
99
+ end
100
+
70
101
  it "should stop archives", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
71
102
  archive = archives.stop_by_id started_archive_id
72
103
  expect(archive).to be_an_instance_of OpenTok::Archive
@@ -159,6 +190,25 @@ describe OpenTok::Archives do
159
190
  })
160
191
  }.to raise_error(ArgumentError)
161
192
  end
193
+
194
+ it "raise an error if invalid layout type with screenshare_type" do
195
+ expect {
196
+ archives.layout(started_archive_id, {
197
+ type: "pip",
198
+ screenshare_type: "bestFit"
199
+ })
200
+ }.to raise_error(ArgumentError)
201
+ end
202
+
203
+ it "raise an error if invalid layout screenshare_type" do
204
+ expect {
205
+ archives.layout(started_archive_id, {
206
+ type: "bestFit",
207
+ screenshare_type: "pip1"
208
+ })
209
+ }.to raise_error(ArgumentError)
210
+ end
211
+
162
212
  it "calls layout on archive object", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
163
213
  archive = archives.find findable_archive_id
164
214
  expect(archive).to be_an_instance_of OpenTok::Archive
@@ -230,4 +280,15 @@ describe OpenTok::Archives do
230
280
  it { should raise_error(OpenTok::OpenTokError) }
231
281
  end
232
282
 
283
+ it "adds a stream to an archive", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
284
+ opts = {}
285
+ response = archives.add_stream(started_archive_id, '12312312-3811-4726-b508-e41a0f96c68f', opts)
286
+ expect(response.code).to eq(204)
287
+ end
288
+
289
+ it "removes a stream from an archive", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
290
+ response = archives.remove_stream(started_archive_id, '12312312-3811-4726-b508-e41a0f96c68f')
291
+ expect(response.code).to eq(204)
292
+ end
293
+
233
294
  end
@@ -45,6 +45,22 @@ describe OpenTok::Broadcasts do
45
45
  broadcast.create(nil, {})
46
46
  }.to raise_error(ArgumentError)
47
47
  end
48
+ it 'raises an error if outputs is not set in options' do
49
+ opts = { maxDuration: 5400 }
50
+ expect { broadcast.create(nil, opts) }.to raise_error(ArgumentError)
51
+ end
52
+ it 'raises an error if outputs is set in options but is not a Hash' do
53
+ opts = { outputs: [] }
54
+ expect { broadcast.create(nil, opts) }.to raise_error(ArgumentError)
55
+ end
56
+ it 'raises an error if an HLS Broadcast object has both dvr and low_latency options set to true' do
57
+ opts = {
58
+ outputs: {
59
+ hls: { dvr: true, low_latency: true}
60
+ }
61
+ }
62
+ expect { broadcast.create(nil, opts) }.to raise_error(ArgumentError)
63
+ end
48
64
  it 'fetches a hls broadcast url', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
49
65
  opts = {
50
66
  :outputs => {
@@ -77,6 +93,44 @@ describe OpenTok::Broadcasts do
77
93
  expect(b_rtmp.broadcastUrls["rtmp"].count).to eq 1
78
94
  end
79
95
 
96
+ it 'starts a broadcast with a specified multiBroadcastTag', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
97
+ broadcast_tag = 'broadcast-1'
98
+ opts = {
99
+ :outputs => {
100
+ :hls => {}
101
+ },
102
+ :multiBroadcastTag => broadcast_tag
103
+ }
104
+ broadcast_1 = broadcast.create(session_id, opts)
105
+ expect(broadcast_1).to be_an_instance_of OpenTok::Broadcast
106
+ expect(broadcast_1.id).to eq broadcast_id
107
+ expect(broadcast_1.multiBroadcastTag).to eq broadcast_tag
108
+ end
109
+
110
+ it 'starts a broadcast with a matching multi_broadcast_tag value when multiBroadcastTag is specified', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
111
+ broadcast_tag = 'broadcast-1'
112
+ opts = {
113
+ :outputs => {
114
+ :hls => {}
115
+ },
116
+ :multiBroadcastTag => broadcast_tag
117
+ }
118
+ broadcast_1 = broadcast.create(session_id, opts)
119
+ expect(broadcast_1).to be_an_instance_of OpenTok::Broadcast
120
+ expect(broadcast_1.multi_broadcast_tag).to eq broadcast_tag
121
+ end
122
+
123
+ it 'starts a broadcast with a multi_broadcast_tag value of nil when multiBroadcastTag not specified', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
124
+ opts = {
125
+ :outputs => {
126
+ :hls => {}
127
+ }
128
+ }
129
+ broadcast_1 = broadcast.create(session_id, opts)
130
+ expect(broadcast_1).to be_an_instance_of OpenTok::Broadcast
131
+ expect(broadcast_1.multi_broadcast_tag).to be_nil
132
+ end
133
+
80
134
  it 'finds a broadcast', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
81
135
  b = broadcast.find started_broadcast_id
82
136
  expect(b).to be_an_instance_of OpenTok::Broadcast
@@ -144,6 +198,27 @@ describe OpenTok::Broadcasts do
144
198
  }.to raise_error(ArgumentError)
145
199
  end
146
200
 
201
+ it "raise an error for non valid type" do
202
+ expect {
203
+ broadcast.layout(started_broadcast_id, {
204
+ type: "not-valid",
205
+ stylesheet: "stream {}"
206
+ })
207
+ }.to raise_error(ArgumentError)
208
+ end
209
+
210
+ it "change the layout to custom type with custom stylesheet" do
211
+ stub_request(:put, "https://api.opentok.com/v2/project/#{api_key}/broadcast/#{started_broadcast_id}/layout").
212
+ with(body: {type: 'custom', stylesheet: 'stream {float: left; height: 100%; width: 33.33%;}'}).
213
+ to_return(status: 200)
214
+
215
+ response = broadcast.layout(started_broadcast_id, {
216
+ type: "custom",
217
+ stylesheet: "stream {float: left; height: 100%; width: 33.33%;}"
218
+ })
219
+ expect(response).not_to be_nil
220
+ end
221
+
147
222
  it "raise an error if invalid layout type" do
148
223
  expect {
149
224
  broadcast.layout(started_broadcast_id, {
@@ -151,6 +226,25 @@ describe OpenTok::Broadcasts do
151
226
  })
152
227
  }.to raise_error(ArgumentError)
153
228
  end
229
+
230
+ it "raise an error if invalid layout type with screenshare_type" do
231
+ expect {
232
+ broadcast.layout(started_broadcast_id, {
233
+ type: "pip",
234
+ screenshare_type: "bestFit"
235
+ })
236
+ }.to raise_error(ArgumentError)
237
+ end
238
+
239
+ it "raise an error if invalid layout screenshare_type" do
240
+ expect {
241
+ broadcast.layout(started_broadcast_id, {
242
+ type: "bestFit",
243
+ screenshare_type: "pip1"
244
+ })
245
+ }.to raise_error(ArgumentError)
246
+ end
247
+
154
248
  it "calls layout on broadcast object", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
155
249
  b = broadcast.find started_broadcast_id
156
250
  expect(b).to be_an_instance_of OpenTok::Broadcast
@@ -161,11 +255,73 @@ describe OpenTok::Broadcasts do
161
255
  )
162
256
  }.to raise_error(ArgumentError)
163
257
  end
258
+
164
259
  it "changes the layout of a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
260
+ stub_request(:put, "https://api.opentok.com/v2/project/#{api_key}/broadcast/#{started_broadcast_id}/layout").
261
+ to_return(status: 200)
262
+
165
263
  response = broadcast.layout(started_broadcast_id, {
166
264
  :type => "verticalPresentation"
167
265
  })
168
266
  expect(response).not_to be_nil
169
267
  end
170
268
 
171
- end
269
+ it "changes the screenshare option in the layout of a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
270
+ stub_request(:put, "https://api.opentok.com/v2/project/#{api_key}/broadcast/#{started_broadcast_id}/layout").
271
+ to_return(status: 200)
272
+
273
+ response = broadcast.layout(started_broadcast_id, {
274
+ :type => "bestFit",
275
+ :screenshare_type => "bestFit"
276
+ })
277
+ expect(response).not_to be_nil
278
+ end
279
+
280
+ it "adds a stream to a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
281
+ opts = {}
282
+ response = broadcast.add_stream(started_broadcast_id, '12312312-3811-4726-b508-e41a0f96c68f', opts)
283
+ expect(response.code).to eq(204)
284
+ end
285
+
286
+ it "removes a stream from a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
287
+ response = broadcast.remove_stream(started_broadcast_id, '12312312-3811-4726-b508-e41a0f96c68f')
288
+ expect(response.code).to eq(204)
289
+ end
290
+
291
+ context "for many broadcasts" do
292
+ it "should return all broadcasts", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
293
+ broadcast_list = broadcast.all
294
+ expect(broadcast_list).to be_an_instance_of OpenTok::BroadcastList
295
+ expect(broadcast_list.total).to eq 6
296
+ expect(broadcast_list.count).to eq 6
297
+ end
298
+
299
+ it "should return broadcasts with an offset", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
300
+ broadcast_list = broadcast.all :offset => 3
301
+ expect(broadcast_list).to be_an_instance_of OpenTok::BroadcastList
302
+ expect(broadcast_list.total).to eq 3
303
+ expect(broadcast_list.count).to eq 3
304
+ end
305
+
306
+ it "should return count number of broadcasts", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
307
+ broadcast_list = broadcast.all :count => 2
308
+ expect(broadcast_list).to be_an_instance_of OpenTok::BroadcastList
309
+ expect(broadcast_list.count).to eq 2
310
+ expect(broadcast_list.count).to eq 2
311
+ end
312
+
313
+ it "should return part of the broadcasts when using offset and count", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
314
+ broadcast_list = broadcast.all :count => 4, :offset => 2
315
+ expect(broadcast_list).to be_an_instance_of OpenTok::BroadcastList
316
+ expect(broadcast_list.count).to eq 4
317
+ expect(broadcast_list.count).to eq 4
318
+ end
319
+
320
+ it "should return session broadcasts", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
321
+ broadcast_list = broadcast.all :sessionId => session_id
322
+ expect(broadcast_list).to be_an_instance_of OpenTok::BroadcastList
323
+ expect(broadcast_list.total).to eq 3
324
+ expect(broadcast_list.count).to eq 3
325
+ end
326
+ end
327
+ end
@@ -35,4 +35,4 @@ describe OpenTok::Connections do
35
35
  response = connection.forceDisconnect(session_id, connection_id)
36
36
  expect(response).not_to be_nil
37
37
  end
38
- end
38
+ end
@@ -152,6 +152,12 @@ describe OpenTok::OpenTok do
152
152
  it "should have an timeout_length property" do
153
153
  expect(opentok.timeout_length).to eq timeout_length
154
154
  end
155
+
156
+ it "should send the custom timeout_length to new instances of OpenTok::Client" do
157
+ streams = opentok.streams
158
+
159
+ expect(streams.instance_variable_get(:@client).timeout_length).to eq timeout_length
160
+ end
155
161
  end
156
162
 
157
163
  context "with an addendum to the user agent string" do
@@ -0,0 +1,142 @@
1
+ require "opentok/render"
2
+ require "opentok/renders"
3
+ require "opentok/opentok"
4
+ require "opentok/version"
5
+ require "spec_helper"
6
+
7
+ describe OpenTok::Renders do
8
+ before(:each) do
9
+ now = Time.parse("2017-04-18 20:17:40 +1000")
10
+ allow(Time).to receive(:now) { now }
11
+ end
12
+
13
+ let(:api_key) { "123456" }
14
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
15
+ let(:session_id) { "SESSIONID" }
16
+ let(:render_id) { "80abaf0d-25a3-4efc-968f-6268d620668d" }
17
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
18
+ let(:token) { "TOKEN" }
19
+ let(:render) { opentok.renders }
20
+ let(:render_url) { 'https://example.com/my-render'}
21
+
22
+ subject { render }
23
+
24
+ it 'raises an error on empty sessionId' do
25
+ opts = {
26
+ :token => token,
27
+ :url => render_url
28
+ }
29
+ expect {
30
+ render.start('', opts)
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it 'raises an error on nil sessionId' do
35
+ opts = {
36
+ :token => token,
37
+ :url => render_url
38
+ }
39
+ expect {
40
+ render.start(nil, opts)
41
+ }.to raise_error(ArgumentError)
42
+ end
43
+
44
+ it 'raises an error on empty options' do
45
+ expect {
46
+ render.start(session_id, {})
47
+ }.to raise_error(ArgumentError)
48
+ end
49
+
50
+ it 'raises an error if token is not set in options' do
51
+ opts = { :url => render_url }
52
+ expect { render.start(session_id, opts) }.to raise_error(ArgumentError)
53
+ end
54
+
55
+ it 'raises an error if url is not set in options' do
56
+ opts = { :token => token }
57
+ expect { render.start(session_id, opts) }.to raise_error(ArgumentError)
58
+ end
59
+
60
+ it 'starts an Experience Composer render', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
61
+ opts = {
62
+ :token => token,
63
+ :url => render_url
64
+ }
65
+ r = render.start(session_id, opts)
66
+ expect(r).to be_an_instance_of OpenTok::Render
67
+ expect(r.sessionId).to eq session_id
68
+ expect(r.url).to eq render_url
69
+ expect(r.status).to eq "starting"
70
+ end
71
+
72
+ it 'raises an error on empty renderId in find' do
73
+ expect {
74
+ render.find("")
75
+ }.to raise_error(ArgumentError)
76
+ end
77
+
78
+ it 'raises an error on nil renderId in find' do
79
+ expect {
80
+ render.find(nil)
81
+ }.to raise_error(ArgumentError)
82
+ end
83
+
84
+ it 'finds an Experience Composer render', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
85
+ r = render.find render_id
86
+ expect(r).to be_an_instance_of OpenTok::Render
87
+ expect(r.id).to eq render_id
88
+ end
89
+
90
+ it 'raises an error on empty renderId in stop' do
91
+ expect {
92
+ render.stop("")
93
+ }.to raise_error(ArgumentError)
94
+ end
95
+
96
+ it 'raises an error on nil renderId in stop' do
97
+ expect {
98
+ render.stop(nil)
99
+ }.to raise_error(ArgumentError)
100
+ end
101
+
102
+ it 'stops an Experience Composer render', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
103
+ r = render.stop(render_id)
104
+ expect(r).to be_an_instance_of OpenTok::Render
105
+ end
106
+
107
+ context "for many renders" do
108
+ it 'raises an error for an invalid limit in list' do
109
+ expect {
110
+ render.list(count: 1001)
111
+ }.to raise_error(ArgumentError)
112
+ end
113
+
114
+ it "should return all renders", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
115
+ render_list = render.list
116
+ expect(render_list).to be_an_instance_of OpenTok::RenderList
117
+ expect(render_list.count).to eq 6
118
+ expect(render_list.total).to eq 6
119
+ end
120
+
121
+ it "should return renders with an offset", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
122
+ render_list = render.list :offset => 3
123
+ expect(render_list).to be_an_instance_of OpenTok::RenderList
124
+ expect(render_list.count).to eq 3
125
+ expect(render_list.total).to eq 3
126
+ end
127
+
128
+ it "should return count number of renders", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
129
+ render_list = render.list :count => 2
130
+ expect(render_list).to be_an_instance_of OpenTok::RenderList
131
+ expect(render_list.count).to eq 2
132
+ expect(render_list.total).to eq 2
133
+ end
134
+
135
+ it "should return part of the renders when using offset and count", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
136
+ render_list = render.list :count => 2, :offset => 2
137
+ expect(render_list).to be_an_instance_of OpenTok::RenderList
138
+ expect(render_list.count).to eq 2
139
+ expect(render_list.total).to eq 2
140
+ end
141
+ end
142
+ end