void RTCConfiguration::initialize(const Dictionary& configuration, ExceptionCode& ec) { ArrayValue iceServers; bool ok = configuration.get("iceServers", iceServers); if (!ok || iceServers.isUndefinedOrNull()) { ec = TYPE_MISMATCH_ERR; return; } size_t numberOfServers; ok = iceServers.length(numberOfServers); if (!ok || !numberOfServers) { ec = !ok ? TYPE_MISMATCH_ERR : INVALID_ACCESS_ERR; return; } for (size_t i = 0; i < numberOfServers; ++i) { Dictionary iceServerDict; ok = iceServers.get(i, iceServerDict); if (!ok) { ec = TYPE_MISMATCH_ERR; return; } RefPtr<RTCIceServer> iceServer = parseIceServer(iceServerDict, ec); if (!iceServer) return; m_iceServers.append(WTFMove(iceServer)); } String iceTransportPolicy; if (configuration.get("iceTransportPolicy", iceTransportPolicy)) { if (iceTransportPolicy == "relay") m_iceTransportPolicy = IceTransportPolicy::Relay; else if (iceTransportPolicy == "all") m_iceTransportPolicy = IceTransportPolicy::All; else { ec = TypeError; return; } } String bundlePolicy; if (configuration.get("bundlePolicy", bundlePolicy)) { if (bundlePolicy == "balanced") m_bundlePolicy = BundlePolicy::Balanced; else if (bundlePolicy == "max-compat") m_bundlePolicy = BundlePolicy::MaxCompat; else if (bundlePolicy == "max-bundle") m_bundlePolicy = BundlePolicy::MaxBundle; else ec = TypeError; } }
ExceptionOr<void> RTCConfiguration::initialize(const Dictionary& configuration) { ArrayValue iceServers; bool ok = configuration.get("iceServers", iceServers); if (!ok || iceServers.isUndefinedOrNull()) return Exception { TYPE_MISMATCH_ERR }; size_t numberOfServers; ok = iceServers.length(numberOfServers); if (!ok) return Exception { TYPE_MISMATCH_ERR }; if (!numberOfServers) return Exception { INVALID_ACCESS_ERR }; for (size_t i = 0; i < numberOfServers; ++i) { Dictionary iceServerDict; ok = iceServers.get(i, iceServerDict); if (!ok) return Exception { TYPE_MISMATCH_ERR }; auto server = parseIceServer(iceServerDict); if (server.hasException()) return server.releaseException(); m_iceServers.append(server.releaseReturnValue()); } String iceTransportPolicy; if (configuration.get("iceTransportPolicy", iceTransportPolicy)) { if (iceTransportPolicy == "relay") m_iceTransportPolicy = IceTransportPolicy::Relay; else if (iceTransportPolicy == "all") m_iceTransportPolicy = IceTransportPolicy::All; else return Exception { TypeError }; } String bundlePolicy; if (configuration.get("bundlePolicy", bundlePolicy)) { if (bundlePolicy == "balanced") m_bundlePolicy = BundlePolicy::Balanced; else if (bundlePolicy == "max-compat") m_bundlePolicy = BundlePolicy::MaxCompat; else if (bundlePolicy == "max-bundle") m_bundlePolicy = BundlePolicy::MaxBundle; else return Exception { TypeError }; } return { }; }