opentok 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +249 -14
  3. data/lib/opentok/archive.rb +45 -4
  4. data/lib/opentok/archives.rb +62 -5
  5. data/lib/opentok/broadcast.rb +118 -0
  6. data/lib/opentok/broadcasts.rb +149 -0
  7. data/lib/opentok/client.rb +206 -3
  8. data/lib/opentok/connections.rb +28 -0
  9. data/lib/opentok/exceptions.rb +6 -0
  10. data/lib/opentok/opentok.rb +40 -8
  11. data/lib/opentok/session.rb +5 -0
  12. data/lib/opentok/signals.rb +47 -0
  13. data/lib/opentok/sip.rb +35 -0
  14. data/lib/opentok/stream.rb +46 -0
  15. data/lib/opentok/stream_list.rb +18 -0
  16. data/lib/opentok/streams.rb +79 -0
  17. data/lib/opentok/version.rb +1 -1
  18. data/spec/cassettes/OpenTok_Archives/calls_layout_on_archive_object.yml +45 -0
  19. data/spec/cassettes/OpenTok_Archives/changes_the_layout_of_an_archive.yml +36 -0
  20. data/spec/cassettes/OpenTok_Archives/should_create_hd_archives.yml +52 -0
  21. data/spec/cassettes/OpenTok_Broadcasts/calls_layout_on_broadcast_object.yml +55 -0
  22. data/spec/cassettes/OpenTok_Broadcasts/changes_the_layout_of_a_broadcast.yml +36 -0
  23. data/spec/cassettes/OpenTok_Broadcasts/fetches_a_hls_broadcast_url.yml +50 -0
  24. data/spec/cassettes/OpenTok_Broadcasts/finds_a_broadcast.yml +55 -0
  25. data/spec/cassettes/OpenTok_Broadcasts/starts_a_rtmp_broadcast.yml +59 -0
  26. data/spec/cassettes/OpenTok_Broadcasts/stops_a_broadcast.yml +45 -0
  27. data/spec/cassettes/OpenTok_Connections/forces_a_connection_to_be_terminated.yml +36 -0
  28. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_a_connection.yml +37 -0
  29. data/spec/cassettes/OpenTok_Signals/receives_a_valid_response_for_all_connections.yml +37 -0
  30. data/spec/cassettes/OpenTok_Streams/get_all_streams_information.yml +53 -0
  31. data/spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml +42 -0
  32. data/spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml +36 -0
  33. data/spec/opentok/archives_spec.rb +73 -0
  34. data/spec/opentok/broadcasts_spec.rb +171 -0
  35. data/spec/opentok/connection_spec.rb +38 -0
  36. data/spec/opentok/signal_spec.rb +50 -0
  37. data/spec/opentok/streams_spec.rb +75 -0
  38. metadata +48 -3
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/signal
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"type":"chat","data":"Hello"}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzdCI6InByb2plY3QifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.Oh_JHhtEUKK1pPV4s6neXJj_RXI8EcEpJRRpG_2c9U0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 204
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Tue, 28 Aug 2018 21:31:02 GMT
25
+ Content-Type:
26
+ - application/xml
27
+ Connection:
28
+ - keep-alive
29
+ Content-Length:
30
+ - '177'
31
+ body:
32
+ encoding: UTF-8
33
+ string: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><errorPayload><code>-1</code><message>Issuer
34
+ not found</message><description>Issuer not found</description></errorPayload>
35
+ http_version:
36
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
37
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,53 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/stream
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzdCI6InByb2plY3QifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.Oh_JHhtEUKK1pPV4s6neXJj_RXI8EcEpJRRpG_2c9U0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Mon, 24 Sep 2018 20:41:24 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Content-Length:
30
+ - '73'
31
+ body:
32
+ encoding: UTF-8
33
+ string: |-
34
+ {
35
+ "count": 2,
36
+ "items": [
37
+ {
38
+ "id": "1234356-0a06-46a2-8ea8-074e64d43422",
39
+ "videoType": "camera",
40
+ "name": "",
41
+ "layoutClassList": ["full", "focus"]
42
+ },
43
+ {
44
+ "id": "8b732909-0a06-46a2-8ea8-074e64d43422",
45
+ "videoType": "screen",
46
+ "name": "",
47
+ "layoutClassList": ["full"]
48
+ }
49
+ ]
50
+ }
51
+ http_version:
52
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
53
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/stream/STREAMID
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzdCI6InByb2plY3QifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.Oh_JHhtEUKK1pPV4s6neXJj_RXI8EcEpJRRpG_2c9U0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Mon, 24 Sep 2018 20:41:24 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Content-Length:
30
+ - '0'
31
+ body:
32
+ encoding: UTF-8
33
+ string: |-
34
+ {
35
+ "id": "8b732909-0a06-46a2-8ea8-074e64d43422",
36
+ "videoType": "camera",
37
+ "name": "",
38
+ "layoutClassList": ["full"]
39
+ }
40
+ http_version:
41
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
42
+ recorded_with: VCR 2.8.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: https://api.opentok.com/v2/project/123456/session/SESSIONID/stream
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"items":[{"id":"8b732909-0a06-46a2-8ea8-074e64d43422","layoutClassList":["full"]},{"id":"8b732909-0a06-46a2-8ea8-074e64d43423","layoutClassList":["full","focus"]}]}'
9
+ headers:
10
+ User-Agent:
11
+ - OpenTok-Ruby-SDK/<%= version %>
12
+ X-Opentok-Auth:
13
+ - eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzdCI6InByb2plY3QifQ.eyJpc3MiOiIxMjM0NTYiLCJpYXQiOjE0OTI1MTA2NjAsImV4cCI6MTQ5MjUxMDk2MH0.Oh_JHhtEUKK1pPV4s6neXJj_RXI8EcEpJRRpG_2c9U0
14
+ Content-Type:
15
+ - application/json
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Wed, 26 Sep 2018 22:48:29 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Connection:
28
+ - keep-alive
29
+ Content-Length:
30
+ - '73'
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"code":-1,"message":"Issuer not found","description":"Issuer not found"}'
34
+ http_version:
35
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
36
+ recorded_with: VCR 2.8.0
@@ -93,6 +93,79 @@ describe OpenTok::Archives do
93
93
  expect(archive).to be_an_instance_of OpenTok::Archive
