wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 9 | */ |
| 10 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 11 | #include "pc/webrtc_session_description_factory.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include <stddef.h> |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 14 | #include <algorithm> |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 15 | #include <memory> |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 16 | #include <string> |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 17 | #include <type_traits> |
kwiberg | 0eb15ed | 2015-12-17 11:04:15 | [diff] [blame] | 18 | #include <utility> |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 19 | #include <vector> |
kwiberg | 0eb15ed | 2015-12-17 11:04:15 | [diff] [blame] | 20 | |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 21 | #include "absl/algorithm/container.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 22 | #include "absl/types/optional.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 24 | #include "api/jsep_session_description.h" |
| 25 | #include "api/rtc_error.h" |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 26 | #include "pc/sdp_state_provider.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 27 | #include "pc/session_description.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 28 | #include "rtc_base/checks.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 29 | #include "rtc_base/location.h" |
| 30 | #include "rtc_base/logging.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 31 | #include "rtc_base/ref_counted_object.h" |
| 32 | #include "rtc_base/ssl_identity.h" |
| 33 | #include "rtc_base/ssl_stream_adapter.h" |
| 34 | #include "rtc_base/string_encode.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 35 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 36 | using cricket::MediaSessionOptions; |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 37 | using rtc::UniqueRandomIdGenerator; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 | [diff] [blame] | 38 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 39 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 40 | namespace { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 41 | static const char kFailedDueToIdentityFailed[] = |
| 42 | " failed because DTLS identity request failed"; |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 43 | static const char kFailedDueToSessionShutdown[] = |
| 44 | " failed because the session was shut down"; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 45 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 46 | static const uint64_t kInitSessionVersion = 2; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 47 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 48 | // Check that each sender has a unique ID. |
| 49 | static bool ValidMediaSessionOptions( |
| 50 | const cricket::MediaSessionOptions& session_options) { |
| 51 | std::vector<cricket::SenderOptions> sorted_senders; |
| 52 | for (const cricket::MediaDescriptionOptions& media_description_options : |
| 53 | session_options.media_description_options) { |
| 54 | sorted_senders.insert(sorted_senders.end(), |
| 55 | media_description_options.sender_options.begin(), |
| 56 | media_description_options.sender_options.end()); |
| 57 | } |
Steve Anton | 64b626b | 2019-01-29 01:25:26 | [diff] [blame] | 58 | absl::c_sort(sorted_senders, [](const cricket::SenderOptions& sender1, |
| 59 | const cricket::SenderOptions& sender2) { |
| 60 | return sender1.track_id < sender2.track_id; |
| 61 | }); |
| 62 | return absl::c_adjacent_find(sorted_senders, |
| 63 | [](const cricket::SenderOptions& sender1, |
| 64 | const cricket::SenderOptions& sender2) { |
| 65 | return sender1.track_id == sender2.track_id; |
| 66 | }) == sorted_senders.end(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | enum { |
| 70 | MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 71 | MSG_CREATE_SESSIONDESCRIPTION_FAILED, |
| 72 | MSG_USE_CONSTRUCTOR_CERTIFICATE |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 73 | }; |
| 74 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 75 | struct CreateSessionDescriptionMsg : public rtc::MessageData { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 76 | explicit CreateSessionDescriptionMsg( |
Harald Alvestrand | 73771a8 | 2018-05-24 08:53:49 | [diff] [blame] | 77 | webrtc::CreateSessionDescriptionObserver* observer, |
| 78 | RTCError error_in) |
| 79 | : observer(observer), error(std::move(error_in)) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 80 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 81 | rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; |
Harald Alvestrand | 73771a8 | 2018-05-24 08:53:49 | [diff] [blame] | 82 | RTCError error; |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 83 | std::unique_ptr<webrtc::SessionDescriptionInterface> description; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 84 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 85 | } // namespace |
| 86 | |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 87 | void WebRtcCertificateGeneratorCallback::OnFailure() { |
| 88 | SignalRequestFailed(); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 89 | } |
| 90 | |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 91 | void WebRtcCertificateGeneratorCallback::OnSuccess( |
| 92 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
| 93 | SignalCertificateReady(certificate); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 94 | } |
| 95 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 96 | // static |
| 97 | void WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
| 98 | const SessionDescriptionInterface* source_desc, |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 99 | const std::string& content_name, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 100 | SessionDescriptionInterface* dest_desc) { |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 101 | if (!source_desc) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 102 | return; |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 103 | } |
| 104 | const cricket::ContentInfos& contents = |
| 105 | source_desc->description()->contents(); |
| 106 | const cricket::ContentInfo* cinfo = |
| 107 | source_desc->description()->GetContentByName(content_name); |
| 108 | if (!cinfo) { |
| 109 | return; |
| 110 | } |
| 111 | size_t mediasection_index = static_cast<int>(cinfo - &contents[0]); |
| 112 | const IceCandidateCollection* source_candidates = |
| 113 | source_desc->candidates(mediasection_index); |
| 114 | const IceCandidateCollection* dest_candidates = |
| 115 | dest_desc->candidates(mediasection_index); |
Taylor Brandstetter | 4eb1ddd | 2016-03-02 00:21:07 | [diff] [blame] | 116 | if (!source_candidates || !dest_candidates) { |
| 117 | return; |
| 118 | } |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 119 | for (size_t n = 0; n < source_candidates->count(); ++n) { |
| 120 | const IceCandidateInterface* new_candidate = source_candidates->at(n); |
| 121 | if (!dest_candidates->HasCandidate(new_candidate)) { |
| 122 | dest_desc->AddCandidate(source_candidates->at(n)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 128 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 129 | cricket::ChannelManager* channel_manager, |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 130 | const SdpStateProvider* sdp_info, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 131 | const std::string& session_id, |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 132 | bool dtls_enabled, |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 133 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 134 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate, |
Harald Alvestrand | a094787 | 2020-11-09 14:15:00 | [diff] [blame] | 135 | UniqueRandomIdGenerator* ssrc_generator, |
| 136 | std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)> |
| 137 | on_certificate_ready) |
Tomas Gunnarsson | 77baeee | 2020-09-24 20:39:21 | [diff] [blame] | 138 | : signaling_thread_(signaling_thread), |
Amit Hilbuch | bcd39d4 | 2019-01-26 01:13:56 | [diff] [blame] | 139 | session_desc_factory_(channel_manager, |
| 140 | &transport_desc_factory_, |
| 141 | ssrc_generator), |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 142 | // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp |
| 143 | // as the session id and session version. To simplify, it should be fine |
| 144 | // to just use a random number as session id and start version from |
| 145 | // |kInitSessionVersion|. |
| 146 | session_version_(kInitSessionVersion), |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 147 | cert_generator_(dtls_enabled ? std::move(cert_generator) : nullptr), |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 148 | sdp_info_(sdp_info), |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 149 | session_id_(session_id), |
Harald Alvestrand | a094787 | 2020-11-09 14:15:00 | [diff] [blame] | 150 | certificate_request_state_(CERTIFICATE_NOT_NEEDED), |
| 151 | on_certificate_ready_(on_certificate_ready) { |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 152 | RTC_DCHECK(signaling_thread_); |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 153 | |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 154 | if (!dtls_enabled) { |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 155 | SetSdesPolicy(cricket::SEC_REQUIRED); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 156 | RTC_LOG(LS_VERBOSE) << "DTLS-SRTP disabled."; |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 160 | // SRTP-SDES is disabled if DTLS is on. |
| 161 | SetSdesPolicy(cricket::SEC_DISABLED); |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 162 | if (certificate) { |
| 163 | // Use |certificate|. |
| 164 | certificate_request_state_ = CERTIFICATE_WAITING; |
| 165 | |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 166 | RTC_LOG(LS_VERBOSE) << "DTLS-SRTP enabled; has certificate parameter."; |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 167 | // We already have a certificate but we wait to do |SetIdentity|; if we do |
| 168 | // it in the constructor then the caller has not had a chance to connect to |
| 169 | // |SignalCertificateReady|. |
| 170 | signaling_thread_->Post( |
Taylor Brandstetter | 5d97a9a | 2016-06-10 21:17:27 | [diff] [blame] | 171 | RTC_FROM_HERE, this, MSG_USE_CONSTRUCTOR_CERTIFICATE, |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 172 | new rtc::ScopedRefMessageData<rtc::RTCCertificate>(certificate)); |
| 173 | } else { |
| 174 | // Generate certificate. |
| 175 | certificate_request_state_ = CERTIFICATE_WAITING; |
| 176 | |
| 177 | rtc::scoped_refptr<WebRtcCertificateGeneratorCallback> callback( |
| 178 | new rtc::RefCountedObject<WebRtcCertificateGeneratorCallback>()); |
| 179 | callback->SignalRequestFailed.connect( |
| 180 | this, &WebRtcSessionDescriptionFactory::OnCertificateRequestFailed); |
| 181 | callback->SignalCertificateReady.connect( |
| 182 | this, &WebRtcSessionDescriptionFactory::SetCertificate); |
| 183 | |
| 184 | rtc::KeyParams key_params = rtc::KeyParams(); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 185 | RTC_LOG(LS_VERBOSE) |
Jonas Olsson | 45cc890 | 2018-02-13 09:37:07 | [diff] [blame] | 186 | << "DTLS-SRTP enabled; sending DTLS identity request (key type: " |
| 187 | << key_params.type() << ")."; |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 188 | |
| 189 | // Request certificate. This happens asynchronously, so that the caller gets |
| 190 | // a chance to connect to |SignalCertificateReady|. |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 191 | cert_generator_->GenerateCertificateAsync(key_params, absl::nullopt, |
Oskar Sundbom | 36f8f3e | 2017-11-16 09:54:27 | [diff] [blame] | 192 | callback); |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 193 | } |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 194 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 195 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 196 | WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 197 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 198 | |
| 199 | // Fail any requests that were asked for before identity generation completed. |
| 200 | FailPendingRequests(kFailedDueToSessionShutdown); |
| 201 | |
| 202 | // Process all pending notifications in the message queue. If we don't do |
| 203 | // this, requests will linger and not know they succeeded or failed. |
| 204 | rtc::MessageList list; |
| 205 | signaling_thread_->Clear(this, rtc::MQID_ANY, &list); |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 206 | for (auto& msg : list) { |
| 207 | if (msg.message_id != MSG_USE_CONSTRUCTOR_CERTIFICATE) { |
| 208 | OnMessage(&msg); |
| 209 | } else { |
| 210 | // Skip MSG_USE_CONSTRUCTOR_CERTIFICATE because we don't want to trigger |
| 211 | // SetIdentity-related callbacks in the destructor. This can be a problem |
| 212 | // when WebRtcSession listens to the callback but it was the WebRtcSession |
| 213 | // destructor that caused WebRtcSessionDescriptionFactory's destruction. |
| 214 | // The callback is then ignored, leaking memory allocated by OnMessage for |
| 215 | // MSG_USE_CONSTRUCTOR_CERTIFICATE. |
| 216 | delete msg.pdata; |
| 217 | } |
| 218 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void WebRtcSessionDescriptionFactory::CreateOffer( |
| 222 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 223 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 224 | const cricket::MediaSessionOptions& session_options) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 225 | std::string error = "CreateOffer"; |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 226 | if (certificate_request_state_ == CERTIFICATE_FAILED) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 227 | error += kFailedDueToIdentityFailed; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 228 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 229 | PostCreateSessionDescriptionFailed(observer, error); |
| 230 | return; |
| 231 | } |
| 232 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 233 | if (!ValidMediaSessionOptions(session_options)) { |
| 234 | error += " called with invalid session options"; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 235 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 236 | PostCreateSessionDescriptionFailed(observer, error); |
| 237 | return; |
| 238 | } |
| 239 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 240 | CreateSessionDescriptionRequest request( |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 | [diff] [blame] | 241 | CreateSessionDescriptionRequest::kOffer, observer, session_options); |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 242 | if (certificate_request_state_ == CERTIFICATE_WAITING) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 243 | create_session_description_requests_.push(request); |
| 244 | } else { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 245 | RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
| 246 | certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 247 | InternalCreateOffer(request); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void WebRtcSessionDescriptionFactory::CreateAnswer( |
| 252 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 253 | const cricket::MediaSessionOptions& session_options) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 254 | std::string error = "CreateAnswer"; |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 255 | if (certificate_request_state_ == CERTIFICATE_FAILED) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 256 | error += kFailedDueToIdentityFailed; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 257 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 258 | PostCreateSessionDescriptionFailed(observer, error); |
| 259 | return; |
| 260 | } |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 261 | if (!sdp_info_->remote_description()) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 262 | error += " can't be called before SetRemoteDescription."; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 263 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 264 | PostCreateSessionDescriptionFailed(observer, error); |
| 265 | return; |
| 266 | } |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 267 | if (sdp_info_->remote_description()->GetType() != SdpType::kOffer) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 268 | error += " failed because remote_description is not an offer."; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 269 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 270 | PostCreateSessionDescriptionFailed(observer, error); |
| 271 | return; |
| 272 | } |
| 273 | |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 274 | if (!ValidMediaSessionOptions(session_options)) { |
| 275 | error += " called with invalid session options."; |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 276 | RTC_LOG(LS_ERROR) << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 277 | PostCreateSessionDescriptionFailed(observer, error); |
| 278 | return; |
| 279 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 280 | |
| 281 | CreateSessionDescriptionRequest request( |
deadbeef | ab9b2d1 | 2015-10-14 18:33:11 | [diff] [blame] | 282 | CreateSessionDescriptionRequest::kAnswer, observer, session_options); |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 283 | if (certificate_request_state_ == CERTIFICATE_WAITING) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 284 | create_session_description_requests_.push(request); |
| 285 | } else { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 286 | RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
| 287 | certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 288 | InternalCreateAnswer(request); |
| 289 | } |
| 290 | } |
| 291 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 | [diff] [blame] | 292 | void WebRtcSessionDescriptionFactory::SetSdesPolicy( |
| 293 | cricket::SecurePolicy secure_policy) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 294 | session_desc_factory_.set_secure(secure_policy); |
| 295 | } |
| 296 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 | [diff] [blame] | 297 | cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 298 | return session_desc_factory_.secure(); |
| 299 | } |
| 300 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 | [diff] [blame] | 301 | void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 302 | switch (msg->message_id) { |
| 303 | case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: { |
| 304 | CreateSessionDescriptionMsg* param = |
| 305 | static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
| 306 | param->observer->OnSuccess(param->description.release()); |
| 307 | delete param; |
| 308 | break; |
| 309 | } |
| 310 | case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { |
| 311 | CreateSessionDescriptionMsg* param = |
| 312 | static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
Harald Alvestrand | 73771a8 | 2018-05-24 08:53:49 | [diff] [blame] | 313 | param->observer->OnFailure(std::move(param->error)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 314 | delete param; |
| 315 | break; |
| 316 | } |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 317 | case MSG_USE_CONSTRUCTOR_CERTIFICATE: { |
| 318 | rtc::ScopedRefMessageData<rtc::RTCCertificate>* param = |
| 319 | static_cast<rtc::ScopedRefMessageData<rtc::RTCCertificate>*>( |
| 320 | msg->pdata); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 321 | RTC_LOG(LS_INFO) << "Using certificate supplied to the constructor."; |
Henrik Boström | d828198 | 2015-08-27 08:12:24 | [diff] [blame] | 322 | SetCertificate(param->data()); |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 323 | delete param; |
| 324 | break; |
| 325 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 326 | default: |
nisse | c80e741 | 2017-01-11 13:56:46 | [diff] [blame] | 327 | RTC_NOTREACHED(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 328 | break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | void WebRtcSessionDescriptionFactory::InternalCreateOffer( |
| 333 | CreateSessionDescriptionRequest request) { |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 334 | if (sdp_info_->local_description()) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 335 | // If the needs-ice-restart flag is set as described by JSEP, we should |
| 336 | // generate an offer with a new ufrag/password to trigger an ICE restart. |
| 337 | for (cricket::MediaDescriptionOptions& options : |
| 338 | request.options.media_description_options) { |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 339 | if (sdp_info_->NeedsIceRestart(options.mid)) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 340 | options.transport_options.ice_restart = true; |
deadbeef | d1a38b5 | 2016-12-10 21:15:33 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 345 | std::unique_ptr<cricket::SessionDescription> desc = |
| 346 | session_desc_factory_.CreateOffer( |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 347 | request.options, sdp_info_->local_description() |
| 348 | ? sdp_info_->local_description()->description() |
| 349 | : nullptr); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 350 | if (!desc) { |
| 351 | PostCreateSessionDescriptionFailed(request.observer, |
| 352 | "Failed to initialize the offer."); |
| 353 | return; |
| 354 | } |
| 355 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 356 | // RFC 3264 |
| 357 | // When issuing an offer that modifies the session, |
| 358 | // the "o=" line of the new SDP MUST be identical to that in the |
| 359 | // previous SDP, except that the version in the origin field MUST |
| 360 | // increment by one from the previous SDP. |
| 361 | |
| 362 | // Just increase the version number by one each time when a new offer |
| 363 | // is created regardless if it's identical to the previous one or not. |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 364 | // The |session_version_| is a uint64_t, the wrap around should not happen. |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 365 | RTC_DCHECK(session_version_ + 1 > session_version_); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 366 | auto offer = std::make_unique<JsepSessionDescription>( |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 367 | SdpType::kOffer, std::move(desc), session_id_, |
| 368 | rtc::ToString(session_version_++)); |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 369 | if (sdp_info_->local_description()) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 370 | for (const cricket::MediaDescriptionOptions& options : |
| 371 | request.options.media_description_options) { |
| 372 | if (!options.transport_options.ice_restart) { |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 373 | CopyCandidatesFromSessionDescription(sdp_info_->local_description(), |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 374 | options.mid, offer.get()); |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 375 | } |
| 376 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 377 | } |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 378 | PostCreateSessionDescriptionSucceeded(request.observer, std::move(offer)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | void WebRtcSessionDescriptionFactory::InternalCreateAnswer( |
| 382 | CreateSessionDescriptionRequest request) { |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 383 | if (sdp_info_->remote_description()) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 384 | for (cricket::MediaDescriptionOptions& options : |
| 385 | request.options.media_description_options) { |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 386 | // According to http://tools.ietf.org/html/rfc5245#section-9.2.1.1 |
| 387 | // an answer should also contain new ICE ufrag and password if an offer |
| 388 | // has been received with new ufrag and password. |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 389 | options.transport_options.ice_restart = |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 390 | sdp_info_->IceRestartPending(options.mid); |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 391 | // We should pass the current DTLS role to the transport description |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 392 | // factory, if there is already an existing ongoing session. |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 393 | absl::optional<rtc::SSLRole> dtls_role = |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 394 | sdp_info_->GetDtlsRole(options.mid); |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 395 | if (dtls_role) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 396 | options.transport_options.prefer_passive_role = |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 397 | (rtc::SSL_SERVER == *dtls_role); |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 398 | } |
| 399 | } |
sergeyu@chromium.org | 0be6aa0 | 2013-08-23 23:21:25 | [diff] [blame] | 400 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 401 | |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 402 | std::unique_ptr<cricket::SessionDescription> desc = |
| 403 | session_desc_factory_.CreateAnswer( |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 404 | sdp_info_->remote_description() |
| 405 | ? sdp_info_->remote_description()->description() |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 406 | : nullptr, |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 407 | request.options, |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 408 | sdp_info_->local_description() |
| 409 | ? sdp_info_->local_description()->description() |
Harald Alvestrand | d89ce53 | 2020-10-21 08:59:22 | [diff] [blame] | 410 | : nullptr); |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 411 | if (!desc) { |
| 412 | PostCreateSessionDescriptionFailed(request.observer, |
| 413 | "Failed to initialize the answer."); |
| 414 | return; |
| 415 | } |
| 416 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 417 | // RFC 3264 |
| 418 | // If the answer is different from the offer in any way (different IP |
| 419 | // addresses, ports, etc.), the origin line MUST be different in the answer. |
| 420 | // In that case, the version number in the "o=" line of the answer is |
| 421 | // unrelated to the version number in the o line of the offer. |
| 422 | // Get a new version number by increasing the |session_version_answer_|. |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 423 | // The |session_version_| is a uint64_t, the wrap around should not happen. |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 424 | RTC_DCHECK(session_version_ + 1 > session_version_); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 425 | auto answer = std::make_unique<JsepSessionDescription>( |
Steve Anton | 6fe1fba | 2018-12-11 18:15:23 | [diff] [blame] | 426 | SdpType::kAnswer, std::move(desc), session_id_, |
| 427 | rtc::ToString(session_version_++)); |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 428 | if (sdp_info_->local_description()) { |
zhihuang | 1c378ed | 2017-08-17 21:10:50 | [diff] [blame] | 429 | // Include all local ICE candidates in the SessionDescription unless |
| 430 | // the remote peer has requested an ICE restart. |
| 431 | for (const cricket::MediaDescriptionOptions& options : |
| 432 | request.options.media_description_options) { |
| 433 | if (!options.transport_options.ice_restart) { |
Harald Alvestrand | f01bd6c | 2020-10-23 13:30:46 | [diff] [blame] | 434 | CopyCandidatesFromSessionDescription(sdp_info_->local_description(), |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 435 | options.mid, answer.get()); |
deadbeef | 0ed85b2 | 2016-02-24 01:24:52 | [diff] [blame] | 436 | } |
| 437 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 438 | } |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 439 | PostCreateSessionDescriptionSucceeded(request.observer, std::move(answer)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 440 | } |
| 441 | |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 442 | void WebRtcSessionDescriptionFactory::FailPendingRequests( |
| 443 | const std::string& reason) { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 444 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 445 | while (!create_session_description_requests_.empty()) { |
| 446 | const CreateSessionDescriptionRequest& request = |
| 447 | create_session_description_requests_.front(); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 448 | PostCreateSessionDescriptionFailed( |
| 449 | request.observer, |
| 450 | ((request.type == CreateSessionDescriptionRequest::kOffer) |
| 451 | ? "CreateOffer" |
| 452 | : "CreateAnswer") + |
| 453 | reason); |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 454 | create_session_description_requests_.pop(); |
| 455 | } |
| 456 | } |
| 457 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 458 | void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 459 | CreateSessionDescriptionObserver* observer, |
| 460 | const std::string& error) { |
Harald Alvestrand | 73771a8 | 2018-05-24 08:53:49 | [diff] [blame] | 461 | CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg( |
| 462 | observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::string(error))); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 21:17:27 | [diff] [blame] | 463 | signaling_thread_->Post(RTC_FROM_HERE, this, |
| 464 | MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 465 | RTC_LOG(LS_ERROR) << "Create SDP failed: " << error; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( |
| 469 | CreateSessionDescriptionObserver* observer, |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 470 | std::unique_ptr<SessionDescriptionInterface> description) { |
Harald Alvestrand | 73771a8 | 2018-05-24 08:53:49 | [diff] [blame] | 471 | CreateSessionDescriptionMsg* msg = |
| 472 | new CreateSessionDescriptionMsg(observer, RTCError::OK()); |
Steve Anton | a3a92c2 | 2017-12-07 18:27:41 | [diff] [blame] | 473 | msg->description = std::move(description); |
Taylor Brandstetter | 5d97a9a | 2016-06-10 21:17:27 | [diff] [blame] | 474 | signaling_thread_->Post(RTC_FROM_HERE, this, |
| 475 | MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 476 | } |
| 477 | |
Henrik Boström | d03c23b | 2016-06-01 09:44:18 | [diff] [blame] | 478 | void WebRtcSessionDescriptionFactory::OnCertificateRequestFailed() { |
nisse | ede5da4 | 2017-01-12 13:15:36 | [diff] [blame] | 479 | RTC_DCHECK(signaling_thread_->IsCurrent()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 480 | |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 481 | RTC_LOG(LS_ERROR) << "Asynchronous certificate generation request failed."; |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 482 | certificate_request_state_ = CERTIFICATE_FAILED; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 483 | |
tommi | 0f620f4 | 2015-07-09 10:25:02 | [diff] [blame] | 484 | FailPendingRequests(kFailedDueToIdentityFailed); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 485 | } |
| 486 | |
Henrik Boström | d828198 | 2015-08-27 08:12:24 | [diff] [blame] | 487 | void WebRtcSessionDescriptionFactory::SetCertificate( |
| 488 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 489 | RTC_DCHECK(certificate); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 490 | RTC_LOG(LS_VERBOSE) << "Setting new certificate."; |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 | [diff] [blame] | 491 | |
Henrik Boström | 87713d0 | 2015-08-25 07:53:21 | [diff] [blame] | 492 | certificate_request_state_ = CERTIFICATE_SUCCEEDED; |
Harald Alvestrand | a094787 | 2020-11-09 14:15:00 | [diff] [blame] | 493 | |
| 494 | on_certificate_ready_(certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 495 | |
Henrik Boström | 3a14bf3 | 2015-08-31 07:27:58 | [diff] [blame] | 496 | transport_desc_factory_.set_certificate(certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 497 | transport_desc_factory_.set_secure(cricket::SEC_ENABLED); |
| 498 | |
| 499 | while (!create_session_description_requests_.empty()) { |
| 500 | if (create_session_description_requests_.front().type == |
| 501 | CreateSessionDescriptionRequest::kOffer) { |
| 502 | InternalCreateOffer(create_session_description_requests_.front()); |
| 503 | } else { |
| 504 | InternalCreateAnswer(create_session_description_requests_.front()); |
| 505 | } |
| 506 | create_session_description_requests_.pop(); |
| 507 | } |
| 508 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 | [diff] [blame] | 509 | } // namespace webrtc |