зеркало из https://github.com/mozilla/gecko-dev.git
Bug 834463: Corrected RTCConfiguration format. r=jst
This commit is contained in:
Родитель
0888abcc1f
Коммит
0995673625
|
@ -262,8 +262,8 @@ PeerConnection.prototype = {
|
|||
throw new Error("RTCPeerConnection constructor already called");
|
||||
}
|
||||
if (!rtcConfig) {
|
||||
// TODO(jib@mozilla.com): Hardcoded server pending Mozilla one. Bug 807494
|
||||
rtcConfig = [{ url: "stun:23.21.150.121" }];
|
||||
// TODO(jib@mozilla.com): Hardcoded Mozilla server. Final? Bug 807494
|
||||
rtcConfig = { "iceServers": [{ url: "stun:23.21.150.121" }] };
|
||||
}
|
||||
this._mustValidateRTCConfiguration(rtcConfig,
|
||||
"RTCPeerConnection constructor passed invalid RTCConfiguration");
|
||||
|
@ -330,8 +330,8 @@ PeerConnection.prototype = {
|
|||
/**
|
||||
* An RTCConfiguration looks like this:
|
||||
*
|
||||
* [ { url:"stun:23.21.150.121" },
|
||||
* { url:"turn:user@turn.example.org", credential:"myPassword"} ]
|
||||
* { "iceServers": [ { url:"stun:23.21.150.121" },
|
||||
* { url:"turn:user@turn.example.org", credential:"mypass"} ] }
|
||||
*
|
||||
* We check for basic structure and well-formed stun/turn urls, but not
|
||||
* validity of servers themselves, before passing along to C++.
|
||||
|
@ -355,18 +355,21 @@ PeerConnection.prototype = {
|
|||
}
|
||||
function mustValidateServer(server) {
|
||||
let url = nicerNewURI(server.url, errorMsg);
|
||||
if (!(url.scheme in { stun:1, stuns:1, turn:1 })) {
|
||||
if (!(url.scheme in { stun:1, stuns:1, turn:1, turns:1 })) {
|
||||
throw new Error (errorMsg + " - improper scheme: " + url.scheme);
|
||||
}
|
||||
if (server.credential && isObject(server.credential)) {
|
||||
throw new Error (errorMsg + " - invalid credential");
|
||||
}
|
||||
}
|
||||
if (!isArray(rtcConfig)) {
|
||||
if (!isObject(rtcConfig)) {
|
||||
throw new Error (errorMsg);
|
||||
}
|
||||
for (let i=0; i < rtcConfig.length; i++) {
|
||||
mustValidateServer (rtcConfig[i], errorMsg);
|
||||
if (!isArray(rtcConfig.iceServers)) {
|
||||
throw new Error (errorMsg + " - iceServers [] property not present");
|
||||
}
|
||||
for (let i=0; i < rtcConfig.iceServers.length; i++) {
|
||||
mustValidateServer (rtcConfig.iceServers[i], errorMsg);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -31,22 +31,25 @@ runTest(function () {
|
|||
ok(exception, "mozRTCPeerConnection({}) throws");
|
||||
exception = null;
|
||||
try { pcs = new mozRTCPeerConnection([]); } catch (e) { exception = e; }
|
||||
ok(!exception, "mozRTCPeerConnection([]) succeeds");
|
||||
ok(exception, "mozRTCPeerConnection([]) throws");
|
||||
exception = null;
|
||||
try { pc = new mozRTCPeerConnection([{}]); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection([{}]) throws");
|
||||
try { pc = new mozRTCPeerConnection({ iceServers: {}}); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection({ iceServers: {}}) throws");
|
||||
exception = null;
|
||||
try { pc = new mozRTCPeerConnection([{ url:"" }]); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection([{ url:\"\" }]) throws");
|
||||
try { pcs = new mozRTCPeerConnection({ iceServers: [] }); } catch (e) { exception = e; }
|
||||
ok(!exception, "mozRTCPeerConnection({ iceServers: [] }) succeeds");
|
||||
exception = null;
|
||||
try { pc = new mozRTCPeerConnection([{ url:"http:0.0.0.0" }]); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection([{ url:\"http:0.0.0.0\" }]) throws");
|
||||
try { pc = new mozRTCPeerConnection({ iceServers: [{ url:"" }] }); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection({ iceServers: [{ url:\"\" }] }) throws");
|
||||
exception = null;
|
||||
try { pcs = new mozRTCPeerConnection([{ url:"stun:0.0.0.0" }, { url:"stuns:x.net", foo:"" }, { url:"turn:user@x.org:42", credential:"p" }]); } catch (e) { exception = e; }
|
||||
ok(!exception, "mozRTCPeerConnection([{ url:\"stun:0.0.0.0\" }, { url:\"stuns:x.net\", foo:\"\" }, { url:\"turn:user@x.org:42\", credential:\"p\" }]) succeeds");
|
||||
try { pc = new mozRTCPeerConnection({ iceServers: [{ url:"http:0.0.0.0" }] }); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection({ iceServers: [{ url:\"http:0.0.0.0\" }] }) throws");
|
||||
exception = null;
|
||||
try { pc = new mozRTCPeerConnection([{ url:"stun:0.0.0.0", credential:{}}]); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection([{ url:\"stun:0.0.0.0\", credential:{}}]) throws");
|
||||
try { pcs = new mozRTCPeerConnection({ iceServers: [{ url:"stun:0.0.0.0" }, { url:"stuns:x.net", foo:"" }, { url: "turn:[::192.9.5.5]:42" }, { url:"turns:user@x.org:42", credential:"p" }] }); } catch (e) { exception = e; }
|
||||
ok(!exception, "mozRTCPeerConnection({ iceServers: [{ url:\"stun:0.0.0.0\" }, { url:\"stuns:x.net\", foo:\"\" }, { url: \"turn:[::192.9.5.5]:42\" }, { url:\"turns:user@x.org:42\", credential:\"p\" }] }) succeeds");
|
||||
exception = null;
|
||||
try { pc = new mozRTCPeerConnection({ iceServers: [{ url:"stun:0.0.0.0", credential:{}}] }); } catch (e) { exception = e; }
|
||||
ok(exception, "mozRTCPeerConnection({ iceServers: [{ url:\"stun:0.0.0.0\", credential:{}}] }) throws");
|
||||
pc = null;
|
||||
pcs = null;
|
||||
SimpleTest.finish();
|
||||
|
|
|
@ -320,8 +320,8 @@ Warn(JSContext* aCx, const nsCString& aMsg) {
|
|||
/**
|
||||
* In JS, an RTCConfiguration looks like this:
|
||||
*
|
||||
* [ { url:"stun:23.21.150.121" },
|
||||
* { url:"turn:user@turn.example.org", credential:"myPassword"} ]
|
||||
* { "iceServers": [ { url:"stun:23.21.150.121" },
|
||||
* { url:"turn:user@turn.example.org", credential:"mypass"} ] }
|
||||
*
|
||||
* This function converts an already-validated jsval that looks like the above
|
||||
* into an RTCConfiguration object.
|
||||
|
@ -335,8 +335,13 @@ PeerConnectionImpl::ConvertRTCConfiguration(const JS::Value& aSrc,
|
|||
if (!aSrc.isObject()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSObject& servers = aSrc.toObject();
|
||||
JSAutoCompartment ac(aCx, &servers);
|
||||
JSObject& config = aSrc.toObject();
|
||||
JSAutoCompartment ac(aCx, &config);
|
||||
JS::Value jsServers;
|
||||
if (!(JS_GetProperty(aCx, &config, "iceServers", &jsServers) && jsServers.isObject())) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JSObject& servers = jsServers.toObject();
|
||||
uint32_t len;
|
||||
if (!(IsArrayLike(aCx, &servers) && JS_GetArrayLength(aCx, &servers, &len))) {
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче