Bug 1247622 - Make RTCRtpSender.setParameters return a promise. r=jesup,smaug

MozReview-Commit-ID: 6lfmqpKevQl
This commit is contained in:
Jan-Ivar Bruaroey 2016-02-24 19:14:57 -05:00
parent 68e0e8b7f1
commit b8a437e28e
5 changed files with 45 additions and 57 deletions

View File

@ -1593,7 +1593,8 @@ RTCRtpSender.prototype = {
},
setParameters: function(parameters) {
return this._pc._setParameters(this, parameters);
return this._pc._win.Promise.resolve()
.then(() => this._pc._setParameters(this, parameters));
},
getParameters: function() {

View File

@ -26,15 +26,9 @@
.then(() => pc1.setRemoteDescription(pc2.localDescription))
.catch(generateErrorCallback());
function mustThrowWith(msg, reason, f) {
try {
f();
ok(false, msg + " must throw");
} catch (e) {
is(e.name, reason, msg + " must throw: " + e.message);
}
}
var mustRejectWith = (msg, reason, f) =>
f().then(() => ok(false, msg),
e => is(e.name, reason, msg));
var v1, v2;
runNetworkTest(function() {
@ -48,11 +42,11 @@
v1.srcObject = stream;
var sender = pc1.addTrack(stream.getVideoTracks()[0], stream);
mustThrowWith("scaleResolutionDownBy must be valid", "RangeError",
() => sender.setParameters({ encodings: [{ scaleResolutionDownBy: 0.5 } ] }));
sender.setParameters({ encodings: [{ maxBitrate: 60000,
scaleResolutionDownBy: 2 }] });
return mustRejectWith("Invalid scaleResolutionDownBy must reject", "RangeError",
() => sender.setParameters({ encodings:
[{ scaleResolutionDownBy: 0.5 } ] }))
.then(() => sender.setParameters({ encodings: [{ maxBitrate: 60000,
scaleResolutionDownBy: 2 }] }))
})
.then(() => new Promise(resolve => pc2.ontrack = e => resolve(e)))
.then(e => v2.srcObject = e.streams[0])

View File

@ -12,57 +12,52 @@ createHTML({
visible: true
});
function parameterstest(wrapper) {
var pc = wrapper._pc;
function parameterstest(pc) {
ok(pc.getSenders().length > 0, "have senders");
var sender = pc.getSenders()[0];
var testParameters = (params, errorName, errorMsg) => {
var compareParameters = (a, b) => {
var compareEncoding = (a, b) => {
var validateParameters = (a, b) => {
var validateEncoding = (a, b) => {
is(a.rid, b.rid || "", "same rid");
is(a.maxBitrate, b.maxBitrate, "same maxBitrate");
is(a.scaleResolutionDownBy, b.scaleResolutionDownBy,
"same scaleResolutionDownBy");
};
is(a.encodings.length, (b.encodings || []).length, "same encodings");
a.encodings.forEach((en, i) => compareEncoding(en, b.encodings[i]));
a.encodings.forEach((en, i) => validateEncoding(en, b.encodings[i]));
};
try {
sender.setParameters(params);
compareParameters(sender.getParameters(), params);
var before = JSON.stringify(sender.getParameters());
isnot(JSON.stringify(params), before, "starting condition");
var p = sender.setParameters(params)
.then(() => {
isnot(JSON.stringify(sender.getParameters()), before, "parameters changed");
validateParameters(sender.getParameters(), params);
is(null, errorName || null, "is success expected");
} catch (e) {
}, e => {
is(e.name, errorName, "correct error name");
is(e.message, errorMsg, "correct error message");
}
});
is(JSON.stringify(sender.getParameters()), before, "parameters not set yet");
return p;
};
testParameters({
encodings: [
{ rid: "foo", maxBitrate: 40000, scaleResolutionDownBy: 2 },
{ rid: "bar", maxBitrate: 10000, scaleResolutionDownBy: 4 },
]
});
testParameters({
encodings: [
{ maxBitrate: 10000, scaleResolutionDownBy: 4 },
]
});
testParameters({
encodings: [
{ maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 10000 },
]
}, "TypeError", "Missing rid");
testParameters({
encodings: [
{ rid: "foo", maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 10000 },
{ rid: "bar", maxBitrate: 20000 },
]
}, "TypeError", "Duplicate rid");
testParameters({});
return [
[{ encodings: [ { rid: "foo", maxBitrate: 40000, scaleResolutionDownBy: 2 },
{ rid: "bar", maxBitrate: 10000, scaleResolutionDownBy: 4 }]
}],
[{ encodings: [{ maxBitrate: 10000, scaleResolutionDownBy: 4 }]}],
[{ encodings: [{ maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 10000 }] }, "TypeError", "Missing rid"],
[{ encodings: [{ rid: "foo", maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 10000 },
{ rid: "bar", maxBitrate: 20000 }] }, "TypeError", "Duplicate rid"],
[{}]
].reduce((p, args) => p.then(() => testParameters.apply(this, args)),
Promise.resolve());
}
runNetworkTest(() => {
@ -74,7 +69,7 @@ runNetworkTest(() => {
// Test sender parameters.
test.chain.append([
function PC_LOCAL_SET_PARAMETERS(test) {
return parameterstest(test.pcLocal);
return parameterstest(test.pcLocal._pc);
}
]);

View File

@ -80,11 +80,9 @@
var sender = senders[0];
ok(sender.track, "Sender has a track");
sender.setParameters({
encodings: [
{ rid: "foo", maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 40000, scaleResolutionDownBy: 2 },
]
return sender.setParameters({
encodings: [{ rid: "foo", maxBitrate: 40000 },
{ rid: "bar", maxBitrate: 40000, scaleResolutionDownBy: 2 }]
});
}
]);

View File

@ -70,7 +70,7 @@ dictionary RTCRtpParameters {
JSImplementation="@mozilla.org/dom/rtpsender;1"]
interface RTCRtpSender {
readonly attribute MediaStreamTrack track;
void setParameters (optional RTCRtpParameters parameters);
Promise<void> setParameters (optional RTCRtpParameters parameters);
RTCRtpParameters getParameters();
Promise<void> replaceTrack(MediaStreamTrack track);
};