OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 UseCounter::count(context, UseCounter::RTCIceServerURL); | 291 UseCounter::count(context, UseCounter::RTCIceServerURL); |
292 urlStrings.push_back(iceServer.url()); | 292 urlStrings.push_back(iceServer.url()); |
293 } else { | 293 } else { |
294 exceptionState.throwTypeError("Malformed RTCIceServer"); | 294 exceptionState.throwTypeError("Malformed RTCIceServer"); |
295 return WebRTCConfiguration(); | 295 return WebRTCConfiguration(); |
296 } | 296 } |
297 | 297 |
298 String username = iceServer.username(); | 298 String username = iceServer.username(); |
299 String credential = iceServer.credential(); | 299 String credential = iceServer.credential(); |
300 | 300 |
301 Vector<WebURL> urls; | |
301 for (const String& urlString : urlStrings) { | 302 for (const String& urlString : urlStrings) { |
302 KURL url(KURL(), urlString); | 303 KURL url(KURL(), urlString); |
303 if (!url.isValid()) { | 304 if (!url.isValid()) { |
304 exceptionState.throwDOMException( | 305 exceptionState.throwDOMException( |
305 SyntaxError, "'" + urlString + "' is not a valid URL."); | 306 SyntaxError, "'" + urlString + "' is not a valid URL."); |
306 return WebRTCConfiguration(); | 307 return WebRTCConfiguration(); |
307 } | 308 } |
308 if (!(url.protocolIs("turn") || url.protocolIs("turns") || | 309 if (!(url.protocolIs("turn") || url.protocolIs("turns") || |
309 url.protocolIs("stun"))) { | 310 url.protocolIs("stun"))) { |
310 exceptionState.throwDOMException( | 311 exceptionState.throwDOMException( |
311 SyntaxError, "'" + url.protocol() + | 312 SyntaxError, "'" + url.protocol() + |
312 "' is not one of the supported URL schemes " | 313 "' is not one of the supported URL schemes " |
313 "'stun', 'turn' or 'turns'."); | 314 "'stun', 'turn' or 'turns'."); |
314 return WebRTCConfiguration(); | 315 return WebRTCConfiguration(); |
315 } | 316 } |
316 if ((url.protocolIs("turn") || url.protocolIs("turns")) && | 317 if ((url.protocolIs("turn") || url.protocolIs("turns")) && |
317 (username.isNull() || credential.isNull())) { | 318 (username.isNull() || credential.isNull())) { |
318 exceptionState.throwDOMException(InvalidAccessError, | 319 exceptionState.throwDOMException(InvalidAccessError, |
319 "Both username and credential are " | 320 "Both username and credential are " |
320 "required when the URL scheme is " | 321 "required when the URL scheme is " |
321 "\"turn\" or \"turns\"."); | 322 "\"turn\" or \"turns\"."); |
322 } | 323 } |
323 iceServers.push_back(WebRTCIceServer{url, username, credential}); | 324 urls.push_back(url); |
324 } | 325 } |
326 iceServers.push_back(WebRTCIceServer{urls, username, credential}); | |
dcheng
2017/03/09 21:36:54
Nit: () rather than {}. We only use uniform initia
zhihuang1
2017/03/10 03:20:43
Thanks for the link. Good to learn that.
dcheng
2017/03/10 19:54:00
Ah... I missed that this was a struct. It's OK to
Taylor_Brandstetter
2017/03/10 20:06:03
Actually, isn't emplace_back preferable then?
ice
| |
325 } | 327 } |
326 webConfiguration.iceServers = iceServers; | 328 webConfiguration.iceServers = iceServers; |
327 } | 329 } |
328 | 330 |
329 if (configuration.hasCertificates()) { | 331 if (configuration.hasCertificates()) { |
330 const HeapVector<Member<RTCCertificate>>& certificates = | 332 const HeapVector<Member<RTCCertificate>>& certificates = |
331 configuration.certificates(); | 333 configuration.certificates(); |
332 WebVector<std::unique_ptr<WebRTCCertificate>> certificatesCopy( | 334 WebVector<std::unique_ptr<WebRTCCertificate>> certificatesCopy( |
333 certificates.size()); | 335 certificates.size()); |
334 for (size_t i = 0; i < certificates.size(); ++i) { | 336 for (size_t i = 0; i < certificates.size(); ++i) { |
335 certificatesCopy[i] = certificates[i]->certificateShallowCopy(); | 337 certificatesCopy[i] = certificates[i]->certificateShallowCopy(); |
336 } | 338 } |
337 webConfiguration.certificates = std::move(certificatesCopy); | 339 webConfiguration.certificates = std::move(certificatesCopy); |
338 } | 340 } |
339 | 341 |
340 return webConfiguration; | 342 return webConfiguration; |
341 } | 343 } |
342 | 344 |
345 RTCConfiguration getWebKitRtcConfiguration(WebRTCConfiguration& blinkConfig) { | |
dcheng
2017/03/09 21:36:54
Pass argument by const ref.
The naming is also a
zhihuang1
2017/03/10 03:20:43
It is not const because the ownership of blinkConf
| |
346 RTCConfiguration rtcConfig; | |
347 | |
348 switch (blinkConfig.iceTransportPolicy) { | |
349 case blink::WebRTCIceTransportPolicy::kNone: | |
350 rtcConfig.setIceTransportPolicy("none"); | |
351 break; | |
352 case blink::WebRTCIceTransportPolicy::kRelay: | |
353 rtcConfig.setIceTransportPolicy("relay"); | |
354 break; | |
355 case blink::WebRTCIceTransportPolicy::kAll: | |
356 rtcConfig.setIceTransportPolicy("all"); | |
357 break; | |
358 } | |
359 | |
360 switch (blinkConfig.bundlePolicy) { | |
361 case blink::WebRTCBundlePolicy::kBalanced: | |
362 rtcConfig.setBundlePolicy("balanced"); | |
363 break; | |
364 case blink::WebRTCBundlePolicy::kMaxBundle: | |
365 rtcConfig.setBundlePolicy("max-bundle"); | |
366 break; | |
367 case blink::WebRTCBundlePolicy::kMaxCompat: | |
368 rtcConfig.setBundlePolicy("max-compat"); | |
369 break; | |
370 } | |
371 | |
372 switch (blinkConfig.rtcpMuxPolicy) { | |
373 case blink::WebRTCRtcpMuxPolicy::kNegotiate: | |
374 rtcConfig.setRtcpMuxPolicy("negotiate"); | |
375 break; | |
376 case blink::WebRTCRtcpMuxPolicy::kRequire: | |
377 rtcConfig.setRtcpMuxPolicy("require"); | |
378 break; | |
379 } | |
380 | |
381 HeapVector<RTCIceServer> servers; | |
382 for (WebRTCIceServer blink_server : blinkConfig.iceServers) { | |
tommi (sloooow) - chröme
2017/03/09 19:37:08
nit: const WebRTCIceServer&
as is, you're creating
zhihuang1
2017/03/10 03:20:43
Done.
| |
383 RTCIceServer server; | |
384 Vector<String> urlStrings; | |
385 StringOrStringSequence urls; | |
386 for (WebURL blink_url : blink_server.urls) { | |
tommi (sloooow) - chröme
2017/03/09 19:37:08
const WebURL&
zhihuang1
2017/03/10 03:20:43
Done.
| |
387 String urlString(blink_url.string().utf8().c_str()); | |
388 urlStrings.push_back(urlString); | |
389 } | |
390 urls.setStringSequence(urlStrings); | |
391 server.setURLs(urls); | |
392 String username(blink_server.username.utf8().c_str()); | |
393 server.setUsername(blink_server.username); | |
394 String credential(blink_server.credential.utf8().c_str()); | |
395 server.setCredential(credential); | |
396 servers.push_back(server); | |
397 } | |
398 rtcConfig.setIceServers(servers); | |
399 | |
400 HeapVector<Member<RTCCertificate>> certificates; | |
401 for (std::unique_ptr<blink::WebRTCCertificate>& blink_certificate : | |
dcheng
2017/03/09 21:36:54
auto& for conciseness
zhihuang1
2017/03/10 03:20:43
Done.
| |
402 blinkConfig.certificates) { | |
403 certificates.push_back(new RTCCertificate(std::move(blink_certificate))); | |
404 } | |
405 rtcConfig.setCertificates(certificates); | |
406 | |
407 return rtcConfig; | |
408 } | |
409 | |
343 RTCOfferOptionsPlatform* parseOfferOptions(const Dictionary& options, | 410 RTCOfferOptionsPlatform* parseOfferOptions(const Dictionary& options, |
344 ExceptionState& exceptionState) { | 411 ExceptionState& exceptionState) { |
345 if (options.isUndefinedOrNull()) | 412 if (options.isUndefinedOrNull()) |
346 return nullptr; | 413 return nullptr; |
347 | 414 |
348 const Vector<String>& propertyNames = | 415 const Vector<String>& propertyNames = |
349 options.getPropertyNames(exceptionState); | 416 options.getPropertyNames(exceptionState); |
350 if (exceptionState.hadException()) | 417 if (exceptionState.hadException()) |
351 return nullptr; | 418 return nullptr; |
352 | 419 |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 | 855 |
789 RTCSessionDescription* RTCPeerConnection::remoteDescription() { | 856 RTCSessionDescription* RTCPeerConnection::remoteDescription() { |
790 WebRTCSessionDescription webSessionDescription = | 857 WebRTCSessionDescription webSessionDescription = |
791 m_peerHandler->remoteDescription(); | 858 m_peerHandler->remoteDescription(); |
792 if (webSessionDescription.isNull()) | 859 if (webSessionDescription.isNull()) |
793 return nullptr; | 860 return nullptr; |
794 | 861 |
795 return RTCSessionDescription::create(webSessionDescription); | 862 return RTCSessionDescription::create(webSessionDescription); |
796 } | 863 } |
797 | 864 |
865 void RTCPeerConnection::getConfiguration(RTCConfiguration& rtcConfig) { | |
866 blink::WebRTCConfiguration blinkConfig = m_peerHandler->getConfiguration(); | |
867 rtcConfig = getWebKitRtcConfiguration(blinkConfig); | |
dcheng
2017/03/09 21:36:54
Nit: reads a bit more naturally to just return the
zhihuang1
2017/03/10 03:20:43
I agree that the direct return is more nature but
dcheng
2017/03/10 19:54:00
Acknowledged.
| |
868 } | |
869 | |
798 void RTCPeerConnection::setConfiguration( | 870 void RTCPeerConnection::setConfiguration( |
799 ScriptState* scriptState, | 871 ScriptState* scriptState, |
800 const RTCConfiguration& rtcConfiguration, | 872 const RTCConfiguration& rtcConfiguration, |
801 ExceptionState& exceptionState) { | 873 ExceptionState& exceptionState) { |
802 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) | 874 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) |
803 return; | 875 return; |
804 | 876 |
805 WebRTCConfiguration configuration = parseConfiguration( | 877 WebRTCConfiguration configuration = parseConfiguration( |
806 scriptState->getExecutionContext(), rtcConfiguration, exceptionState); | 878 scriptState->getExecutionContext(), rtcConfiguration, exceptionState); |
807 | 879 |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1499 DEFINE_TRACE(RTCPeerConnection) { | 1571 DEFINE_TRACE(RTCPeerConnection) { |
1500 visitor->trace(m_localStreams); | 1572 visitor->trace(m_localStreams); |
1501 visitor->trace(m_remoteStreams); | 1573 visitor->trace(m_remoteStreams); |
1502 visitor->trace(m_dispatchScheduledEventRunner); | 1574 visitor->trace(m_dispatchScheduledEventRunner); |
1503 visitor->trace(m_scheduledEvents); | 1575 visitor->trace(m_scheduledEvents); |
1504 EventTargetWithInlineData::trace(visitor); | 1576 EventTargetWithInlineData::trace(visitor); |
1505 SuspendableObject::trace(visitor); | 1577 SuspendableObject::trace(visitor); |
1506 } | 1578 } |
1507 | 1579 |
1508 } // namespace blink | 1580 } // namespace blink |
OLD | NEW |