Skip to content

Commit ce0456d

Browse files
Fix device selection (webrtc#338)
1 parent 64a277e commit ce0456d

File tree

4 files changed

+55
-38
lines changed

4 files changed

+55
-38
lines changed

src/js/bandwidth_test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,8 @@ function VideoBandwidthTest(test) {
146146
this.constraints = {
147147
audio: false,
148148
video: {
149-
optional: [
150-
{minWidth: 1280},
151-
{minHeight: 720}
152-
]
149+
minWidth: 1280,
150+
minHeight: 720
153151
}
154152
};
155153
}

src/js/camresolutionstest.js

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,31 +68,32 @@ CamResolutionsTest.prototype = {
6868
height: {exact: resolution[1]}
6969
}
7070
};
71-
navigator.mediaDevices.getUserMedia(constraints)
72-
.then(function(stream) {
73-
// Do not check actual video frames when more than one resolution is
74-
// provided.
75-
if (this.resolutions.length > 1) {
76-
this.test.reportSuccess('Supported: ' + resolution[0] + 'x' +
77-
resolution[1]);
78-
stream.getTracks().forEach(function(track) {
79-
track.stop();
80-
});
81-
this.maybeContinueGetUserMedia();
82-
} else {
83-
this.collectAndAnalyzeStats_(stream, resolution);
84-
}
85-
}.bind(this))
86-
.catch(function(error) {
87-
if (this.resolutions.length > 1) {
88-
this.test.reportInfo(resolution[0] + 'x' + resolution[1] +
71+
72+
doGetUserMedia(constraints, onSuccess.bind(this), onFail.bind(this));
73+
74+
function onSuccess(stream) {
75+
if (this.resolutions.length > 1) {
76+
this.test.reportSuccess('Supported: ' + resolution[0] + 'x' +
77+
resolution[1]);
78+
stream.getTracks().forEach(function(track) {
79+
track.stop();
80+
});
81+
this.maybeContinueGetUserMedia();
82+
} else {
83+
this.collectAndAnalyzeStats_(stream, resolution);
84+
}
85+
};
86+
87+
function onFail(error) {
88+
if (this.resolutions.length > 1) {
89+
this.test.reportInfo(resolution[0] + 'x' + resolution[1] +
8990
' not supported');
90-
} else {
91-
this.test.reportError('getUserMedia failed with error: ' +
92-
error.name);
93-
}
94-
this.maybeContinueGetUserMedia();
95-
}.bind(this));
91+
} else {
92+
this.test.reportError('getUserMedia failed with error: ' +
93+
error);
94+
}
95+
this.maybeContinueGetUserMedia();
96+
};
9697
},
9798

9899
maybeContinueGetUserMedia: function() {
@@ -102,6 +103,31 @@ CamResolutionsTest.prototype = {
102103
}
103104
this.startGetUserMedia(this.resolutions[this.currentResolution++]);
104105
},
106+
107+
onSuccess: function(stream) {
108+
if (this.resolutions.length > 1) {
109+
this.test.reportSuccess('Supported: ' + resolution[0] + 'x' +
110+
resolution[1]);
111+
stream.getTracks().forEach(function(track) {
112+
track.stop();
113+
});
114+
this.maybeContinueGetUserMedia();
115+
} else {
116+
this.collectAndAnalyzeStats_(stream, resolution);
117+
}
118+
},
119+
120+
onFail: function(error) {
121+
if (this.resolutions.length > 1) {
122+
this.test.reportInfo(resolution[0] + 'x' + resolution[1] +
123+
' not supported');
124+
} else {
125+
this.test.reportError('getUserMedia failed with error: ' +
126+
error.name);
127+
}
128+
this.maybeContinueGetUserMedia();
129+
},
130+
105131

106132
collectAndAnalyzeStats_: function(stream, resolution) {
107133
var tracks = stream.getVideoTracks();

src/js/mictest.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ function MicTest(test) {
2121
// Turning off echoCancellation constraint enables stereo input.
2222
this.constraints = {
2323
audio: {
24-
optional: [
25-
{echoCancellation: false}
26-
]
24+
echoCancellation: false
2725
}
2826
};
2927

src/ui/testrtc-main.html

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,8 @@ <h3>STUN</h3>
206206
},
207207

208208
appendSourceId: function(id, type, constraints) {
209-
if (constraints[type] === true) {
210-
constraints[type] = {optional: [{sourceId: id}]};
211-
} else if (typeof constraints[type] === 'object') {
212-
if (typeof constraints[type].optional === 'undefined') {
213-
constraints[type].optional = [];
214-
}
215-
constraints[type].optional.push({sourceId: id});
209+
if (constraints[type] !== false && typeof(constraints[type]) !== 'undefined') {
210+
constraints[type]['deviceId'] = id;
216211
}
217212
},
218213

0 commit comments

Comments
 (0)