|
@@ -135,7 +135,7 @@ function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid
|
135
|
135
|
}
|
136
|
136
|
|
137
|
137
|
//Options parameter is to pass config options. Currently uses only "useIPv6".
|
138
|
|
-function RTCUtils(RTCService, onTemasysPluginReady, options)
|
|
138
|
+function RTCUtils(RTCService, onTemasysPluginReady)
|
139
|
139
|
{
|
140
|
140
|
var self = this;
|
141
|
141
|
this.service = RTCService;
|
|
@@ -209,7 +209,7 @@ function RTCUtils(RTCService, onTemasysPluginReady, options)
|
209
|
209
|
};
|
210
|
210
|
// DTLS should now be enabled by default but..
|
211
|
211
|
this.pc_constraints = {'optional': [{'DtlsSrtpKeyAgreement': 'true'}]};
|
212
|
|
- if (options.useIPv6) {
|
|
212
|
+ if (this.service.options.useIPv6) {
|
213
|
213
|
// https://code.google.com/p/webrtc/issues/detail?id=2828
|
214
|
214
|
this.pc_constraints.optional.push({googIPv6: true});
|
215
|
215
|
}
|
|
@@ -340,94 +340,93 @@ RTCUtils.prototype.setAvailableDevices = function (um, available) {
|
340
|
340
|
* not to ask twice.
|
341
|
341
|
*/
|
342
|
342
|
RTCUtils.prototype.obtainAudioAndVideoPermissions =
|
343
|
|
- function(devices, callback, usageOptions)
|
|
343
|
+ function(devices, usageOptions, resolution)
|
344
|
344
|
{
|
345
|
345
|
var self = this;
|
346
|
346
|
// Get AV
|
347
|
347
|
|
348
|
|
- var successCallback = function (stream) {
|
349
|
|
- if(callback)
|
350
|
|
- callback(stream, usageOptions);
|
351
|
|
- else
|
352
|
|
- self.successCallback(stream, usageOptions);
|
353
|
|
- };
|
|
348
|
+ return new Promise(function(resolve, reject) {
|
|
349
|
+ var successCallback = function (stream) {
|
|
350
|
+ resolve(self.successCallback(stream, usageOptions));
|
|
351
|
+ };
|
354
|
352
|
|
355
|
|
- if(!devices)
|
356
|
|
- devices = ['audio', 'video'];
|
|
353
|
+ if (!devices)
|
|
354
|
+ devices = ['audio', 'video'];
|
357
|
355
|
|
358
|
|
- var newDevices = [];
|
|
356
|
+ var newDevices = [];
|
359
|
357
|
|
360
|
358
|
|
361
|
|
- if(usageOptions)
|
362
|
|
- for(var i = 0; i < devices.length; i++) {
|
363
|
|
- var device = devices[i];
|
364
|
|
- if(usageOptions[device] === true)
|
365
|
|
- newDevices.push(device);
|
366
|
|
- }
|
367
|
|
- else
|
368
|
|
- newDevices = devices;
|
|
359
|
+ if (usageOptions)
|
|
360
|
+ for (var i = 0; i < devices.length; i++) {
|
|
361
|
+ var device = devices[i];
|
|
362
|
+ if (usageOptions[device] === true)
|
|
363
|
+ newDevices.push(device);
|
|
364
|
+ }
|
|
365
|
+ else
|
|
366
|
+ newDevices = devices;
|
369
|
367
|
|
370
|
|
- if(newDevices.length === 0) {
|
371
|
|
- successCallback();
|
372
|
|
- return;
|
373
|
|
- }
|
|
368
|
+ if (newDevices.length === 0) {
|
|
369
|
+ successCallback();
|
|
370
|
+ return;
|
|
371
|
+ }
|
374
|
372
|
|
375
|
|
- if (RTCBrowserType.isFirefox() || RTCBrowserType.isTemasysPluginUsed()) {
|
376
|
|
-
|
377
|
|
- // With FF/IE we can't split the stream into audio and video because FF
|
378
|
|
- // doesn't support media stream constructors. So, we need to get the
|
379
|
|
- // audio stream separately from the video stream using two distinct GUM
|
380
|
|
- // calls. Not very user friendly :-( but we don't have many other
|
381
|
|
- // options neither.
|
382
|
|
- //
|
383
|
|
- // Note that we pack those 2 streams in a single object and pass it to
|
384
|
|
- // the successCallback method.
|
385
|
|
- var obtainVideo = function (audioStream) {
|
386
|
|
- self.getUserMediaWithConstraints(
|
387
|
|
- ['video'],
|
388
|
|
- function (videoStream) {
|
389
|
|
- return successCallback({
|
390
|
|
- audioStream: audioStream,
|
391
|
|
- videoStream: videoStream
|
392
|
|
- });
|
|
373
|
+ if (RTCBrowserType.isFirefox() || RTCBrowserType.isTemasysPluginUsed()) {
|
|
374
|
+
|
|
375
|
+ // With FF/IE we can't split the stream into audio and video because FF
|
|
376
|
+ // doesn't support media stream constructors. So, we need to get the
|
|
377
|
+ // audio stream separately from the video stream using two distinct GUM
|
|
378
|
+ // calls. Not very user friendly :-( but we don't have many other
|
|
379
|
+ // options neither.
|
|
380
|
+ //
|
|
381
|
+ // Note that we pack those 2 streams in a single object and pass it to
|
|
382
|
+ // the successCallback method.
|
|
383
|
+ var obtainVideo = function (audioStream) {
|
|
384
|
+ self.getUserMediaWithConstraints(
|
|
385
|
+ ['video'],
|
|
386
|
+ function (videoStream) {
|
|
387
|
+ return successCallback({
|
|
388
|
+ audioStream: audioStream,
|
|
389
|
+ videoStream: videoStream
|
|
390
|
+ });
|
|
391
|
+ },
|
|
392
|
+ function (error) {
|
|
393
|
+ console.error(
|
|
394
|
+ 'failed to obtain video stream - stop', error);
|
|
395
|
+ self.errorCallback(error, resolve);
|
|
396
|
+ },
|
|
397
|
+ config.resolution || '360');
|
|
398
|
+ };
|
|
399
|
+ var obtainAudio = function () {
|
|
400
|
+ self.getUserMediaWithConstraints(
|
|
401
|
+ ['audio'],
|
|
402
|
+ function (audioStream) {
|
|
403
|
+ if (newDevices.indexOf('video') !== -1)
|
|
404
|
+ obtainVideo(audioStream);
|
|
405
|
+ },
|
|
406
|
+ function (error) {
|
|
407
|
+ console.error(
|
|
408
|
+ 'failed to obtain audio stream - stop', error);
|
|
409
|
+ self.errorCallback(error, resolve);
|
|
410
|
+ }
|
|
411
|
+ );
|
|
412
|
+ };
|
|
413
|
+ if (newDevices.indexOf('audio') !== -1) {
|
|
414
|
+ obtainAudio();
|
|
415
|
+ } else {
|
|
416
|
+ obtainVideo(null);
|
|
417
|
+ }
|
|
418
|
+ } else {
|
|
419
|
+ this.getUserMediaWithConstraints(
|
|
420
|
+ newDevices,
|
|
421
|
+ function (stream) {
|
|
422
|
+ successCallback(stream);
|
393
|
423
|
},
|
394
|
424
|
function (error) {
|
395
|
|
- console.error(
|
396
|
|
- 'failed to obtain video stream - stop', error);
|
397
|
|
- self.errorCallback(error);
|
398
|
|
- },
|
399
|
|
- config.resolution || '360');
|
400
|
|
- };
|
401
|
|
- var obtainAudio = function () {
|
402
|
|
- self.getUserMediaWithConstraints(
|
403
|
|
- ['audio'],
|
404
|
|
- function (audioStream) {
|
405
|
|
- if (newDevices.indexOf('video') !== -1)
|
406
|
|
- obtainVideo(audioStream);
|
|
425
|
+ self.errorCallback(error, resolve);
|
407
|
426
|
},
|
408
|
|
- function (error) {
|
409
|
|
- console.error(
|
410
|
|
- 'failed to obtain audio stream - stop', error);
|
411
|
|
- self.errorCallback(error);
|
412
|
|
- }
|
413
|
|
- );
|
414
|
|
- };
|
415
|
|
- if (newDevices.indexOf('audio') !== -1) {
|
416
|
|
- obtainAudio();
|
417
|
|
- } else {
|
418
|
|
- obtainVideo(null);
|
|
427
|
+ resolution || '360');
|
419
|
428
|
}
|
420
|
|
- } else {
|
421
|
|
- this.getUserMediaWithConstraints(
|
422
|
|
- newDevices,
|
423
|
|
- function (stream) {
|
424
|
|
- successCallback(stream);
|
425
|
|
- },
|
426
|
|
- function (error) {
|
427
|
|
- self.errorCallback(error);
|
428
|
|
- },
|
429
|
|
- config.resolution || '360');
|
430
|
|
- }
|
|
429
|
+ }.bind(this));
|
431
|
430
|
};
|
432
|
431
|
|
433
|
432
|
RTCUtils.prototype.successCallback = function (stream, usageOptions) {
|
|
@@ -439,7 +438,7 @@ RTCUtils.prototype.successCallback = function (stream, usageOptions) {
|
439
|
438
|
return this.handleLocalStream(stream, usageOptions);
|
440
|
439
|
};
|
441
|
440
|
|
442
|
|
-RTCUtils.prototype.errorCallback = function (error) {
|
|
441
|
+RTCUtils.prototype.errorCallback = function (error, resolve) {
|
443
|
442
|
var self = this;
|
444
|
443
|
console.error('failed to obtain audio/video stream - trying audio only', error);
|
445
|
444
|
var resolution = getPreviousResolution(currentResolution);
|
|
@@ -452,7 +451,7 @@ RTCUtils.prototype.errorCallback = function (error) {
|
452
|
451
|
{
|
453
|
452
|
self.getUserMediaWithConstraints(['audio', 'video'],
|
454
|
453
|
function (stream) {
|
455
|
|
- return self.successCallback(stream);
|
|
454
|
+ resolve(self.successCallback(stream));
|
456
|
455
|
}, function (error) {
|
457
|
456
|
return self.errorCallback(error);
|
458
|
457
|
}, resolution);
|
|
@@ -461,12 +460,12 @@ RTCUtils.prototype.errorCallback = function (error) {
|
461
|
460
|
self.getUserMediaWithConstraints(
|
462
|
461
|
['audio'],
|
463
|
462
|
function (stream) {
|
464
|
|
- return self.successCallback(stream);
|
|
463
|
+ resolve(self.successCallback(stream));
|
465
|
464
|
},
|
466
|
465
|
function (error) {
|
467
|
466
|
console.error('failed to obtain audio/video stream - stop',
|
468
|
467
|
error);
|
469
|
|
- return self.successCallback(null);
|
|
468
|
+ resolve(self.successCallback(null));
|
470
|
469
|
}
|
471
|
470
|
);
|
472
|
471
|
}
|