Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: third_party/WebKit/Source/modules/peerconnection/RTCPeerConnection.cpp

Issue 2706563003: Create the API that returns the RTCConfiguration of the PeerConnection.
Patch Set: Fix the issues in data type conversion. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/11 07:14:46 Nit: omit WebRTCIceServer, and just use braces, si
zhihuang1 2017/03/13 18:50:53 I tried this but the compiler didn't like it. th
dcheng 2017/03/14 05:37:51 Ah... it's because the types here don't exactly ma
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) {
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 790
789 RTCSessionDescription* RTCPeerConnection::remoteDescription() { 791 RTCSessionDescription* RTCPeerConnection::remoteDescription() {
790 WebRTCSessionDescription webSessionDescription = 792 WebRTCSessionDescription webSessionDescription =
791 m_peerHandler->remoteDescription(); 793 m_peerHandler->remoteDescription();
792 if (webSessionDescription.isNull()) 794 if (webSessionDescription.isNull())
793 return nullptr; 795 return nullptr;
794 796
795 return RTCSessionDescription::create(webSessionDescription); 797 return RTCSessionDescription::create(webSessionDescription);
796 } 798 }
797 799
800 void RTCPeerConnection::getConfiguration(RTCConfiguration& rtcConfig) {
801 blink::WebRTCConfiguration blinkConfig = m_peerHandler->getConfiguration();
802
803 switch (blinkConfig.iceTransportPolicy) {
804 case blink::WebRTCIceTransportPolicy::kNone:
805 rtcConfig.setIceTransportPolicy("none");
806 break;
807 case blink::WebRTCIceTransportPolicy::kRelay:
808 rtcConfig.setIceTransportPolicy("relay");
809 break;
810 case blink::WebRTCIceTransportPolicy::kAll:
811 rtcConfig.setIceTransportPolicy("all");
812 break;
813 }
814
815 switch (blinkConfig.bundlePolicy) {
816 case blink::WebRTCBundlePolicy::kBalanced:
817 rtcConfig.setBundlePolicy("balanced");
818 break;
819 case blink::WebRTCBundlePolicy::kMaxBundle:
820 rtcConfig.setBundlePolicy("max-bundle");
821 break;
822 case blink::WebRTCBundlePolicy::kMaxCompat:
823 rtcConfig.setBundlePolicy("max-compat");
824 break;
825 }
826
827 switch (blinkConfig.rtcpMuxPolicy) {
828 case blink::WebRTCRtcpMuxPolicy::kNegotiate:
829 rtcConfig.setRtcpMuxPolicy("negotiate");
830 break;
831 case blink::WebRTCRtcpMuxPolicy::kRequire:
832 rtcConfig.setRtcpMuxPolicy("require");
833 break;
834 }
835
836 HeapVector<RTCIceServer> servers;
837 for (const WebRTCIceServer& blink_server : blinkConfig.iceServers) {
838 RTCIceServer server;
839 Vector<String> urlStrings;
840 StringOrStringSequence urls;
841 for (const WebURL& blink_url : blink_server.urls)
842 urlStrings.push_back(blink_url.string());
843 urls.setStringSequence(urlStrings);
844 server.setURLs(urls);
845 server.setUsername(blink_server.username);
846 server.setCredential(blink_server.credential);
847 servers.push_back(server);
848 }
849 rtcConfig.setIceServers(servers);
850
851 HeapVector<Member<RTCCertificate>> certificates;
852 for (auto& blink_certificate : blinkConfig.certificates) {
853 certificates.push_back(new RTCCertificate(std::move(blink_certificate)));
854 }
855 rtcConfig.setCertificates(certificates);
856 }
857
798 void RTCPeerConnection::setConfiguration( 858 void RTCPeerConnection::setConfiguration(
799 ScriptState* scriptState, 859 ScriptState* scriptState,
800 const RTCConfiguration& rtcConfiguration, 860 const RTCConfiguration& rtcConfiguration,
801 ExceptionState& exceptionState) { 861 ExceptionState& exceptionState) {
802 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) 862 if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState))
803 return; 863 return;
804 864
805 WebRTCConfiguration configuration = parseConfiguration( 865 WebRTCConfiguration configuration = parseConfiguration(
806 scriptState->getExecutionContext(), rtcConfiguration, exceptionState); 866 scriptState->getExecutionContext(), rtcConfiguration, exceptionState);
807 867
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 DEFINE_TRACE(RTCPeerConnection) { 1559 DEFINE_TRACE(RTCPeerConnection) {
1500 visitor->trace(m_localStreams); 1560 visitor->trace(m_localStreams);
1501 visitor->trace(m_remoteStreams); 1561 visitor->trace(m_remoteStreams);
1502 visitor->trace(m_dispatchScheduledEventRunner); 1562 visitor->trace(m_dispatchScheduledEventRunner);
1503 visitor->trace(m_scheduledEvents); 1563 visitor->trace(m_scheduledEvents);
1504 EventTargetWithInlineData::trace(visitor); 1564 EventTargetWithInlineData::trace(visitor);
1505 SuspendableObject::trace(visitor); 1565 SuspendableObject::trace(visitor);
1506 } 1566 }
1507 1567
1508 } // namespace blink 1568 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698