opentok 4.5.1 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78dc7ec3b0d8d3097e687cc0e7b76d2c9d18e3969372c54a00e3c4f3c95846ed
4
- data.tar.gz: e8c10144c89329205734d7d0dd5c8fb37197c2af0a50401a1d97ec1cbfe9e837
3
+ metadata.gz: '0021225949fed3de846b22c82a91de9a62d5b6a1dd3c272377cd96d0ebe0dffc'
4
+ data.tar.gz: acdc9387e49e85384f25970be630fcbd7a3d6d2e6abe335ed062c2b670eeaed9
5
5
  SHA512:
6
- metadata.gz: 9b481dc1985ffa39e3c371c2d67fc3b6e7b1cdc696db7e21274bea45e0784984facb5cdfdda92bc14f3366af243e8c01f448bc5ddb7cba52e935a8c97bd15694
7
- data.tar.gz: f776558162063de46f8e7e4da99032ec771171098f7cc2e4a2c260374061ec0c840d479e530b2efb24f8ad3754f0da95a27c12a24cdd97c0013680ac31e5b5f7
6
+ metadata.gz: d8d9704ef411eae5a133ab8bd69846f6fc2f9a671e5480e033400abf157e984b2f3e06efbe5e57eac15a832baa95b7ce6b85e28b2fd5c46039a9407c764ab5e4
7
+ data.tar.gz: 63e762828405233f30260842206f837ef25ea1e3156dc5cc3ff339fc6fa46b5ce4eb99f0ebbf096e707c35719c191b2f419a0c31f06fb01e1332b6d8339e1c8c
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 4.6.0
2
+
3
+ * Adds functionality for working with the Audio Connector feature [#247](https://github.com/opentok/OpenTok-Ruby-SDK/pull/247)
4
+
1
5
  # 4.5.1
2
6
 
3
7
  * Fixes issue with uninitialized constant by adding missing `require` statement [#256](https://github.com/opentok/OpenTok-Ruby-SDK/pull/256)
data/README.md CHANGED
@@ -18,6 +18,7 @@ The OpenTok Ruby SDK provides methods for:
18
18
  * [Disconnecting clients from sessions](https://tokbox.com/developer/guides/moderation/rest/)
19
19
  * [Forcing clients in a session to disconnect or mute published audio](https://tokbox.com/developer/guides/moderation/)
20
20
  * Working with OpenTok [Experience Composers](https://tokbox.com/developer/guides/experience-composer)
21
+ * Working with OpenTok [Audio Connector](https://tokbox.com/developer/guides/audio-connector)
21
22
 
22
23
  ## Installation
23
24
 
@@ -188,7 +189,10 @@ archive = opentok.archives.create session_id :output_mode => :individual
188
189
  The `:output_mode => :composed` setting (the default) causes all streams in the archive to be
189
190
  recorded to a single (composed) file.
190
191
 
191
- For composed archives you can set the resolution of the archive, either "640x480" (SD landscape, the default), "1280x720" (HD landscape), "1920x1080" (FHD landscape), "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920" (FHD portrait).. The `resolution` parameter is optional and could be included in the options
192
+ For composed archives you can set the resolution of the archive, either "640x480"
193
+ (SD landscape, the default), "1280x720" (HD landscape), "1920x1080" (FHD landscape),
194
+ "480x640" (SD portrait), "720x1280" (HD portrait), or "1080x1920" (FHD portrait).
195
+ The `resolution` parameter is optional and could be included in the options
192
196
  hash (second argument) of the `opentok.archives.create()` method.
193
197
 
194
198
  ```ruby
@@ -322,7 +326,7 @@ For more information on archiving, see the
322
326
 
323
327
  ### Signaling
324
328
 
325
- You can send a signal using the `opentok.signals.send(session_id, connection_id, opts)` method.
329
+ You can send a signal using the `opentok.signals.send(session_id, connection_id, opts)` method.
326
330
  If `connection_id` is nil or an empty string, then the signal is send to all valid connections in
327
331
  the session.
328
332
 
@@ -457,7 +461,7 @@ You can cause a client to be forced to disconnect from a session by using the
457
461
 
458
462
  ### Forcing clients in a session to mute published audio
459
463
 
460
- You can force the publisher of a specific stream to stop publishing audio using the
464
+ You can force the publisher of a specific stream to stop publishing audio using the
461
465
  `opentok.streams.force_mute(session_id, stream_id)` method.
462
466
 
463
467
  You can force the publisher of all streams in a session (except for an optional list of streams)
@@ -495,6 +499,11 @@ You can stop an Experience Composer by calling the `opentok.renders.stop(render_
495
499
  You can get information about Experience Composers by calling the `opentok.renders.find(render_id)`
496
500
  and `opentok.renders.list(options)` methods.
497
501
 
502
+ ### Working with Audio Connector
503
+
504
+ You can start an [Audio Connector](https://tokbox.com/developer/guides/audio-connector) WebSocket
505
+ by calling the `opentok.websocket.connect()` method.
506
+
498
507
  ## Samples
499
508
 
500
509
  There are three sample applications included in this repository. To get going as fast as possible, clone the whole
@@ -298,6 +298,35 @@ module OpenTok
298
298
  raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
299
299
  end
300
300
 
301
+ def connect_websocket(session_id, token, websocket_uri, opts)
302
+ opts.extend(HashExtensions)
303
+ body = { "sessionId" => session_id,
304
+ "token" => token,
305
+ "websocket" => { "uri" => websocket_uri }.merge(opts.camelize_keys!)
306
+ }
307
+
308
+ response = self.class.post("/v2/project/#{@api_key}/connect", {
309
+ :body => body.to_json,
310
+ :headers => generate_headers("Content-Type" => "application/json")
311
+ })
312
+ case response.code
313
+ when 200
314
+ response
315
+ when 400
316
+ raise ArgumentError, "One of the properties is invalid."
317
+ when 403
318
+ raise OpenTokAuthenticationError, "You are not authorized to start the call, check your authentication information."
319
+ when 409
320
+ raise OpenTokWebSocketError, "Conflict. Only routed sessions are allowed to initiate Connect Calls."
321
+ when 500
322
+ raise OpenTokError, "OpenTok server error."
323
+ else
324
+ raise OpenTokWebSocketError, "The WebSocket could not be connected"
325
+ end
326
+ rescue StandardError => e
327
+ raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
328
+ end
329
+
301
330
  def dial(session_id, token, sip_uri, opts)
302
331
  opts.extend(HashExtensions)
303
332
  body = { "sessionId" => session_id,
@@ -14,7 +14,8 @@ module OpenTok
14
14
  class OpenTokStreamLayoutError < OpenTokError; end
15
15
  # Defines errors raised when you perform Broadcast operations.
16
16
  class OpenTokBroadcastError < OpenTokError; end
17
+ # Defines errors raised when connecting to WebSocket URIs.
18
+ class OpenTokWebSocketError < OpenTokError; end
17
19
  # Defines errors raised when you perform Experience Composer render operations.
18
20
  class OpenTokRenderError < OpenTokError; end
19
-
20
21
  end
@@ -218,6 +218,11 @@ module OpenTok
218
218
  @connections ||= Connections.new client
219
219
  end
220
220
 
221
+ # A WebSocket object, which lets you connect OpenTok streams to a WebSocket URI.
222
+ def websocket
223
+ @websocket ||= WebSocket.new client
224
+ end
225
+
221
226
  protected
222
227
  def client
223
228
  @client ||= Client.new api_key, api_secret, api_url, ua_addendum, timeout_length: @timeout_length
@@ -1,4 +1,4 @@
1
1
  module OpenTok
2
2
  # @private
3
- VERSION = '4.5.1'
3
+ VERSION = '4.6.0'
4
4
  end
@@ -0,0 +1,37 @@
1
+ require "opentok/client"
2
+
3
+ # An object that lets you work with Audio Connector WebSocket connections.
4
+ module OpenTok
5
+ class WebSocket
6
+ # Starts an Audio Connector WebSocket connection to send audio from a Vonage Video API session to a WebSocket URI.
7
+ # See the {https://tokbox.com/developer/guides/audio-connector/ OpenTok Audio Connector developer guide}.
8
+ #
9
+ # @example
10
+ # opts = {
11
+ # "streams" => ["STREAMID1", "STREAMID2"],
12
+ # "headers" => {
13
+ # "key1" => "val1",
14
+ # "key2" => "val2"
15
+ # }
16
+ # }
17
+ # response = opentok.websocket.connect(SESSIONID, TOKEN, "ws://service.com/wsendpoint", opts)
18
+ #
19
+ # @param [String] session_id (required) The OpenTok session ID that includes the OpenTok streams you want to include in
20
+ # the WebSocket stream.
21
+ # @param [String] token (required) The OpenTok token to be used for the Audio Connector connection to the. OpenTok session.
22
+ # @param [String] websocket_uri (required) A publicly reachable WebSocket URI to be used for the destination of the audio
23
+ # stream (such as "wss://service.com/ws-endpoint").
24
+ # @param [Hash] opts (optional) A hash defining options for the Audio Connector WebSocket connection. For example:
25
+ # @option opts [Array] :streams (optional) An array of stream IDs for the OpenTok streams you want to include in the WebSocket stream.
26
+ # If you omit this property, all streams in the session will be included.
27
+ # @option opts [Hash] :headers (optional) A hash of key-value pairs of headers to be sent to your WebSocket server with each message,
28
+ # with a maximum length of 512 bytes.
29
+ def connect(session_id, token, websocket_uri, opts = {})
30
+ response = @client.connect_websocket(session_id, token, websocket_uri, opts)
31
+ end
32
+
33
+ def initialize(client)
34
+ @client = client
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.opentok.com/v2/project/123456/connect
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"sessionId":"SESSIONID","token":"TOKENID","websocket":{"uri":"ws://service.com/wsendpoint"}}'
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
+ Date:
26
+ - Sat, 06 Aug 2022 18:10:28 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Content-Length:
30
+ - '73'
31
+ Connection:
32
+ - keep-alive
33
+ body:
34
+ encoding: UTF-8
35
+ string: '{"id":"2299ba24-a6de-417c-88f7-28da54a441cf","connectionId":"833a7182-61a5-49d4-baae-c324b09953af"}'
36
+ recorded_at: Tue, 18 Apr 2017 10:17:40 GMT
37
+ recorded_with: VCR 6.0.0
@@ -0,0 +1,26 @@
1
+ require "opentok/opentok"
2
+ require "opentok/websocket"
3
+ require "opentok/version"
4
+ require "spec_helper"
5
+
6
+ describe OpenTok::WebSocket 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(:expiring_token) { "TOKENID" }
17
+ let(:websocket_uri) { "ws://service.com/wsendpoint" }
18
+ let(:opentok) { OpenTok::OpenTok.new api_key, api_secret }
19
+ let(:websocket) { opentok.websocket }
20
+ subject { websocket }
21
+
22
+ it "receives a valid response", :vcr => { :erb => { :version => OpenTok::VERSION + "-Ruby-Version-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"} } do
23
+ response = websocket.connect(session_id, expiring_token, websocket_uri)
24
+ expect(response).not_to be_nil
25
+ end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opentok
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.5.1
4
+ version: 4.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stijn Mathysen
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2022-10-28 00:00:00.000000000 Z
15
+ date: 2023-03-09 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler
@@ -206,6 +206,7 @@ files:
206
206
  - lib/opentok/streams.rb
207
207
  - lib/opentok/token_generator.rb
208
208
  - lib/opentok/version.rb
209
+ - lib/opentok/websocket.rb
209
210
  - opentok.gemspec
210
211
  - sample/Archiving/Gemfile
211
212
  - sample/Archiving/README.md
@@ -308,6 +309,7 @@ files:
308
309
  - spec/cassettes/OpenTok_Streams/get_all_streams_information.yml
309
310
  - spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml
310
311
  - spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml
312
+ - spec/cassettes/OpenTok_WebSocket/receives_a_valid_response.yml
311
313
  - spec/matchers/token.rb
312
314
  - spec/opentok/archives_spec.rb
313
315
  - spec/opentok/broadcasts_spec.rb
@@ -319,6 +321,7 @@ files:
319
321
  - spec/opentok/signal_spec.rb
320
322
  - spec/opentok/sip_spec.rb
321
323
  - spec/opentok/streams_spec.rb
324
+ - spec/opentok/websocket_spec.rb
322
325
  - spec/shared/opentok_generates_tokens.rb
323
326
  - spec/shared/session_generates_tokens.rb
324
327
  - spec/spec_helper.rb
@@ -418,6 +421,7 @@ test_files:
418
421
  - spec/cassettes/OpenTok_Streams/get_all_streams_information.yml
419
422
  - spec/cassettes/OpenTok_Streams/get_specific_stream_information.yml
420
423
  - spec/cassettes/OpenTok_Streams/layout_working_on_two_stream_list.yml
424
+ - spec/cassettes/OpenTok_WebSocket/receives_a_valid_response.yml
421
425
  - spec/matchers/token.rb
422
426
  - spec/opentok/archives_spec.rb
423
427
  - spec/opentok/broadcasts_spec.rb
@@ -429,6 +433,7 @@ test_files:
429
433
  - spec/opentok/signal_spec.rb
430
434
  - spec/opentok/sip_spec.rb
431
435
  - spec/opentok/streams_spec.rb
436
+ - spec/opentok/websocket_spec.rb
432
437
  - spec/shared/opentok_generates_tokens.rb
433
438
  - spec/shared/session_generates_tokens.rb
434
439
  - spec/spec_helper.rb