94
94
  end
95
95
 
96
+ it "should create hd archives", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
97
+ archive = archives.create session_id, { :output_mode => :composed, :resolution => "1280x720" }
98
+ expect(archive).to be_an_instance_of OpenTok::Archive
99
+ expect(archive.session_id).to eq session_id
100
+ expect(archive.output_mode).to eq :composed
101
+ expect(archive.resolution).to eq "1280x720"
102
+ end
103
+
104
+ it "should create archives throws exception", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
105
+ opts = {
106
+ :output_mode => :individual,
107
+ :resolution => "1280x720"
108
+ }
109
+
110
+ expect { archives.create session_id, opts }.to raise_exception
111
+ end
112
+
113
+ it "raise an error if layout options are empty" do
114
+ expect {
115
+ archives.layout(started_archive_id, {})
116
+ }.to raise_error(ArgumentError)
117
+ end
118
+
119
+ it "raise an error if archive id is not provided" do
120
+ expect {
121
+ archives.layout("", {
122
+ type: "custom",
123
+ stylesheet: "the layout stylesheet (only used with type == custom)"
124
+ })
125
+ }.to raise_error(ArgumentError)
126
+ end
127
+
128
+ it "raise an error if custom type has no style sheet" do
129
+ expect {
130
+ archives.layout(started_archive_id, {
131
+ type: "custom",
132
+ })
133
+ }.to raise_error(ArgumentError)
134
+ end
135
+
136
+ it "raise an error if non-custom type has style sheet" do
137
+ expect {
138
+ archives.layout(started_archive_id, {
139
+ type: "pip",
140
+ stylesheet: "the layout stylesheet (only used with type == custom)"
141
+ })
142
+ }.to raise_error(ArgumentError)
143
+ end
144
+
145
+ it "raise an error if invalid layout type" do
146
+ expect {
147
+ archives.layout(started_archive_id, {
148
+ type: "pip1"
149
+ })
150
+ }.to raise_error(ArgumentError)
151
+ end
152
+ it "calls layout on archive object", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
153
+ archive = archives.find findable_archive_id
154
+ expect(archive).to be_an_instance_of OpenTok::Archive
155
+ expect(archive.id).to eq findable_archive_id
156
+ expect {
157
+ archive.layout(
158
+ type: 'pip1',
159
+ )
160
+ }.to raise_error(ArgumentError)
161
+ end
162
+ it "changes the layout of an archive", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
163
+ response = archives.layout(started_archive_id, {
164
+ type: "pip"
165
+ })
166
+ expect(response).not_to be_nil
167
+ end
168
+
96
169
  # TODO: context "with a session that has no participants" do
97
170
  # let(:session_id) { "" }
98
171
  # it "should refuse to create archives with appropriate error" do
@@ -0,0 +1,171 @@
1
+ require "opentok/broadcast"
2
+ require "opentok/broadcasts"
3
+ require "opentok/opentok"
4
+ require "opentok/version"
5
+ require "spec_helper"
6
+
7
+ describe OpenTok::Broadcasts 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(:broadcast_id) { "BROADCASTID" }
17
+ let(:started_broadcast_id) { "13dbcc23-af92-4862-9184-74b21815a814" }
18
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
19
+ let(:broadcast) { opentok.broadcasts }
20
+
21
+ subject { broadcast }
22
+
23
+ it 'raise an error on empty sessionId' do
24
+ opts = {
25
+ :outputs => {
26
+ :hls => {}
27
+ }
28
+ }
29
+ expect {
30
+ broadcast.create('', opts)
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+ it 'raise an error on nil sessionId' do
34
+ opts = {
35
+ :outputs => {
36
+ :hls => {}
37
+ }
38
+ }
39
+ expect {
40
+ broadcast.create(nil, opts)
41
+ }.to raise_error(ArgumentError)
42
+ end
43
+ it 'raise an error on empty options' do
44
+ expect {
45
+ broadcast.create(nil, {})
46
+ }.to raise_error(ArgumentError)
47
+ end
48
+ it 'fetches a hls broadcast url', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
49
+ opts = {
50
+ :outputs => {
51
+ :hls => {}
52
+ }
53
+ }
54
+ b_hls = broadcast.create(session_id, opts)
55
+ expect(b_hls).to be_an_instance_of OpenTok::Broadcast
56
+ expect(b_hls.id).to eq broadcast_id
57
+ expect(b_hls.broadcastUrls['hls']).to eq "https://cdn-broadcast001-pdx.tokbox.com/14787/14787_b930bf08-1c9f-4c55-ab04-7d192578c057.smil/playlist.m3u8"
58
+ end
59
+
60
+ it 'starts a rtmp broadcast', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
61
+ opts = {
62
+ :outputs => {
63
+ :hls => {},
64
+ :rtmp => [
65
+ {
66
+ :id => "rubyTestStream",
67
+ :serverUrl => "rtmp://x.rtmp.youtube.com/live2",
68
+ :streamName => "66c9-jwuh-pquf-9x18"
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ b_rtmp = broadcast.create(session_id, opts)
74
+ expect(b_rtmp).to be_an_instance_of OpenTok::Broadcast
75
+ expect(b_rtmp.id).to eq broadcast_id
76
+ expect(b_rtmp.broadcastUrls["rtmp"][0]["serverUrl"]).to eq "rtmp://x.rtmp.youtube.com/live2"
77
+ expect(b_rtmp.broadcastUrls["rtmp"].count).to eq 1
78
+ end
79
+
80
+ it 'finds a broadcast', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
81
+ b = broadcast.find started_broadcast_id
82
+ expect(b).to be_an_instance_of OpenTok::Broadcast
83
+ expect(b.id).to eq started_broadcast_id
84
+ expect(b.broadcastUrls["rtmp"][0]["serverUrl"]).to eq "rtmp://x.rtmp.youtube.com/live2"
85
+ expect(b.broadcastUrls["rtmp"].count).to eq 1
86
+ end
87
+ it 'raise an error on empty broadcastId in find' do
88
+ expect {
89
+ broadcast.find("")
90
+ }.to raise_error(ArgumentError)
91
+ end
92
+ it 'raise an error on nil broadcastId in find' do
93
+ expect {
94
+ broadcast.find(nil)
95
+ }.to raise_error(ArgumentError)
96
+ end
97
+ it 'raise an error on empty broadcastId stop' do
98
+ expect {
99
+ broadcast.stop("")
100
+ }.to raise_error(ArgumentError)
101
+ end
102
+ it 'raise an error on nil broadcastId stop' do
103
+ expect {
104
+ broadcast.stop(nil)
105
+ }.to raise_error(ArgumentError)
106
+ end
107
+ it 'stops a broadcast', :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
108
+ b = broadcast.stop(started_broadcast_id)
109
+ expect(b).to be_an_instance_of OpenTok::Broadcast
110
+ expect(b.id).to eq started_broadcast_id
111
+ expect(b.broadcastUrls).to be_nil
112
+ expect(b.status).to eq "stopped"
113
+ end
114
+
115
+ it "raise an error if layout options are empty" do
116
+ expect {
117
+ broadcast.layout(started_broadcast_id, {})
118
+ }.to raise_error(ArgumentError)
119
+ end
120
+
121
+ it "raise an error if broadcast id is not provided" do
122
+ expect {
123
+ broadcast.layout("", {
124
+ type: "custom",
125
+ stylesheet: "the layout stylesheet (only used with type == custom)"
126
+ })
127
+ }.to raise_error(ArgumentError)
128
+ end
129
+
130
+ it "raise an error if custom type has no style sheet" do
131
+ expect {
132
+ broadcast.layout(started_broadcast_id, {
133
+ type: "custom",
134
+ })
135
+ }.to raise_error(ArgumentError)
136
+ end
137
+
138
+ it "raise an error if non-custom type has style sheet" do
139
+ expect {
140
+ broadcast.layout(started_broadcast_id, {
141
+ type: "pip",
142
+ stylesheet: "the layout stylesheet (only used with type == custom)"
143
+ })
144
+ }.to raise_error(ArgumentError)
145
+ end
146
+
147
+ it "raise an error if invalid layout type" do
148
+ expect {
149
+ broadcast.layout(started_broadcast_id, {
150
+ type: "pip1"
151
+ })
152
+ }.to raise_error(ArgumentError)
153
+ end
154
+ it "calls layout on broadcast object", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
155
+ b = broadcast.find started_broadcast_id
156
+ expect(b).to be_an_instance_of OpenTok::Broadcast
157
+ expect(b.id).to eq started_broadcast_id
158
+ expect {
159
+ b.layout(
160
+ :type => 'pip1',
161
+ )
162
+ }.to raise_error(ArgumentError)
163
+ end
164
+ it "changes the layout of a broadcast", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" } } do
165
+ response = broadcast.layout(started_broadcast_id, {
166
+ :type => "verticalPresentation"
167
+ })
168
+ expect(response).not_to be_nil
169
+ end
170
+
171
+ end
@@ -0,0 +1,38 @@
1
+ require "opentok/opentok"
2
+ require "opentok/version"
3
+ require "opentok/connections"
4
+ require "spec_helper"
5
+
6
+ describe OpenTok::Connections do
7
+ before(:each) do
8
+ now = Time.parse("2017-04-18 20:17:40 +1000")
9
+ allow(Time).to receive(:now) { now }
10
+ end
11
+
12
+ let(:api_key) { "123456" }
13
+ let(:api_secret) { "1234567890abcdef1234567890abcdef1234567890" }
14
+ let(:session_id) { "SESSIONID" }
15
+ let(:connection_id) { "CONNID" }
16
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
17
+ let(:connection) { opentok.connections }
18
+
19
+ subject { connection }
20
+
21
+
22
+ it 'raise an error on nil session_id' do
23
+ expect {
24
+ connection.forceDisconnect(nil,connection_id)
25
+ }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it 'raise an error on nil connection_id' do
29
+ expect {
30
+ connection.forceDisconnect(session_id,nil)
31
+ }.to raise_error(ArgumentError)
32
+ end
33
+
34
+ it "forces a connection to be terminated", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
35
+ response = connection.forceDisconnect(session_id, connection_id)
36
+ expect(response).not_to be_nil
37
+ end
38
+ end