opentok 4.7.1 → 4.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/lib/opentok/archive.rb +2 -1
- data/lib/opentok/archives.rb +13 -4
- data/lib/opentok/captions.rb +61 -0
- data/lib/opentok/client.rb +268 -203
- data/lib/opentok/exceptions.rb +2 -0
- data/lib/opentok/opentok.rb +11 -5
- data/lib/opentok/version.rb +1 -1
- data/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_matching_multi_archive_tag_when_multiArchiveTag_is_specified.yml +1 -1
- data/spec/cassettes/OpenTok_Archives/should_create_an_archive_with_streamMode_set_to_specified_stream_mode_value.yml +52 -0
- data/spec/cassettes/OpenTok_Archives/should_create_an_archives_with_a_specified_multiArchiveTag.yml +1 -1
- data/spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_starting_captions.yml +44 -0
- data/spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_starting_captions_with_options.yml +44 -0
- data/spec/cassettes/OpenTok_Captions/receives_a_valid_response_when_stopping_captions.yml +44 -0
- data/spec/opentok/archives_spec.rb +9 -2
- data/spec/opentok/captions_spec.rb +44 -0
- metadata +14 -3
data/lib/opentok/client.rb
CHANGED
@@ -62,6 +62,8 @@ module OpenTok
|
|
62
62
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
63
63
|
end
|
64
64
|
|
65
|
+
# Archives methods
|
66
|
+
|
65
67
|
def start_archive(session_id, opts)
|
66
68
|
opts.extend(HashExtensions)
|
67
69
|
body = { "sessionId" => session_id }.merge(opts.camelize_keys!)
|
@@ -215,463 +217,526 @@ module OpenTok
|
|
215
217
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
216
218
|
end
|
217
219
|
|
218
|
-
|
219
|
-
|
220
|
+
# Broadcasts methods
|
221
|
+
|
222
|
+
def start_broadcast(session_id, opts)
|
223
|
+
opts.extend(HashExtensions)
|
224
|
+
body = { :sessionId => session_id }.merge(opts.camelize_keys!)
|
225
|
+
response = self.class.post("/v2/project/#{@api_key}/broadcast", {
|
226
|
+
:body => body.to_json,
|
220
227
|
:headers => generate_headers("Content-Type" => "application/json")
|
221
228
|
})
|
222
229
|
case response.code
|
223
|
-
when
|
230
|
+
when 200
|
224
231
|
response
|
225
232
|
when 400
|
226
|
-
raise
|
233
|
+
raise OpenTokBroadcastError, "The broadcast could not be started. The request was invalid or invalid layout options or exceeded the limit of five simultaneous RTMP streams."
|
227
234
|
when 403
|
228
|
-
raise OpenTokAuthenticationError, "
|
235
|
+
raise OpenTokAuthenticationError, "Authentication failed while starting a broadcast. API Key: #{@api_key}"
|
236
|
+
when 409
|
237
|
+
raise OpenTokBroadcastError, "The broadcast has already been started for this session."
|
238
|
+
when 500
|
239
|
+
raise OpenTokError, "OpenTok server error."
|
240
|
+
else
|
241
|
+
raise OpenTokBroadcastError, "The broadcast could not be started"
|
242
|
+
end
|
243
|
+
rescue StandardError => e
|
244
|
+
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
245
|
+
end
|
246
|
+
|
247
|
+
def get_broadcast(broadcast_id)
|
248
|
+
response = self.class.get("/v2/project/#{@api_key}/broadcast/#{broadcast_id}", {
|
249
|
+
:headers => generate_headers
|
250
|
+
})
|
251
|
+
case response.code
|
252
|
+
when 200
|
253
|
+
response
|
254
|
+
when 400
|
255
|
+
raise OpenTokBroadcastError, "The request was invalid."
|
256
|
+
when 403
|
257
|
+
raise OpenTokAuthenticationError, "Authentication failed while getting a broadcast. API Key: #{@api_key}"
|
229
258
|
when 404
|
230
|
-
raise
|
259
|
+
raise OpenTokBroadcastError, "No matching broadcast found (with the specified ID)"
|
260
|
+
when 500
|
261
|
+
raise OpenTokError, "OpenTok server error."
|
262
|
+
else
|
263
|
+
raise OpenTokBroadcastError, "Could not fetch broadcast information."
|
231
264
|
end
|
232
265
|
rescue StandardError => e
|
233
266
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
234
267
|
end
|
235
268
|
|
236
|
-
def
|
237
|
-
response = self.class.post("/v2/project/#{@api_key}/
|
238
|
-
:headers => generate_headers
|
269
|
+
def stop_broadcast(broadcast_id)
|
270
|
+
response = self.class.post("/v2/project/#{@api_key}/broadcast/#{broadcast_id}/stop", {
|
271
|
+
:headers => generate_headers
|
239
272
|
})
|
240
273
|
case response.code
|
241
274
|
when 200
|
242
275
|
response
|
243
276
|
when 400
|
244
|
-
raise
|
277
|
+
raise OpenTokBroadcastError, "The request was invalid."
|
245
278
|
when 403
|
246
|
-
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
279
|
+
raise OpenTokAuthenticationError, "Authentication failed while stopping a broadcast. API Key: #{@api_key}"
|
247
280
|
when 404
|
248
|
-
raise
|
281
|
+
raise OpenTokBroadcastError, "No matching broadcast found (with the specified ID) or it is already stopped"
|
282
|
+
when 500
|
283
|
+
raise OpenTokError, "OpenTok server error."
|
284
|
+
else
|
285
|
+
raise OpenTokBroadcastError, "The broadcast could not be stopped."
|
249
286
|
end
|
250
287
|
rescue StandardError => e
|
251
288
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
252
289
|
end
|
253
290
|
|
254
|
-
def
|
291
|
+
def list_broadcasts(offset, count, session_id)
|
292
|
+
query = Hash.new
|
293
|
+
query[:offset] = offset unless offset.nil?
|
294
|
+
query[:count] = count unless count.nil?
|
295
|
+
query[:sessionId] = session_id unless session_id.nil?
|
296
|
+
response = self.class.get("/v2/project/#{@api_key}/broadcast", {
|
297
|
+
:query => query.empty? ? nil : query,
|
298
|
+
:headers => generate_headers,
|
299
|
+
})
|
300
|
+
case response.code
|
301
|
+
when 200
|
302
|
+
response
|
303
|
+
when 403
|
304
|
+
raise OpenTokAuthenticationError,
|
305
|
+
"Authentication failed while retrieving broadcasts. API Key: #{@api_key}"
|
306
|
+
else
|
307
|
+
raise OpenTokBroadcastError, "The broadcasts could not be retrieved."
|
308
|
+
end
|
309
|
+
rescue StandardError => e
|
310
|
+
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
311
|
+
end
|
312
|
+
|
313
|
+
def layout_broadcast(broadcast_id, opts)
|
255
314
|
opts.extend(HashExtensions)
|
256
|
-
|
257
|
-
|
258
|
-
:body => body.to_json,
|
315
|
+
response = self.class.put("/v2/project/#{@api_key}/broadcast/#{broadcast_id}/layout", {
|
316
|
+
:body => opts.camelize_keys!.to_json,
|
259
317
|
:headers => generate_headers("Content-Type" => "application/json")
|
260
318
|
})
|
261
319
|
case response.code
|
262
320
|
when 200
|
263
321
|
response
|
264
322
|
when 400
|
265
|
-
raise
|
323
|
+
raise OpenTokBroadcastError, "The layout operation could not be performed. The request was invalid or invalid layout options."
|
266
324
|
when 403
|
267
|
-
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
268
|
-
when
|
269
|
-
raise
|
325
|
+
raise OpenTokAuthenticationError, "Authentication failed for broadcast layout. API Key: #{@api_key}"
|
326
|
+
when 500
|
327
|
+
raise OpenTokError, "OpenTok server error."
|
328
|
+
else
|
329
|
+
raise OpenTokBroadcastError, "The broadcast layout could not be performed."
|
270
330
|
end
|
271
331
|
rescue StandardError => e
|
272
332
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
273
333
|
end
|
274
334
|
|
275
|
-
def
|
335
|
+
def select_streams_for_broadcast(broadcast_id, opts)
|
276
336
|
opts.extend(HashExtensions)
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
:body => opts.camelize_keys!.to_json,
|
337
|
+
body = opts.camelize_keys!
|
338
|
+
response = self.class.patch("/v2/project/#{@api_key}/broadcast/#{broadcast_id}/streams", {
|
339
|
+
:body => body.to_json,
|
281
340
|
:headers => generate_headers("Content-Type" => "application/json")
|
282
341
|
})
|
283
342
|
case response.code
|
284
343
|
when 204
|
285
344
|
response
|
286
345
|
when 400
|
287
|
-
raise
|
346
|
+
raise OpenTokBroadcastError, "The request was invalid."
|
288
347
|
when 403
|
289
|
-
raise OpenTokAuthenticationError, "
|
348
|
+
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
290
349
|
when 404
|
291
|
-
raise
|
292
|
-
when
|
293
|
-
raise
|
350
|
+
raise OpenTokBroadcastError, "No matching broadcast found with the specified ID: #{broadcast_id}"
|
351
|
+
when 405
|
352
|
+
raise OpenTokBroadcastError, "The broadcast was started with streamMode set to 'auto', which does not support stream manipulation."
|
353
|
+
when 500
|
354
|
+
raise OpenTokError, "OpenTok server error."
|
294
355
|
else
|
295
|
-
raise
|
356
|
+
raise OpenTokBroadcastError, "The broadcast streams could not be updated."
|
296
357
|
end
|
297
358
|
rescue StandardError => e
|
298
359
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
299
360
|
end
|
300
361
|
|
301
|
-
|
302
|
-
|
362
|
+
# Captions methods
|
363
|
+
|
364
|
+
def start_live_captions(session_id, token, options)
|
365
|
+
options.extend(HashExtensions)
|
303
366
|
body = { "sessionId" => session_id,
|
304
367
|
"token" => token,
|
305
|
-
|
306
|
-
}
|
368
|
+
}.merge(options.camelize_keys!)
|
307
369
|
|
308
|
-
response = self.class.post("/v2/project/#{@api_key}/
|
370
|
+
response = self.class.post("/v2/project/#{@api_key}/captions", {
|
309
371
|
:body => body.to_json,
|
310
372
|
:headers => generate_headers("Content-Type" => "application/json")
|
311
373
|
})
|
312
374
|
case response.code
|
313
|
-
when
|
375
|
+
when 202
|
314
376
|
response
|
315
377
|
when 400
|
316
|
-
raise
|
378
|
+
raise OpenTokCaptionsError, "The request was invalid."
|
317
379
|
when 403
|
318
|
-
raise OpenTokAuthenticationError, "
|
380
|
+
raise OpenTokAuthenticationError, "Authentication failed while starting captions. API Key: #{@api_key}"
|
319
381
|
when 409
|
320
|
-
raise
|
382
|
+
raise OpenTokCaptionsError, "Live captions have already started for this OpenTok Session: #{session_id}"
|
321
383
|
when 500
|
322
384
|
raise OpenTokError, "OpenTok server error."
|
323
385
|
else
|
324
|
-
raise
|
386
|
+
raise OpenTokCaptionsError, "Captions could not be started"
|
325
387
|
end
|
326
388
|
rescue StandardError => e
|
327
389
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
328
390
|
end
|
329
391
|
|
330
|
-
def
|
331
|
-
|
332
|
-
body = { "sessionId" => session_id,
|
333
|
-
"token" => token,
|
334
|
-
"sip" => { "uri" => sip_uri }.merge(opts.camelize_keys!)
|
335
|
-
}
|
336
|
-
|
337
|
-
response = self.class.post("/v2/project/#{@api_key}/dial", {
|
338
|
-
:body => body.to_json,
|
392
|
+
def stop_live_captions(captions_id)
|
393
|
+
response = self.class.post("/v2/project/#{@api_key}/captions/#{captions_id}/stop", {
|
339
394
|
:headers => generate_headers("Content-Type" => "application/json")
|
340
395
|
})
|
341
396
|
case response.code
|
342
|
-
when
|
397
|
+
when 202
|
343
398
|
response
|
344
399
|
when 403
|
345
|
-
raise OpenTokAuthenticationError, "Authentication failed while
|
400
|
+
raise OpenTokAuthenticationError, "Authentication failed while starting captions. API Key: #{@api_key}"
|
346
401
|
when 404
|
347
|
-
raise
|
402
|
+
raise OpenTokCaptionsError, "No matching captions_id was found: #{captions_id}"
|
403
|
+
when 500
|
404
|
+
raise OpenTokError, "OpenTok server error."
|
348
405
|
else
|
349
|
-
raise
|
406
|
+
raise OpenTokCaptionsError, "Captions could not be stopped"
|
350
407
|
end
|
351
408
|
rescue StandardError => e
|
352
409
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
353
410
|
end
|
354
411
|
|
355
|
-
|
356
|
-
body = { "digits" => dtmf_digits }
|
412
|
+
# Connections methods
|
357
413
|
|
358
|
-
|
359
|
-
|
360
|
-
|
414
|
+
def forceDisconnect(session_id, connection_id)
|
415
|
+
response = self.class.delete("/v2/project/#{@api_key}/session/#{session_id}/connection/#{connection_id}", {
|
416
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
361
417
|
})
|
362
418
|
case response.code
|
363
|
-
when
|
419
|
+
when 204
|
364
420
|
response
|
365
421
|
when 400
|
366
|
-
raise ArgumentError, "
|
422
|
+
raise ArgumentError, "Force disconnect failed. Connection ID #{connection_id} or Session ID #{session_id} is invalid"
|
367
423
|
when 403
|
368
|
-
raise OpenTokAuthenticationError, "
|
424
|
+
raise OpenTokAuthenticationError, "You are not authorized to forceDisconnect, check your authentication credentials or token type is non-moderator"
|
369
425
|
when 404
|
370
|
-
raise
|
371
|
-
else
|
372
|
-
raise OpenTokError, "An error occurred when attempting to play DTMF digits to the session"
|
426
|
+
raise OpenTokConnectionError, "The client specified by the connection ID: #{connection_id} is not connected to the session"
|
373
427
|
end
|
374
428
|
rescue StandardError => e
|
375
429
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
376
430
|
end
|
377
431
|
|
378
|
-
|
379
|
-
body = { "digits" => dtmf_digits }
|
432
|
+
# Renders methods
|
380
433
|
|
381
|
-
|
382
|
-
|
383
|
-
|
434
|
+
def start_render(session_id, opts)
|
435
|
+
opts.extend(HashExtensions)
|
436
|
+
body = { :sessionId => session_id }.merge(opts.camelize_keys!)
|
437
|
+
response = self.class.post("/v2/project/#{@api_key}/render", {
|
438
|
+
:body => body.to_json,
|
439
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
384
440
|
})
|
385
441
|
case response.code
|
386
|
-
when
|
442
|
+
when 202
|
387
443
|
response
|
388
444
|
when 400
|
389
|
-
raise
|
445
|
+
raise OpenTokRenderError, "The render could not be started. The request was invalid."
|
390
446
|
when 403
|
391
|
-
raise OpenTokAuthenticationError, "Authentication failed
|
392
|
-
when
|
393
|
-
raise OpenTokError, "
|
447
|
+
raise OpenTokAuthenticationError, "Authentication failed while starting a render. API Key: #{@api_key}"
|
448
|
+
when 500
|
449
|
+
raise OpenTokError, "OpenTok server error."
|
394
450
|
else
|
395
|
-
raise
|
451
|
+
raise OpenTokRenderError, "The render could not be started"
|
396
452
|
end
|
397
453
|
rescue StandardError => e
|
398
454
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
399
455
|
end
|
400
456
|
|
401
|
-
def
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
headers: generate_headers('Content-Type' => 'application/json'))
|
457
|
+
def get_render(render_id)
|
458
|
+
response = self.class.get("/v2/project/#{@api_key}/render/#{render_id}", {
|
459
|
+
:headers => generate_headers
|
460
|
+
})
|
406
461
|
case response.code
|
407
462
|
when 200
|
408
463
|
response
|
409
464
|
when 400
|
410
|
-
raise
|
465
|
+
raise OpenTokRenderError, "The request was invalid."
|
411
466
|
when 403
|
412
|
-
raise OpenTokAuthenticationError,
|
413
|
-
when
|
414
|
-
raise
|
467
|
+
raise OpenTokAuthenticationError, "Authentication failed while getting a render. API Key: #{@api_key}"
|
468
|
+
when 404
|
469
|
+
raise OpenTokRenderError, "No matching render found (with the specified ID)"
|
415
470
|
when 500
|
416
|
-
raise OpenTokError,
|
471
|
+
raise OpenTokError, "OpenTok server error."
|
417
472
|
else
|
418
|
-
raise
|
473
|
+
raise OpenTokRenderError, "Could not fetch render information."
|
419
474
|
end
|
420
475
|
rescue StandardError => e
|
421
476
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
422
477
|
end
|
423
478
|
|
424
|
-
def
|
425
|
-
|
426
|
-
|
427
|
-
:body => opts.camelize_keys!.to_json,
|
428
|
-
:headers => generate_headers("Content-Type" => "application/json")
|
479
|
+
def stop_render(render_id)
|
480
|
+
response = self.class.delete("/v2/project/#{@api_key}/render/#{render_id}", {
|
481
|
+
:headers => generate_headers
|
429
482
|
})
|
430
483
|
case response.code
|
431
|
-
when
|
484
|
+
when 204
|
432
485
|
response
|
433
486
|
when 400
|
434
|
-
raise
|
487
|
+
raise OpenTokRenderError, "The request was invalid."
|
435
488
|
when 403
|
436
|
-
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
489
|
+
raise OpenTokAuthenticationError, "Authentication failed while stopping a render. API Key: #{@api_key}"
|
490
|
+
when 404
|
491
|
+
raise OpenTokRenderError, "No matching render found (with the specified ID) or it is already stopped"
|
437
492
|
when 500
|
438
|
-
raise OpenTokError, "
|
493
|
+
raise OpenTokError, "OpenTok server error."
|
439
494
|
else
|
440
|
-
raise
|
495
|
+
raise OpenTokRenderError, "The render could not be stopped."
|
441
496
|
end
|
442
497
|
rescue StandardError => e
|
443
498
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
444
499
|
end
|
445
500
|
|
446
|
-
def
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
501
|
+
def list_renders(offset, count)
|
502
|
+
query = Hash.new
|
503
|
+
query[:offset] = offset unless offset.nil?
|
504
|
+
query[:count] = count unless count.nil?
|
505
|
+
response = self.class.get("/v2/project/#{@api_key}/render", {
|
506
|
+
:query => query.empty? ? nil : query,
|
507
|
+
:headers => generate_headers,
|
452
508
|
})
|
453
509
|
case response.code
|
454
510
|
when 200
|
455
511
|
response
|
456
|
-
when 400
|
457
|
-
raise OpenTokBroadcastError, "The broadcast could not be started. The request was invalid or invalid layout options or exceeded the limit of five simultaneous RTMP streams."
|
458
512
|
when 403
|
459
|
-
raise OpenTokAuthenticationError,
|
460
|
-
|
461
|
-
raise OpenTokBroadcastError, "The broadcast has already been started for this session."
|
513
|
+
raise OpenTokAuthenticationError,
|
514
|
+
"Authentication failed while retrieving renders. API Key: #{@api_key}"
|
462
515
|
when 500
|
463
516
|
raise OpenTokError, "OpenTok server error."
|
464
517
|
else
|
465
|
-
raise
|
518
|
+
raise OpenTokRenderError, "The renders could not be retrieved."
|
466
519
|
end
|
467
520
|
rescue StandardError => e
|
468
521
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
469
522
|
end
|
470
523
|
|
471
|
-
|
472
|
-
|
473
|
-
|
524
|
+
# Sip methods
|
525
|
+
|
526
|
+
def dial(session_id, token, sip_uri, opts)
|
527
|
+
opts.extend(HashExtensions)
|
528
|
+
body = { "sessionId" => session_id,
|
529
|
+
"token" => token,
|
530
|
+
"sip" => { "uri" => sip_uri }.merge(opts.camelize_keys!)
|
531
|
+
}
|
532
|
+
|
533
|
+
response = self.class.post("/v2/project/#{@api_key}/dial", {
|
534
|
+
:body => body.to_json,
|
535
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
474
536
|
})
|
475
537
|
case response.code
|
476
538
|
when 200
|
477
539
|
response
|
478
|
-
when 400
|
479
|
-
raise OpenTokBroadcastError, "The request was invalid."
|
480
540
|
when 403
|
481
|
-
raise OpenTokAuthenticationError, "Authentication failed while
|
541
|
+
raise OpenTokAuthenticationError, "Authentication failed while dialing a SIP session. API Key: #{@api_key}"
|
482
542
|
when 404
|
483
|
-
raise
|
484
|
-
when 500
|
485
|
-
raise OpenTokError, "OpenTok server error."
|
543
|
+
raise OpenTokSipError, "The SIP session could not be dialed. The Session ID does not exist: #{session_id}"
|
486
544
|
else
|
487
|
-
raise
|
545
|
+
raise OpenTokSipError, "The SIP session could not be dialed"
|
488
546
|
end
|
489
547
|
rescue StandardError => e
|
490
548
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
491
549
|
end
|
492
550
|
|
493
|
-
def
|
494
|
-
|
495
|
-
|
551
|
+
def play_dtmf_to_connection(session_id, connection_id, dtmf_digits)
|
552
|
+
body = { "digits" => dtmf_digits }
|
553
|
+
|
554
|
+
response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/connection/#{connection_id}/play-dtmf", {
|
555
|
+
:body => body.to_json,
|
556
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
496
557
|
})
|
497
558
|
case response.code
|
498
559
|
when 200
|
499
560
|
response
|
500
561
|
when 400
|
501
|
-
raise
|
562
|
+
raise ArgumentError, "One of the properties — dtmf_digits #{dtmf_digits} or session_id #{session_id} — is invalid."
|
502
563
|
when 403
|
503
|
-
raise OpenTokAuthenticationError, "Authentication failed
|
564
|
+
raise OpenTokAuthenticationError, "Authentication failed. This can occur if you use an invalid OpenTok API key or an invalid JSON web token. API Key: #{@api_key}"
|
504
565
|
when 404
|
505
|
-
raise
|
506
|
-
when 500
|
507
|
-
raise OpenTokError, "OpenTok server error."
|
566
|
+
raise OpenTokError, "The specified session #{session_id} does not exist or the client specified by the #{connection_id} property is not connected to the session."
|
508
567
|
else
|
509
|
-
raise
|
568
|
+
raise OpenTokError, "An error occurred when attempting to play DTMF digits to the session"
|
510
569
|
end
|
511
570
|
rescue StandardError => e
|
512
571
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
513
572
|
end
|
514
573
|
|
515
|
-
def
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
:query => query.empty? ? nil : query,
|
522
|
-
:headers => generate_headers,
|
574
|
+
def play_dtmf_to_session(session_id, dtmf_digits)
|
575
|
+
body = { "digits" => dtmf_digits }
|
576
|
+
|
577
|
+
response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/play-dtmf", {
|
578
|
+
:body => body.to_json,
|
579
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
523
580
|
})
|
524
581
|
case response.code
|
525
582
|
when 200
|
526
583
|
response
|
584
|
+
when 400
|
585
|
+
raise ArgumentError, "One of the properties — dtmf_digits #{dtmf_digits} or session_id #{session_id} — is invalid."
|
527
586
|
when 403
|
528
|
-
raise OpenTokAuthenticationError,
|
529
|
-
|
587
|
+
raise OpenTokAuthenticationError, "Authentication failed. This can occur if you use an invalid OpenTok API key or an invalid JSON web token. API Key: #{@api_key}"
|
588
|
+
when 404
|
589
|
+
raise OpenTokError, "The specified session does not exist. Session ID: #{session_id}"
|
530
590
|
else
|
531
|
-
raise
|
591
|
+
raise OpenTokError, "An error occurred when attempting to play DTMF digits to the session"
|
532
592
|
end
|
533
593
|
rescue StandardError => e
|
534
594
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
535
595
|
end
|
536
596
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
597
|
+
# Streams methods
|
598
|
+
|
599
|
+
def info_stream(session_id, stream_id)
|
600
|
+
streamId = stream_id.to_s.empty? ? '' : "/#{stream_id}"
|
601
|
+
url = "/v2/project/#{@api_key}/session/#{session_id}/stream#{streamId}"
|
602
|
+
response = self.class.get(url,
|
603
|
+
headers: generate_headers('Content-Type' => 'application/json'))
|
543
604
|
case response.code
|
544
605
|
when 200
|
545
606
|
response
|
546
607
|
when 400
|
547
|
-
raise
|
608
|
+
raise ArgumentError, 'Invalid request. You did not pass in a valid session ID or stream ID.'
|
548
609
|
when 403
|
549
|
-
raise OpenTokAuthenticationError,
|
610
|
+
raise OpenTokAuthenticationError, 'Check your authentication credentials. You passed in an invalid OpenTok API key.'
|
611
|
+
when 408
|
612
|
+
raise ArgumentError, 'You passed in an invalid stream ID.'
|
550
613
|
when 500
|
551
|
-
raise OpenTokError,
|
614
|
+
raise OpenTokError, 'OpenTok server error.'
|
552
615
|
else
|
553
|
-
raise
|
616
|
+
raise OpenTokError, 'Could not fetch the stream information.'
|
554
617
|
end
|
555
618
|
rescue StandardError => e
|
556
619
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
557
620
|
end
|
558
621
|
|
559
|
-
def
|
622
|
+
def layout_streams(session_id, opts)
|
560
623
|
opts.extend(HashExtensions)
|
561
|
-
|
562
|
-
|
563
|
-
:body => body.to_json,
|
624
|
+
response = self.class.put("/v2/project/#{@api_key}/session/#{session_id}/stream", {
|
625
|
+
:body => opts.camelize_keys!.to_json,
|
564
626
|
:headers => generate_headers("Content-Type" => "application/json")
|
565
627
|
})
|
566
628
|
case response.code
|
567
|
-
when
|
629
|
+
when 200
|
568
630
|
response
|
569
631
|
when 400
|
570
|
-
raise
|
632
|
+
raise OpenTokStreamLayoutError, "Setting the layout failed. The request was invalid or invalid layout options were given."
|
571
633
|
when 403
|
572
634
|
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
573
|
-
when 404
|
574
|
-
raise OpenTokBroadcastError, "No matching broadcast found with the specified ID: #{broadcast_id}"
|
575
|
-
when 405
|
576
|
-
raise OpenTokBroadcastError, "The broadcast was started with streamMode set to 'auto', which does not support stream manipulation."
|
577
635
|
when 500
|
578
|
-
raise OpenTokError, "OpenTok server error."
|
636
|
+
raise OpenTokError, "Setting the layout failed. OpenTok server error."
|
579
637
|
else
|
580
|
-
raise
|
638
|
+
raise OpenTokStreamLayoutError, "Setting the layout failed."
|
581
639
|
end
|
582
640
|
rescue StandardError => e
|
583
641
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
584
642
|
end
|
585
643
|
|
586
|
-
def
|
587
|
-
|
588
|
-
body = { :sessionId => session_id }.merge(opts.camelize_keys!)
|
589
|
-
response = self.class.post("/v2/project/#{@api_key}/render", {
|
590
|
-
:body => body.to_json,
|
644
|
+
def force_mute_stream(session_id, stream_id)
|
645
|
+
response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/stream/#{stream_id}/mute", {
|
591
646
|
:headers => generate_headers("Content-Type" => "application/json")
|
592
647
|
})
|
593
648
|
case response.code
|
594
|
-
when
|
649
|
+
when 200
|
595
650
|
response
|
596
651
|
when 400
|
597
|
-
raise
|
652
|
+
raise ArgumentError, "Force mute failed. Stream ID #{stream_id} or Session ID #{session_id} is invalid"
|
598
653
|
when 403
|
599
|
-
raise OpenTokAuthenticationError, "Authentication failed
|
600
|
-
when
|
601
|
-
raise
|
602
|
-
else
|
603
|
-
raise OpenTokRenderError, "The render could not be started"
|
654
|
+
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
655
|
+
when 404
|
656
|
+
raise OpenTokConnectionError, "Either Stream ID #{stream_id} or Session ID #{session_id} is invalid"
|
604
657
|
end
|
605
658
|
rescue StandardError => e
|
606
659
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
607
660
|
end
|
608
661
|
|
609
|
-
def
|
610
|
-
|
611
|
-
|
662
|
+
def force_mute_session(session_id, opts)
|
663
|
+
opts.extend(HashExtensions)
|
664
|
+
body = opts.camelize_keys!
|
665
|
+
response = self.class.post("/v2/project/#{@api_key}/session/#{session_id}/mute", {
|
666
|
+
:body => body.to_json,
|
667
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
612
668
|
})
|
613
669
|
case response.code
|
614
670
|
when 200
|
615
671
|
response
|
616
672
|
when 400
|
617
|
-
raise
|
673
|
+
raise ArgumentError, "Force mute failed. The request could not be processed due to a bad request"
|
618
674
|
when 403
|
619
|
-
raise OpenTokAuthenticationError, "Authentication failed
|
675
|
+
raise OpenTokAuthenticationError, "Authentication failed. API Key: #{@api_key}"
|
620
676
|
when 404
|
621
|
-
raise
|
622
|
-
when 500
|
623
|
-
raise OpenTokError, "OpenTok server error."
|
624
|
-
else
|
625
|
-
raise OpenTokRenderError, "Could not fetch render information."
|
677
|
+
raise OpenTokConnectionError, "Session ID #{session_id} is invalid"
|
626
678
|
end
|
627
679
|
rescue StandardError => e
|
628
680
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
629
681
|
end
|
630
682
|
|
631
|
-
|
632
|
-
|
633
|
-
|
683
|
+
# Signals methods
|
684
|
+
|
685
|
+
def signal(session_id, connection_id, opts)
|
686
|
+
opts.extend(HashExtensions)
|
687
|
+
connectionPath = connection_id.to_s.empty? ? "" : "/connection/#{connection_id}"
|
688
|
+
url = "/v2/project/#{@api_key}/session/#{session_id}#{connectionPath}/signal"
|
689
|
+
response = self.class.post(url, {
|
690
|
+
:body => opts.camelize_keys!.to_json,
|
691
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
634
692
|
})
|
635
693
|
case response.code
|
636
694
|
when 204
|
637
695
|
response
|
638
696
|
when 400
|
639
|
-
raise
|
697
|
+
raise ArgumentError, "One of the signal properties — data, type, sessionId or connectionId — is invalid."
|
640
698
|
when 403
|
641
|
-
raise OpenTokAuthenticationError, "
|
699
|
+
raise OpenTokAuthenticationError, "You are not authorized to send the signal. Check your authentication credentials."
|
642
700
|
when 404
|
643
|
-
raise
|
644
|
-
when
|
645
|
-
raise OpenTokError, "
|
701
|
+
raise OpenTokError, "The client specified by the connectionId property is not connected to the session."
|
702
|
+
when 413
|
703
|
+
raise OpenTokError, "The type string exceeds the maximum length (128 bytes), or the data string exceeds the maximum size (8 kB)."
|
646
704
|
else
|
647
|
-
raise
|
705
|
+
raise OpenTokError, "The signal could not be send."
|
648
706
|
end
|
649
707
|
rescue StandardError => e
|
650
708
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
651
709
|
end
|
652
710
|
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
711
|
+
# WebSocket methods
|
712
|
+
|
713
|
+
def connect_websocket(session_id, token, websocket_uri, opts)
|
714
|
+
opts.extend(HashExtensions)
|
715
|
+
body = { "sessionId" => session_id,
|
716
|
+
"token" => token,
|
717
|
+
"websocket" => { "uri" => websocket_uri }.merge(opts.camelize_keys!)
|
718
|
+
}
|
719
|
+
|
720
|
+
response = self.class.post("/v2/project/#{@api_key}/connect", {
|
721
|
+
:body => body.to_json,
|
722
|
+
:headers => generate_headers("Content-Type" => "application/json")
|
660
723
|
})
|
661
724
|
case response.code
|
662
725
|
when 200
|
663
726
|
response
|
727
|
+
when 400
|
728
|
+
raise ArgumentError, "One of the properties is invalid."
|
664
729
|
when 403
|
665
|
-
raise OpenTokAuthenticationError,
|
666
|
-
|
730
|
+
raise OpenTokAuthenticationError, "You are not authorized to start the call, check your authentication information."
|
731
|
+
when 409
|
732
|
+
raise OpenTokWebSocketError, "Conflict. Only routed sessions are allowed to initiate Connect Calls."
|
667
733
|
when 500
|
668
734
|
raise OpenTokError, "OpenTok server error."
|
669
735
|
else
|
670
|
-
raise
|
736
|
+
raise OpenTokWebSocketError, "The WebSocket could not be connected"
|
671
737
|
end
|
672
738
|
rescue StandardError => e
|
673
739
|
raise OpenTokError, "Failed to connect to OpenTok. Response code: #{e.message}"
|
674
740
|
end
|
675
|
-
|
676
741
|
end
|
677
742
|
end
|