Bug 834463: Corrected RTCConfiguration format. r=jst

This commit is contained in:
Jan-Ivar Bruaroey 2013-01-24 17:58:29 -05:00
Родитель 0888abcc1f
Коммит 0995673625
3 изменённых файлов: 34 добавлений и 23 удалений

Просмотреть файл

@ -262,8 +262,8 @@ PeerConnection.prototype = {
throw new Error("RTCPeerConnection constructor already called"); throw new Error("RTCPeerConnection constructor already called");
} }
if (!rtcConfig) { if (!rtcConfig) {
// TODO(jib@mozilla.com): Hardcoded server pending Mozilla one. Bug 807494 // TODO(jib@mozilla.com): Hardcoded Mozilla server. Final? Bug 807494
rtcConfig = [{ url: "stun:23.21.150.121" }]; rtcConfig = { "iceServers": [{ url: "stun:23.21.150.121" }] };
} }
this._mustValidateRTCConfiguration(rtcConfig, this._mustValidateRTCConfiguration(rtcConfig,
"RTCPeerConnection constructor passed invalid RTCConfiguration"); "RTCPeerConnection constructor passed invalid RTCConfiguration");
@ -330,8 +330,8 @@ PeerConnection.prototype = {
/** /**
* An RTCConfiguration looks like this: * An RTCConfiguration looks like this:
* *
* [ { url:"stun:23.21.150.121" }, * { "iceServers": [ { url:"stun:23.21.150.121" },
* { url:"turn:user@turn.example.org", credential:"myPassword"} ] * { url:"turn:user@turn.example.org", credential:"mypass"} ] }
* *
* We check for basic structure and well-formed stun/turn urls, but not * We check for basic structure and well-formed stun/turn urls, but not
* validity of servers themselves, before passing along to C++. * validity of servers themselves, before passing along to C++.
@ -355,18 +355,21 @@ PeerConnection.prototype = {
} }
function mustValidateServer(server) { function mustValidateServer(server) {
let url = nicerNewURI(server.url, errorMsg); 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); throw new Error (errorMsg + " - improper scheme: " + url.scheme);
} }
if (server.credential && isObject(server.credential)) { if (server.credential && isObject(server.credential)) {
throw new Error (errorMsg + " - invalid credential"); throw new Error (errorMsg + " - invalid credential");
} }
} }
if (!isArray(rtcConfig)) { if (!isObject(rtcConfig)) {
throw new Error (errorMsg); throw new Error (errorMsg);
} }
for (let i=0; i < rtcConfig.length; i++) { if (!isArray(rtcConfig.iceServers)) {
mustValidateServer (rtcConfig[i], errorMsg); 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"); ok(exception, "mozRTCPeerConnection({}) throws");
exception = null; exception = null;
try { pcs = new mozRTCPeerConnection([]); } catch (e) { exception = e; } try { pcs = new mozRTCPeerConnection([]); } catch (e) { exception = e; }
ok(!exception, "mozRTCPeerConnection([]) succeeds"); ok(exception, "mozRTCPeerConnection([]) throws");
exception = null; exception = null;
try { pc = new mozRTCPeerConnection([{}]); } catch (e) { exception = e; } try { pc = new mozRTCPeerConnection({ iceServers: {}}); } catch (e) { exception = e; }
ok(exception, "mozRTCPeerConnection([{}]) throws"); ok(exception, "mozRTCPeerConnection({ iceServers: {}}) throws");
exception = null; exception = null;
try { pc = new mozRTCPeerConnection([{ url:"" }]); } catch (e) { exception = e; } try { pcs = new mozRTCPeerConnection({ iceServers: [] }); } catch (e) { exception = e; }
ok(exception, "mozRTCPeerConnection([{ url:\"\" }]) throws"); ok(!exception, "mozRTCPeerConnection({ iceServers: [] }) succeeds");
exception = null; exception = null;
try { pc = new mozRTCPeerConnection([{ url:"http:0.0.0.0" }]); } catch (e) { exception = e; } try { pc = new mozRTCPeerConnection({ iceServers: [{ url:"" }] }); } catch (e) { exception = e; }
ok(exception, "mozRTCPeerConnection([{ url:\"http:0.0.0.0\" }]) throws"); ok(exception, "mozRTCPeerConnection({ iceServers: [{ url:\"\" }] }) throws");
exception = null; 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; } try { pc = new mozRTCPeerConnection({ iceServers: [{ url:"http:0.0.0.0" }] }); } 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"); ok(exception, "mozRTCPeerConnection({ iceServers: [{ url:\"http:0.0.0.0\" }] }) throws");
exception = null; exception = null;
try { pc = new mozRTCPeerConnection([{ url:"stun:0.0.0.0", credential:{}}]); } catch (e) { exception = e; } 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([{ url:\"stun:0.0.0.0\", credential:{}}]) throws"); 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; pc = null;
pcs = null; pcs = null;
SimpleTest.finish(); SimpleTest.finish();

Просмотреть файл

@ -320,8 +320,8 @@ Warn(JSContext* aCx, const nsCString& aMsg) {
/** /**
* In JS, an RTCConfiguration looks like this: * In JS, an RTCConfiguration looks like this:
* *
* [ { url:"stun:23.21.150.121" }, * { "iceServers": [ { url:"stun:23.21.150.121" },
* { url:"turn:user@turn.example.org", credential:"myPassword"} ] * { url:"turn:user@turn.example.org", credential:"mypass"} ] }
* *
* This function converts an already-validated jsval that looks like the above * This function converts an already-validated jsval that looks like the above
* into an RTCConfiguration object. * into an RTCConfiguration object.
@ -335,8 +335,13 @@ PeerConnectionImpl::ConvertRTCConfiguration(const JS::Value& aSrc,
if (!aSrc.isObject()) { if (!aSrc.isObject()) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
JSObject& servers = aSrc.toObject(); JSObject& config = aSrc.toObject();
JSAutoCompartment ac(aCx, &servers); 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; uint32_t len;
if (!(IsArrayLike(aCx, &servers) && JS_GetArrayLength(aCx, &servers, &len))) { if (!(IsArrayLike(aCx, &servers) && JS_GetArrayLength(aCx, &servers, &len))) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;