|
@@ -1,3 +1,4 @@
|
|
1
|
+/* global config, require, attachMediaStream, getUserMedia */
|
1
|
2
|
var RTCBrowserType = require("./RTCBrowserType");
|
2
|
3
|
var Resolutions = require("../../service/RTC/Resolutions");
|
3
|
4
|
var AdapterJS = require("./adapter.screenshare");
|
|
@@ -11,11 +12,9 @@ function getPreviousResolution(resolution) {
|
11
|
12
|
var order = Resolutions[resolution].order;
|
12
|
13
|
var res = null;
|
13
|
14
|
var resName = null;
|
14
|
|
- for(var i in Resolutions)
|
15
|
|
- {
|
|
15
|
+ for(var i in Resolutions) {
|
16
|
16
|
var tmp = Resolutions[i];
|
17
|
|
- if(res == null || (res.order < tmp.order && tmp.order < order))
|
18
|
|
- {
|
|
17
|
+ if(res == null || (res.order < tmp.order && tmp.order < order)) {
|
19
|
18
|
resName = i;
|
20
|
19
|
res = tmp;
|
21
|
20
|
}
|
|
@@ -23,19 +22,17 @@ function getPreviousResolution(resolution) {
|
23
|
22
|
return resName;
|
24
|
23
|
}
|
25
|
24
|
|
26
|
|
-function setResolutionConstraints(constraints, resolution, isAndroid)
|
27
|
|
-{
|
|
25
|
+function setResolutionConstraints(constraints, resolution, isAndroid) {
|
28
|
26
|
if (resolution && !constraints.video || isAndroid) {
|
29
|
|
- constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
|
|
27
|
+ // same behaviour as true
|
|
28
|
+ constraints.video = { mandatory: {}, optional: [] };
|
30
|
29
|
}
|
31
|
30
|
|
32
|
|
- if(Resolutions[resolution])
|
33
|
|
- {
|
|
31
|
+ if(Resolutions[resolution]) {
|
34
|
32
|
constraints.video.mandatory.minWidth = Resolutions[resolution].width;
|
35
|
33
|
constraints.video.mandatory.minHeight = Resolutions[resolution].height;
|
36
|
34
|
}
|
37
|
|
- else
|
38
|
|
- {
|
|
35
|
+ else {
|
39
|
36
|
if (isAndroid) {
|
40
|
37
|
constraints.video.mandatory.minWidth = 320;
|
41
|
38
|
constraints.video.mandatory.minHeight = 240;
|
|
@@ -44,9 +41,11 @@ function setResolutionConstraints(constraints, resolution, isAndroid)
|
44
|
41
|
}
|
45
|
42
|
|
46
|
43
|
if (constraints.video.mandatory.minWidth)
|
47
|
|
- constraints.video.mandatory.maxWidth = constraints.video.mandatory.minWidth;
|
|
44
|
+ constraints.video.mandatory.maxWidth =
|
|
45
|
+ constraints.video.mandatory.minWidth;
|
48
|
46
|
if (constraints.video.mandatory.minHeight)
|
49
|
|
- constraints.video.mandatory.maxHeight = constraints.video.mandatory.minHeight;
|
|
47
|
+ constraints.video.mandatory.maxHeight =
|
|
48
|
+ constraints.video.mandatory.minHeight;
|
50
|
49
|
}
|
51
|
50
|
|
52
|
51
|
function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid)
|
|
@@ -54,10 +53,12 @@ function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid
|
54
|
53
|
var constraints = {audio: false, video: false};
|
55
|
54
|
|
56
|
55
|
if (um.indexOf('video') >= 0) {
|
57
|
|
- constraints.video = { mandatory: {}, optional: [] };// same behaviour as true
|
|
56
|
+ // same behaviour as true
|
|
57
|
+ constraints.video = { mandatory: {}, optional: [] };
|
58
|
58
|
}
|
59
|
59
|
if (um.indexOf('audio') >= 0) {
|
60
|
|
- constraints.audio = { mandatory: {}, optional: []};// same behaviour as true
|
|
60
|
+ // same behaviour as true
|
|
61
|
+ constraints.audio = { mandatory: {}, optional: []};
|
61
|
62
|
}
|
62
|
63
|
if (um.indexOf('screen') >= 0) {
|
63
|
64
|
if (RTCBrowserType.isChrome()) {
|
|
@@ -126,13 +127,20 @@ function getConstraints(um, resolution, bandwidth, fps, desktopStream, isAndroid
|
126
|
127
|
setResolutionConstraints(constraints, resolution, isAndroid);
|
127
|
128
|
}
|
128
|
129
|
|
129
|
|
- if (bandwidth) { // doesn't work currently, see webrtc issue 1846
|
130
|
|
- if (!constraints.video) constraints.video = {mandatory: {}, optional: []};//same behaviour as true
|
|
130
|
+ if (bandwidth) {
|
|
131
|
+ if (!constraints.video) {
|
|
132
|
+ //same behaviour as true
|
|
133
|
+ constraints.video = {mandatory: {}, optional: []};
|
|
134
|
+ }
|
131
|
135
|
constraints.video.optional.push({bandwidth: bandwidth});
|
132
|
136
|
}
|
133
|
|
- if (fps) { // for some cameras it might be necessary to request 30fps
|
|
137
|
+ if (fps) {
|
|
138
|
+ // for some cameras it might be necessary to request 30fps
|
134
|
139
|
// so they choose 30fps mjpg over 10fps yuy2
|
135
|
|
- if (!constraints.video) constraints.video = {mandatory: {}, optional: []};// same behaviour as true;
|
|
140
|
+ if (!constraints.video) {
|
|
141
|
+ // same behaviour as true;
|
|
142
|
+ constraints.video = {mandatory: {}, optional: []};
|
|
143
|
+ }
|
136
|
144
|
constraints.video.mandatory.minFrameRate = fps;
|
137
|
145
|
}
|
138
|
146
|
|
|
@@ -167,8 +175,7 @@ function RTCUtils(RTCService, onTemasysPluginReady)
|
167
|
175
|
var id = stream.id;
|
168
|
176
|
if (!id) {
|
169
|
177
|
var tracks = stream.getVideoTracks();
|
170
|
|
- if (!tracks || tracks.length === 0)
|
171
|
|
- {
|
|
178
|
+ if (!tracks || tracks.length === 0) {
|
172
|
179
|
tracks = stream.getAudioTracks();
|
173
|
180
|
}
|
174
|
181
|
id = tracks[0].id;
|
|
@@ -258,7 +265,6 @@ function RTCUtils(RTCService, onTemasysPluginReady)
|
258
|
265
|
console.warn("Attempt to get video SRC of null element");
|
259
|
266
|
return null;
|
260
|
267
|
}
|
261
|
|
- var src = null;
|
262
|
268
|
var children = element.children;
|
263
|
269
|
for (var i = 0; i !== children.length; ++i) {
|
264
|
270
|
if (children[i].name === 'streamId') {
|
|
@@ -293,8 +299,7 @@ function RTCUtils(RTCService, onTemasysPluginReady)
|
293
|
299
|
|
294
|
300
|
RTCUtils.prototype.getUserMediaWithConstraints = function(
|
295
|
301
|
um, success_callback, failure_callback, resolution,bandwidth, fps,
|
296
|
|
- desktopStream)
|
297
|
|
-{
|
|
302
|
+ desktopStream) {
|
298
|
303
|
currentResolution = resolution;
|
299
|
304
|
// Check if we are running on Android device
|
300
|
305
|
var isAndroid = navigator.userAgent.indexOf('Android') != -1;
|
|
@@ -331,16 +336,14 @@ RTCUtils.prototype.getUserMediaWithConstraints = function(
|
331
|
336
|
|
332
|
337
|
RTCUtils.prototype.setAvailableDevices = function (um, available) {
|
333
|
338
|
var devices = {};
|
334
|
|
- if(um.indexOf("video") != -1)
|
335
|
|
- {
|
|
339
|
+ if(um.indexOf("video") != -1) {
|
336
|
340
|
devices.video = available;
|
337
|
341
|
}
|
338
|
|
- if(um.indexOf("audio") != -1)
|
339
|
|
- {
|
|
342
|
+ if(um.indexOf("audio") != -1) {
|
340
|
343
|
devices.audio = available;
|
341
|
344
|
}
|
342
|
345
|
this.service.setDeviceAvailability(devices);
|
343
|
|
-}
|
|
346
|
+};
|
344
|
347
|
|
345
|
348
|
/**
|
346
|
349
|
* We ask for audio and video combined stream in order to get permissions and
|
|
@@ -366,8 +369,7 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions =
|
366
|
369
|
|
367
|
370
|
|
368
|
371
|
if(usageOptions)
|
369
|
|
- for(var i = 0; i < devices.length; i++)
|
370
|
|
- {
|
|
372
|
+ for(var i = 0; i < devices.length; i++) {
|
371
|
373
|
var device = devices[i];
|
372
|
374
|
if(usageOptions[device] === true)
|
373
|
375
|
newDevices.push(device);
|
|
@@ -375,8 +377,7 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions =
|
375
|
377
|
else
|
376
|
378
|
newDevices = devices;
|
377
|
379
|
|
378
|
|
- if(newDevices.length === 0)
|
379
|
|
- {
|
|
380
|
+ if(newDevices.length === 0) {
|
380
|
381
|
successCallback();
|
381
|
382
|
return;
|
382
|
383
|
}
|
|
@@ -437,7 +438,6 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions =
|
437
|
438
|
},
|
438
|
439
|
config.resolution || '360');
|
439
|
440
|
}
|
440
|
|
-
|
441
|
441
|
};
|
442
|
442
|
|
443
|
443
|
RTCUtils.prototype.successCallback = function (stream, usageOptions) {
|
|
@@ -467,8 +467,7 @@ RTCUtils.prototype.errorCallback = function (error) {
|
467
|
467
|
return self.errorCallback(error);
|
468
|
468
|
}, resolution);
|
469
|
469
|
}
|
470
|
|
- else
|
471
|
|
- {
|
|
470
|
+ else {
|
472
|
471
|
self.getUserMediaWithConstraints(
|
473
|
472
|
['audio'],
|
474
|
473
|
function (stream) {
|
|
@@ -481,11 +480,9 @@ RTCUtils.prototype.errorCallback = function (error) {
|
481
|
480
|
}
|
482
|
481
|
);
|
483
|
482
|
}
|
|
483
|
+};
|
484
|
484
|
|
485
|
|
-}
|
486
|
|
-
|
487
|
|
-RTCUtils.prototype.handleLocalStream = function(stream, usageOptions)
|
488
|
|
-{
|
|
485
|
+RTCUtils.prototype.handleLocalStream = function(stream, usageOptions) {
|
489
|
486
|
// If this is FF, the stream parameter is *not* a MediaStream object, it's
|
490
|
487
|
// an object with two properties: audioStream, videoStream.
|
491
|
488
|
var audioStream, videoStream;
|
|
@@ -538,8 +535,8 @@ function DummyMediaStream(id) {
|
538
|
535
|
this.id = id;
|
539
|
536
|
this.label = id;
|
540
|
537
|
this.stop = function() { };
|
541
|
|
- this.getAudioTracks = function() { return []; }
|
542
|
|
- this.getVideoTracks = function() { return []; }
|
|
538
|
+ this.getAudioTracks = function() { return []; };
|
|
539
|
+ this.getVideoTracks = function() { return []; };
|
543
|
540
|
}
|
544
|
541
|
|
545
|
542
|
RTCUtils.prototype.createStream = function(stream, isVideo) {
|
|
@@ -549,7 +546,7 @@ RTCUtils.prototype.createStream = function(stream, isVideo) {
|
549
|
546
|
if (newStream) {
|
550
|
547
|
var tracks = (isVideo ? stream.getVideoTracks() : stream.getAudioTracks());
|
551
|
548
|
|
552
|
|
- for (i = 0; i < tracks.length; i++) {
|
|
549
|
+ for (var i = 0; i < tracks.length; i++) {
|
553
|
550
|
newStream.addTrack(tracks[i]);
|
554
|
551
|
}
|
555
|
552
|
}
|
|
@@ -560,7 +557,8 @@ RTCUtils.prototype.createStream = function(stream, isVideo) {
|
560
|
557
|
if (stream) {
|
561
|
558
|
newStream = stream;
|
562
|
559
|
} else {
|
563
|
|
- newStream = new DummyMediaStream(isVideo ? "dummyVideo" : "dummyAudio");
|
|
560
|
+ newStream =
|
|
561
|
+ new DummyMediaStream(isVideo ? "dummyVideo" : "dummyAudio");
|
564
|
562
|
}
|
565
|
563
|
}
|
566
|
564
|
|