1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/MediaTransportParent.h"
#include "jsapi/MediaTransportHandler.h"
#include "transport/sigslot.h"
#include "common/browser_logging/CSFLog.h"
namespace mozilla {
// Deals with the MediaTransportHandler interface, so MediaTransportParent
// doesn't have to..
class MediaTransportParent::Impl : public sigslot::has_slots<> {
public:
explicit Impl(MediaTransportParent* aParent)
: mHandler(MediaTransportHandler::Create(GetCurrentSerialEventTarget())),
mParent(aParent) {
mHandler->SignalCandidate.connect(this,
&MediaTransportParent::Impl::OnCandidate);
mHandler->SignalAlpnNegotiated.connect(
this, &MediaTransportParent::Impl::OnAlpnNegotiated);
mHandler->SignalGatheringStateChange.connect(
this, &MediaTransportParent::Impl::OnGatheringStateChange);
mHandler->SignalConnectionStateChange.connect(
this, &MediaTransportParent::Impl::OnConnectionStateChange);
mHandler->SignalPacketReceived.connect(
this, &MediaTransportParent::Impl::OnPacketReceived);
mHandler->SignalEncryptedSending.connect(
this, &MediaTransportParent::Impl::OnEncryptedSending);
mHandler->SignalStateChange.connect(
this, &MediaTransportParent::Impl::OnStateChange);
mHandler->SignalRtcpStateChange.connect(
this, &MediaTransportParent::Impl::OnRtcpStateChange);
}
virtual ~Impl() {
disconnect_all();
mHandler = nullptr;
}
void OnCandidate(const std::string& aTransportId,
const CandidateInfo& aCandidateInfo) {
NS_ENSURE_TRUE_VOID(mParent->SendOnCandidate(aTransportId, aCandidateInfo));
}
void OnAlpnNegotiated(const std::string& aAlpn, bool aPrivacyRequested) {
NS_ENSURE_TRUE_VOID(mParent->SendOnAlpnNegotiated(aAlpn));
}
void OnGatheringStateChange(const std::string& aTransportId,
dom::RTCIceGathererState aState) {
NS_ENSURE_TRUE_VOID(mParent->SendOnGatheringStateChange(
aTransportId, static_cast<int>(aState)));
}
void OnConnectionStateChange(const std::string& aTransportId,
dom::RTCIceTransportState aState) {
NS_ENSURE_TRUE_VOID(mParent->SendOnConnectionStateChange(
aTransportId, static_cast<int>(aState)));
}
void OnPacketReceived(const std::string& aTransportId,
const MediaPacket& aPacket) {
NS_ENSURE_TRUE_VOID(mParent->SendOnPacketReceived(aTransportId, aPacket));
}
void OnEncryptedSending(const std::string& aTransportId,
const MediaPacket& aPacket) {
NS_ENSURE_TRUE_VOID(mParent->SendOnEncryptedSending(aTransportId, aPacket));
}
void OnStateChange(const std::string& aTransportId,
TransportLayer::State aState) {
NS_ENSURE_TRUE_VOID(mParent->SendOnStateChange(aTransportId, aState));
}
void OnRtcpStateChange(const std::string& aTransportId,
TransportLayer::State aState) {
NS_ENSURE_TRUE_VOID(mParent->SendOnRtcpStateChange(aTransportId, aState));
}
RefPtr<MediaTransportHandler> mHandler;
private:
MediaTransportParent* mParent;
};
MediaTransportParent::MediaTransportParent() : mImpl(new Impl(this)) {}
MediaTransportParent::~MediaTransportParent() {}
mozilla::ipc::IPCResult MediaTransportParent::RecvGetIceLog(
const nsCString& pattern, GetIceLogResolver&& aResolve) {
mImpl->mHandler->GetIceLog(pattern)->Then(
GetCurrentSerialEventTarget(), __func__,
// IPDL doesn't give us a reject function, so we cannot reject async, so
// we are forced to resolve with an empty result. Laaaaaaame.
[aResolve = std::move(aResolve)](
MediaTransportHandler::IceLogPromise::ResolveOrRejectValue&&
aResult) mutable {
WebrtcGlobalLog logLines;
if (aResult.IsResolve()) {
logLines = std::move(aResult.ResolveValue());
}
aResolve(logLines);
});
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvClearIceLog() {
mImpl->mHandler->ClearIceLog();
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvEnterPrivateMode() {
mImpl->mHandler->EnterPrivateMode();
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvExitPrivateMode() {
mImpl->mHandler->ExitPrivateMode();
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvCreateIceCtx(
const string& name) {
mImpl->mHandler->CreateIceCtx(name);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvSetIceConfig(
nsTArray<RTCIceServer>&& iceServers,
const RTCIceTransportPolicy& icePolicy) {
nsresult rv = mImpl->mHandler->SetIceConfig(iceServers, icePolicy);
if (NS_FAILED(rv)) {
return ipc::IPCResult::Fail(WrapNotNull(this), __func__,
"MediaTransportHandler::SetIceConfig failed");
}
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvSetProxyConfig(
const net::WebrtcProxyConfig& aProxyConfig) {
mImpl->mHandler->SetProxyConfig(NrSocketProxyConfig(aProxyConfig));
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvEnsureProvisionalTransport(
const string& transportId, const string& localUfrag, const string& localPwd,
const int& componentCount) {
mImpl->mHandler->EnsureProvisionalTransport(transportId, localUfrag, localPwd,
componentCount);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult
MediaTransportParent::RecvSetTargetForDefaultLocalAddressLookup(
const std::string& targetIp, uint16_t targetPort) {
mImpl->mHandler->SetTargetForDefaultLocalAddressLookup(targetIp, targetPort);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvStartIceGathering(
const bool& defaultRouteOnly, const bool& obfuscateHostAddresses,
const net::NrIceStunAddrArray& stunAddrs) {
mImpl->mHandler->StartIceGathering(defaultRouteOnly, obfuscateHostAddresses,
stunAddrs);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvActivateTransport(
const string& transportId, const string& localUfrag, const string& localPwd,
const int& componentCount, const string& remoteUfrag,
const string& remotePwd, nsTArray<uint8_t>&& keyDer,
nsTArray<uint8_t>&& certDer, const int& authType, const bool& dtlsClient,
const DtlsDigestList& digests, const bool& privacyRequested) {
mImpl->mHandler->ActivateTransport(
transportId, localUfrag, localPwd, componentCount, remoteUfrag, remotePwd,
keyDer, certDer, static_cast<SSLKEAType>(authType), dtlsClient, digests,
privacyRequested);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvRemoveTransportsExcept(
const StringVector& transportIds) {
std::set<std::string> ids(transportIds.begin(), transportIds.end());
mImpl->mHandler->RemoveTransportsExcept(ids);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvStartIceChecks(
const bool& isControlling, const StringVector& iceOptions) {
mImpl->mHandler->StartIceChecks(isControlling, iceOptions);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvSendPacket(
const string& transportId, MediaPacket&& packet) {
mImpl->mHandler->SendPacket(transportId, std::move(packet));
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvAddIceCandidate(
const string& transportId, const string& candidate, const string& ufrag,
const string& obfuscatedAddr) {
mImpl->mHandler->AddIceCandidate(transportId, candidate, ufrag,
obfuscatedAddr);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvUpdateNetworkState(
const bool& online) {
mImpl->mHandler->UpdateNetworkState(online);
return ipc::IPCResult::Ok();
}
mozilla::ipc::IPCResult MediaTransportParent::RecvGetIceStats(
const string& transportId, const double& now,
GetIceStatsResolver&& aResolve) {
mImpl->mHandler->GetIceStats(transportId, now)
->Then(
GetCurrentSerialEventTarget(), __func__,
// IPDL doesn't give us a reject function, so we cannot reject async,
// so we are forced to resolve with an unmodified result. Laaaaaaame.
[aResolve = std::move(aResolve)](
dom::RTCStatsPromise::ResolveOrRejectValue&& aResult) {
if (aResult.IsResolve()) {
aResolve(aResult.ResolveValue());
} else {
aResolve(MakeUnique<dom::RTCStatsCollection>());
}
});
return ipc::IPCResult::Ok();
}
} // namespace mozilla
|