react-native-webrtc 106.0.0-beta.7 → 106.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +7 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +145 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +25 -0
- package/ios/RCTWebRTC/DataChannelWrapper.h +2 -0
- package/ios/RCTWebRTC/DataChannelWrapper.m +6 -0
- package/ios/RCTWebRTC/SerializeUtils.h +2 -1
- package/ios/RCTWebRTC/SerializeUtils.m +51 -5
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +72 -60
- package/ios/RCTWebRTC/WebRTCModule.h +1 -1
- package/ios/RCTWebRTC/WebRTCModule.m +1 -1
- package/lib/commonjs/EventEmitter.js +29 -6
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +28 -17
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiver.js +19 -0
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +13 -0
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/index.js +5 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js +25 -5
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/RTCDataChannel.js +28 -17
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCRtpReceiver.js +17 -0
- package/lib/module/RTCRtpReceiver.js.map +1 -1
- package/lib/module/RTCRtpSender.js +13 -0
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +2 -3
- package/lib/typescript/RTCDataChannel.d.ts +2 -4
- package/lib/typescript/RTCRtpReceiver.d.ts +1 -0
- package/lib/typescript/RTCRtpSender.d.ts +1 -0
- package/package.json +1 -1
- package/src/EventEmitter.ts +36 -4
- package/src/RTCDataChannel.ts +62 -47
- package/src/RTCRtpReceiver.ts +17 -0
- package/src/RTCRtpSender.ts +14 -0
- package/src/index.ts +4 -0
|
@@ -53,7 +53,12 @@ class DataChannelWrapper implements DataChannel.Observer {
|
|
|
53
53
|
|
|
54
54
|
@Override
|
|
55
55
|
public void onBufferedAmountChange(long amount) {
|
|
56
|
-
|
|
56
|
+
WritableMap params = Arguments.createMap();
|
|
57
|
+
params.putString("reactTag", reactTag);
|
|
58
|
+
params.putInt("peerConnectionId", peerConnectionId);
|
|
59
|
+
params.putDouble("bufferedAmount", Long.valueOf(amount).doubleValue());
|
|
60
|
+
|
|
61
|
+
webRTCModule.sendEvent("dataChannelDidChangeBufferedAmount", params);
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
@Override
|
|
@@ -92,6 +97,7 @@ class DataChannelWrapper implements DataChannel.Observer {
|
|
|
92
97
|
params.putInt("peerConnectionId", peerConnectionId);
|
|
93
98
|
params.putInt("id", mDataChannel.id());
|
|
94
99
|
params.putString("state", dataChannelStateString(mDataChannel.state()));
|
|
100
|
+
|
|
95
101
|
webRTCModule.sendEvent("dataChannelStateChanged", params);
|
|
96
102
|
}
|
|
97
103
|
}
|
|
@@ -19,6 +19,8 @@ import org.webrtc.IceCandidate;
|
|
|
19
19
|
import org.webrtc.MediaStream;
|
|
20
20
|
import org.webrtc.MediaStreamTrack;
|
|
21
21
|
import org.webrtc.PeerConnection;
|
|
22
|
+
import org.webrtc.RTCStats;
|
|
23
|
+
import org.webrtc.RTCStatsReport;
|
|
22
24
|
import org.webrtc.RtpReceiver;
|
|
23
25
|
import org.webrtc.RtpSender;
|
|
24
26
|
import org.webrtc.RtpTransceiver;
|
|
@@ -29,11 +31,14 @@ import java.io.UnsupportedEncodingException;
|
|
|
29
31
|
import java.nio.ByteBuffer;
|
|
30
32
|
import java.nio.charset.StandardCharsets;
|
|
31
33
|
import java.util.ArrayList;
|
|
34
|
+
import java.util.Arrays;
|
|
32
35
|
import java.util.HashMap;
|
|
36
|
+
import java.util.HashSet;
|
|
33
37
|
import java.util.Iterator;
|
|
34
38
|
import java.util.List;
|
|
35
39
|
import java.util.Map;
|
|
36
40
|
import java.util.Objects;
|
|
41
|
+
import java.util.Set;
|
|
37
42
|
import java.util.UUID;
|
|
38
43
|
|
|
39
44
|
class PeerConnectionObserver implements PeerConnection.Observer {
|
|
@@ -239,6 +244,146 @@ class PeerConnectionObserver implements PeerConnection.Observer {
|
|
|
239
244
|
});
|
|
240
245
|
}
|
|
241
246
|
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param trackIdentifier sender or receiver id
|
|
250
|
+
* @param streamType "outbound-rtp" for sender or "inbound-rtp" for receiver
|
|
251
|
+
*/
|
|
252
|
+
void getFilteredStats(String trackIdentifier, boolean isReceiver, Promise promise) {
|
|
253
|
+
|
|
254
|
+
peerConnection.getStats(rtcStatsReport -> {
|
|
255
|
+
Map<String, RTCStats> statsMap = rtcStatsReport.getStatsMap();
|
|
256
|
+
Set<RTCStats> filteredStats = new HashSet<>();
|
|
257
|
+
// Get track stats
|
|
258
|
+
RTCStats trackStats = getTrackStats(trackIdentifier, statsMap);
|
|
259
|
+
if (trackStats == null) {
|
|
260
|
+
Log.w(TAG, "getStats: couldn't find track stats!");
|
|
261
|
+
RTCStatsReport report = new RTCStatsReport((long) rtcStatsReport.getTimestampUs(), new HashMap<>());
|
|
262
|
+
promise.resolve(StringUtils.statsToJSON(report));
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
filteredStats.add(trackStats);
|
|
267
|
+
String trackId = trackStats.getId();
|
|
268
|
+
|
|
269
|
+
// Get stream stats
|
|
270
|
+
RTCStats streamStats = getStreamStats(trackId, statsMap);
|
|
271
|
+
if (streamStats != null) {
|
|
272
|
+
filteredStats.add(streamStats);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Get streamType stats and associated information
|
|
276
|
+
Set<Long> ssrcs = new HashSet<>();
|
|
277
|
+
Set<String> codecIds = new HashSet<>();
|
|
278
|
+
|
|
279
|
+
String streamType;
|
|
280
|
+
if (isReceiver) {
|
|
281
|
+
streamType = "inbound-rtp";
|
|
282
|
+
} else {
|
|
283
|
+
streamType = "outbound-rtp";
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
for (RTCStats stats : statsMap.values()) {
|
|
287
|
+
if (stats.getType().equals(streamType) && trackId.equals(stats.getMembers().get("trackId"))) {
|
|
288
|
+
ssrcs.add((Long) stats.getMembers().get("ssrc"));
|
|
289
|
+
codecIds.add((String) stats.getMembers().get("codecId"));
|
|
290
|
+
filteredStats.add(stats);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
// Get candidate information
|
|
296
|
+
RTCStats candidatePairStats = null;
|
|
297
|
+
for (RTCStats stats : statsMap.values()) {
|
|
298
|
+
if (stats.getType().equals("candidate-pair") && stats.getMembers().get("nominated").equals(true)) {
|
|
299
|
+
candidatePairStats = stats;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
String localCandidateId = null;
|
|
305
|
+
String remoteCandidateId = null;
|
|
306
|
+
if (candidatePairStats != null) {
|
|
307
|
+
filteredStats.add(candidatePairStats);
|
|
308
|
+
localCandidateId = (String) candidatePairStats.getMembers().get("localCandidateId");
|
|
309
|
+
remoteCandidateId = (String) candidatePairStats.getMembers().get("remoteCandidateId");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Sweep for any remaining stats we want.
|
|
313
|
+
filteredStats.addAll(getExtraStats(trackIdentifier, ssrcs, codecIds, localCandidateId, remoteCandidateId, statsMap));
|
|
314
|
+
|
|
315
|
+
Map<String, RTCStats> filteredStatsMap = new HashMap<>();
|
|
316
|
+
for (RTCStats stats : filteredStats) {
|
|
317
|
+
filteredStatsMap.put(stats.getId(), stats);
|
|
318
|
+
}
|
|
319
|
+
RTCStatsReport filteredStatsReport = new RTCStatsReport((long) rtcStatsReport.getTimestampUs(), filteredStatsMap);
|
|
320
|
+
promise.resolve(StringUtils.statsToJSON(filteredStatsReport));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Note: trackIdentifier can differ from the internal stats trackId
|
|
325
|
+
// trackIdentifier refers to the sender or receiver id
|
|
326
|
+
@Nullable
|
|
327
|
+
private RTCStats getTrackStats(String trackIdentifier, Map<String, RTCStats> statsMap) {
|
|
328
|
+
for (RTCStats stats : statsMap.values()) {
|
|
329
|
+
if (stats.getType().equals("track") && trackIdentifier.equals(stats.getMembers().get("trackIdentifier"))) {
|
|
330
|
+
return stats;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
@Nullable
|
|
338
|
+
private RTCStats getStreamStats(String trackId, Map<String, RTCStats> statsMap) {
|
|
339
|
+
for (RTCStats stats : statsMap.values()) {
|
|
340
|
+
if (stats.getType().equals("stream")
|
|
341
|
+
&& Arrays.asList((String[]) stats.getMembers().get("trackIds")).contains(trackId)) {
|
|
342
|
+
return stats;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Note: trackIdentifier can differ from the internal stats trackId
|
|
349
|
+
// trackIdentifier refers to the sender or receiver id
|
|
350
|
+
public Set<RTCStats> getExtraStats(
|
|
351
|
+
String trackIdentifier,
|
|
352
|
+
Set<Long> ssrcs,
|
|
353
|
+
Set<String> codecIds,
|
|
354
|
+
@Nullable String localCandidateId,
|
|
355
|
+
@Nullable String remoteCandidateId,
|
|
356
|
+
Map<String, RTCStats> statsMap) {
|
|
357
|
+
Set<RTCStats> extraStats = new HashSet<>();
|
|
358
|
+
for (RTCStats stats : statsMap.values()) {
|
|
359
|
+
switch (stats.getType()) {
|
|
360
|
+
case "certificate":
|
|
361
|
+
case "transport":
|
|
362
|
+
extraStats.add(stats);
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (stats.getId().equals(localCandidateId) || stats.getId().equals(remoteCandidateId)) {
|
|
367
|
+
extraStats.add(stats);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (ssrcs.contains(stats.getMembers().get("ssrc"))) {
|
|
372
|
+
extraStats.add(stats);
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (trackIdentifier.equals(stats.getMembers().get("trackIdentifier"))) {
|
|
376
|
+
extraStats.add(stats);
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (codecIds.contains(stats.getId())) {
|
|
380
|
+
extraStats.add(stats);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return extraStats;
|
|
385
|
+
}
|
|
386
|
+
|
|
242
387
|
@Override
|
|
243
388
|
public void onIceCandidate(final IceCandidate candidate) {
|
|
244
389
|
Log.d(TAG, "onIceCandidate");
|
|
@@ -1143,6 +1143,31 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
}
|
|
1145
1145
|
|
|
1146
|
+
@ReactMethod
|
|
1147
|
+
public void receiverGetStats(int pcId, String receiverId, Promise promise) {
|
|
1148
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
1149
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
|
|
1150
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
1151
|
+
Log.d(TAG, "peerConnectionGetStats() peerConnection is null");
|
|
1152
|
+
promise.reject(new Exception("PeerConnection ID not found"));
|
|
1153
|
+
} else {
|
|
1154
|
+
pco.getFilteredStats(receiverId, true, promise);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
@ReactMethod
|
|
1159
|
+
public void senderGetStats(int pcId, String senderId, Promise promise) {
|
|
1160
|
+
ThreadUtils.runOnExecutor(() -> {
|
|
1161
|
+
PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
|
|
1162
|
+
if (pco == null || pco.getPeerConnection() == null) {
|
|
1163
|
+
Log.d(TAG, "peerConnectionGetStats() peerConnection is null");
|
|
1164
|
+
promise.reject(new Exception("PeerConnection ID not found"));
|
|
1165
|
+
} else {
|
|
1166
|
+
pco.getFilteredStats(senderId, false, promise);
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1146
1171
|
@ReactMethod
|
|
1147
1172
|
public void peerConnectionAddICECandidate(int pcId,
|
|
1148
1173
|
ReadableMap candidateMap,
|
|
@@ -11,6 +11,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
11
11
|
- (void)dataChannelDidChangeState:(DataChannelWrapper *)dataChannelWrapper;
|
|
12
12
|
- (void)dataChannel:(DataChannelWrapper *)dataChannelWrapper
|
|
13
13
|
didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer;
|
|
14
|
+
- (void)dataChannel:(DataChannelWrapper *)dataChannelWrapper
|
|
15
|
+
didChangeBufferedAmount:(uint64_t)amount;
|
|
14
16
|
|
|
15
17
|
@end
|
|
16
18
|
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
+ (NSDictionary *_Nonnull)trackToJSONWithPeerConnectionId: (nonnull NSNumber *) id
|
|
16
16
|
track: (RTCMediaStreamTrack *_Nonnull) track;
|
|
17
17
|
+ (NSString *_Nonnull)serializeDirection: (RTCRtpTransceiverDirection) direction;
|
|
18
|
-
+ (RTCRtpTransceiverDirection)
|
|
18
|
+
+ (RTCRtpTransceiverDirection)parseDirection: (NSString *_Nonnull) direction;
|
|
19
|
+
+ (RTCRtpTransceiverInit *_Nonnull)parseTransceiverOptions: (NSDictionary *_Nonnull) parameters;
|
|
19
20
|
+ (NSDictionary *_Nonnull)parametersToJSON: (RTCRtpParameters *_Nonnull) parameters;
|
|
20
21
|
+ (NSMutableArray *_Nonnull)constructTransceiversInfoArrayWithPeerConnection: (RTCPeerConnection *_Nonnull) peerConnection
|
|
21
22
|
peerConnectionId: (NSNumber *_Nonnull) peerConnectionId;
|
|
@@ -193,21 +193,67 @@
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
+ (RTCRtpTransceiverDirection) parseDirection: (NSString *) direction {
|
|
196
|
-
if ([direction
|
|
196
|
+
if ([direction isEqual: @"inactive"]) {
|
|
197
197
|
return RTCRtpTransceiverDirectionInactive;
|
|
198
|
-
} else if ([direction
|
|
198
|
+
} else if ([direction isEqual: @"recvonly"]) {
|
|
199
199
|
return RTCRtpTransceiverDirectionRecvOnly;
|
|
200
|
-
} else if ([direction
|
|
200
|
+
} else if ([direction isEqual: @"sendonly"]) {
|
|
201
201
|
return RTCRtpTransceiverDirectionSendOnly;
|
|
202
|
-
} else if ([direction
|
|
202
|
+
} else if ([direction isEqual: @"sendrecv"]) {
|
|
203
203
|
return RTCRtpTransceiverDirectionSendRecv;
|
|
204
|
-
} else if ([direction
|
|
204
|
+
} else if ([direction isEqual: @"stopped"]) {
|
|
205
205
|
return RTCRtpTransceiverDirectionStopped;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
208
|
return RTCRtpTransceiverDirectionInactive;
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
+ (RTCRtpEncodingParameters *) parseEncoding: (NSDictionary *) params {
|
|
212
|
+
RTCRtpEncodingParameters *encoding = [RTCRtpEncodingParameters new];
|
|
213
|
+
|
|
214
|
+
if (params[@"rid"] != nil) {
|
|
215
|
+
[encoding setRid: params[@"rid"]];
|
|
216
|
+
}
|
|
217
|
+
if (params[@"active"] != nil) {
|
|
218
|
+
[encoding setIsActive: ((NSNumber *) params[@"active"]).boolValue];
|
|
219
|
+
}
|
|
220
|
+
if (params[@"maxBitrate"] != nil) {
|
|
221
|
+
[encoding setMaxBitrateBps: (NSNumber *) params[@"maxBitrate"]];
|
|
222
|
+
}
|
|
223
|
+
if (params[@"maxFramerate"] != nil) {
|
|
224
|
+
[encoding setMaxFramerate: (NSNumber *) params[@"maxFramerate"]];
|
|
225
|
+
}
|
|
226
|
+
if (params[@"scaleResolutionDownBy"] != nil) {
|
|
227
|
+
[encoding setScaleResolutionDownBy: (NSNumber *) params[@"scaleResolutionDownBy"]];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return encoding;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
+ (RTCRtpTransceiverInit *) parseTransceiverOptions: (NSDictionary *) params {
|
|
234
|
+
RTCRtpTransceiverInit *transceiverInit = [RTCRtpTransceiverInit new];
|
|
235
|
+
|
|
236
|
+
NSString *direction = [params objectForKey: @"direction"];
|
|
237
|
+
if (direction) {
|
|
238
|
+
[transceiverInit setDirection: [SerializeUtils parseDirection: direction]];
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
NSArray *streamIds = [params objectForKey: @"streamIds"];
|
|
242
|
+
if (streamIds) {
|
|
243
|
+
[transceiverInit setStreamIds: streamIds];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
NSArray *encodingsArray = [params objectForKey: @"sendEncodings"];
|
|
247
|
+
if (encodingsArray) {
|
|
248
|
+
NSMutableArray<RTCRtpEncodingParameters *> *sendEncodings = [NSMutableArray new];
|
|
249
|
+
for (NSDictionary* encoding in encodingsArray) {
|
|
250
|
+
[sendEncodings addObject: [self parseEncoding: encoding]];
|
|
251
|
+
}
|
|
252
|
+
[transceiverInit setSendEncodings: sendEncodings];
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return transceiverInit;
|
|
256
|
+
}
|
|
211
257
|
|
|
212
258
|
+ (NSDictionary *)streamToJSONWithPeerConnectionId: (NSNumber *) id
|
|
213
259
|
stream: (RTCMediaStream *) stream
|
|
@@ -149,4 +149,12 @@ RCT_EXPORT_METHOD(dataChannelSend:(nonnull NSNumber *)peerConnectionId
|
|
|
149
149
|
[self sendEventWithName:kEventDataChannelReceiveMessage body:event];
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
+
- (void)dataChannel:(DataChannelWrapper *)dcw didChangeBufferedAmount:(uint64_t)amount
|
|
153
|
+
{
|
|
154
|
+
NSDictionary *event = @{@"reactTag": dcw.reactTag,
|
|
155
|
+
@"peerConnectionId": dcw.pcId,
|
|
156
|
+
@"bufferedAmount": [NSNumber numberWithUnsignedLongLong:amount]};
|
|
157
|
+
[self sendEventWithName:kEventDataChannelDidChangeBufferedAmount body:event];
|
|
158
|
+
}
|
|
159
|
+
|
|
152
160
|
@end
|
|
@@ -357,6 +357,64 @@ RCT_EXPORT_METHOD(peerConnectionGetStats:(nonnull NSNumber *) objectID
|
|
|
357
357
|
}];
|
|
358
358
|
}
|
|
359
359
|
|
|
360
|
+
RCT_EXPORT_METHOD(receiverGetStats:(nonnull NSNumber *) pcId
|
|
361
|
+
receiverId:(nonnull NSString *) receiverId
|
|
362
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
363
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
364
|
+
{
|
|
365
|
+
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
|
|
366
|
+
if (!peerConnection) {
|
|
367
|
+
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
RTCRtpReceiver *receiver;
|
|
372
|
+
for (RTCRtpReceiver *findRecv in peerConnection.receivers) {
|
|
373
|
+
if ([findRecv.receiverId isEqualToString:receiverId]) {
|
|
374
|
+
receiver = findRecv;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (!receiver) {
|
|
380
|
+
reject(@"invalid_id", @"Receiver ID not found", nil);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
[peerConnection statisticsForReceiver:receiver completionHandler:^(RTCStatisticsReport *report) {
|
|
385
|
+
resolve([self statsToJSON:report]);
|
|
386
|
+
}];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
RCT_EXPORT_METHOD(senderGetStats:(nonnull NSNumber *) pcId
|
|
390
|
+
senderId:(nonnull NSString *) senderId
|
|
391
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
392
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
393
|
+
{
|
|
394
|
+
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
|
|
395
|
+
if (!peerConnection) {
|
|
396
|
+
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
RTCRtpSender *sender;
|
|
401
|
+
for (RTCRtpSender *findSend in peerConnection.senders) {
|
|
402
|
+
if ([findSend.senderId isEqualToString:senderId]) {
|
|
403
|
+
sender = findSend;
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if(!sender) {
|
|
409
|
+
reject(@"invalid_id", @"Sender ID not found", nil);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
[peerConnection statisticsForSender:sender completionHandler:^(RTCStatisticsReport *report) {
|
|
414
|
+
resolve([self statsToJSON:report]);
|
|
415
|
+
}];
|
|
416
|
+
}
|
|
417
|
+
|
|
360
418
|
RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
361
419
|
{
|
|
362
420
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
@@ -426,50 +484,27 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
|
|
|
426
484
|
RTCRtpMediaType type = RTCRtpMediaTypeUnsupported;
|
|
427
485
|
|
|
428
486
|
if (kind) {
|
|
429
|
-
if ([kind
|
|
487
|
+
if ([kind isEqual: @"audio"]) {
|
|
430
488
|
type = RTCRtpMediaTypeAudio;
|
|
431
|
-
} else if ([kind
|
|
489
|
+
} else if ([kind isEqual: @"video"]) {
|
|
432
490
|
type = RTCRtpMediaTypeVideo;
|
|
433
491
|
}
|
|
434
|
-
|
|
492
|
+
|
|
493
|
+
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
494
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
495
|
+
|
|
496
|
+
transceiver = [peerConnection addTransceiverOfType: type init: transceiverInit];
|
|
435
497
|
} else if (trackId) {
|
|
436
498
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
437
499
|
|
|
438
|
-
if(!track) {
|
|
500
|
+
if (!track) {
|
|
439
501
|
track = peerConnection.remoteTracks[trackId];
|
|
440
502
|
}
|
|
441
503
|
|
|
442
|
-
NSDictionary *initOptions = [options objectForKey
|
|
443
|
-
RTCRtpTransceiverInit *transceiverInit = [
|
|
444
|
-
|
|
445
|
-
if (initOptions) {
|
|
446
|
-
NSString *dirrection = [initOptions objectForKey:@"direction"];
|
|
447
|
-
if ([dirrection isEqual: @"sendrecv"]) {
|
|
448
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendRecv];
|
|
449
|
-
} else if ([dirrection isEqual: @"sendonly"]) {
|
|
450
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendOnly];
|
|
451
|
-
} else if ([dirrection isEqual: @"recvonly"]) {
|
|
452
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionRecvOnly];
|
|
453
|
-
} else if ([dirrection isEqual: @"inactive"]) {
|
|
454
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionInactive];
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
NSArray *streamIds = [initOptions objectForKey:@"streamIds"];
|
|
458
|
-
if (streamIds) {
|
|
459
|
-
[transceiverInit setStreamIds:streamIds];
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
NSArray *encodingsArray = [initOptions objectForKey:@"sendEncodings"];
|
|
463
|
-
if (encodingsArray) {
|
|
464
|
-
NSMutableArray<RTCRtpEncodingParameters *> *sendEncodings = [NSMutableArray new];
|
|
465
|
-
for (NSDictionary* encoding in encodingsArray) {
|
|
466
|
-
[sendEncodings addObject:[self parseEncoding:encoding]];
|
|
467
|
-
}
|
|
468
|
-
[transceiverInit setSendEncodings:sendEncodings];
|
|
469
|
-
}
|
|
470
|
-
}
|
|
504
|
+
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
505
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
471
506
|
|
|
472
|
-
transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
|
|
507
|
+
transceiver = [peerConnection addTransceiverWithTrack: track init: transceiverInit];
|
|
473
508
|
} else {
|
|
474
509
|
RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
475
510
|
return;
|
|
@@ -481,8 +516,8 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
|
|
|
481
516
|
}
|
|
482
517
|
|
|
483
518
|
params = @{
|
|
484
|
-
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
485
|
-
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver
|
|
519
|
+
@"transceiverOrder": [NSNumber numberWithInt: _transceiverNextId++],
|
|
520
|
+
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver]
|
|
486
521
|
};
|
|
487
522
|
});
|
|
488
523
|
|
|
@@ -521,30 +556,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
521
556
|
return @(ret);
|
|
522
557
|
}
|
|
523
558
|
|
|
524
|
-
// TODO: move these below to some
|
|
525
|
-
|
|
526
|
-
- (RTCRtpEncodingParameters*)parseEncoding:(NSDictionary*)params
|
|
527
|
-
{
|
|
528
|
-
RTCRtpEncodingParameters *encoding = [RTCRtpEncodingParameters new];
|
|
529
|
-
|
|
530
|
-
if (params[@"rid"] != nil) {
|
|
531
|
-
[encoding setRid:params[@"rid"]];
|
|
532
|
-
}
|
|
533
|
-
if (params[@"active"] != nil) {
|
|
534
|
-
[encoding setIsActive:((NSNumber*)params[@"active"]).boolValue];
|
|
535
|
-
}
|
|
536
|
-
if (params[@"maxBitrate"] != nil) {
|
|
537
|
-
[encoding setMaxBitrateBps:(NSNumber*)params[@"maxBitrate"]];
|
|
538
|
-
}
|
|
539
|
-
if (params[@"maxFramerate"] != nil) {
|
|
540
|
-
[encoding setMaxFramerate:(NSNumber*)params[@"maxFramerate"]];
|
|
541
|
-
}
|
|
542
|
-
if (params[@"scaleResolutionDownBy"] != nil) {
|
|
543
|
-
[encoding setScaleResolutionDownBy:(NSNumber*)params[@"scaleResolutionDownBy"]];
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
return encoding;
|
|
547
|
-
}
|
|
559
|
+
// TODO: move these below to some SerializeUtils file
|
|
548
560
|
|
|
549
561
|
/**
|
|
550
562
|
* Constructs a JSON <tt>NSString</tt> representation of a specific
|
|
@@ -27,10 +27,10 @@ static NSString *const kEventPeerConnectionIceConnectionChanged = @"peerConnecti
|
|
|
27
27
|
static NSString *const kEventPeerConnectionIceGatheringChanged = @"peerConnectionIceGatheringChanged";
|
|
28
28
|
static NSString *const kEventPeerConnectionGotICECandidate = @"peerConnectionGotICECandidate";
|
|
29
29
|
static NSString *const kEventPeerConnectionDidOpenDataChannel = @"peerConnectionDidOpenDataChannel";
|
|
30
|
+
static NSString *const kEventDataChannelDidChangeBufferedAmount = @"dataChannelDidChangeBufferedAmount";
|
|
30
31
|
static NSString *const kEventDataChannelStateChanged = @"dataChannelStateChanged";
|
|
31
32
|
static NSString *const kEventDataChannelReceiveMessage = @"dataChannelReceiveMessage";
|
|
32
33
|
static NSString *const kEventMediaStreamTrackMuteChanged = @"mediaStreamTrackMuteChanged";
|
|
33
|
-
static NSString *const kEventTransceiverOnError = @"transceiverOnError";
|
|
34
34
|
static NSString *const kEventPeerConnectionOnRemoveTrack = @"peerConnectionOnRemoveTrack";
|
|
35
35
|
static NSString *const kEventPeerConnectionOnTrack = @"peerConnectionOnTrack";
|
|
36
36
|
|
|
@@ -110,10 +110,10 @@ RCT_EXPORT_MODULE();
|
|
|
110
110
|
kEventPeerConnectionIceGatheringChanged,
|
|
111
111
|
kEventPeerConnectionGotICECandidate,
|
|
112
112
|
kEventPeerConnectionDidOpenDataChannel,
|
|
113
|
+
kEventDataChannelDidChangeBufferedAmount,
|
|
113
114
|
kEventDataChannelStateChanged,
|
|
114
115
|
kEventDataChannelReceiveMessage,
|
|
115
116
|
kEventMediaStreamTrackMuteChanged,
|
|
116
|
-
kEventTransceiverOnError,
|
|
117
117
|
kEventPeerConnectionOnRemoveTrack,
|
|
118
118
|
kEventPeerConnectionOnTrack
|
|
119
119
|
];
|
|
@@ -4,28 +4,51 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.addListener = addListener;
|
|
7
|
-
exports.default = void 0;
|
|
8
7
|
exports.removeListener = removeListener;
|
|
8
|
+
exports.setupNativeEvents = setupNativeEvents;
|
|
9
9
|
|
|
10
10
|
var _reactNative = require("react-native");
|
|
11
11
|
|
|
12
|
+
var _EventEmitter = _interopRequireDefault(require("react-native/Libraries/vendor/emitter/EventEmitter"));
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// @ts-ignore
|
|
12
17
|
const {
|
|
13
18
|
WebRTCModule
|
|
14
|
-
} = _reactNative.NativeModules;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
} = _reactNative.NativeModules; // This emitter is going to be used to listen to all the native events (once) and then
|
|
20
|
+
// re-emit them on a JS-only emitter.
|
|
21
|
+
|
|
22
|
+
const nativeEmitter = new _reactNative.NativeEventEmitter(WebRTCModule);
|
|
23
|
+
const NATIVE_EVENTS = ['peerConnectionSignalingStateChanged', 'peerConnectionStateChanged', 'peerConnectionOnRenegotiationNeeded', 'peerConnectionIceConnectionChanged', 'peerConnectionIceGatheringChanged', 'peerConnectionGotICECandidate', 'peerConnectionDidOpenDataChannel', 'peerConnectionOnRemoveTrack', 'peerConnectionOnTrack', 'dataChannelStateChanged', 'dataChannelReceiveMessage', 'dataChannelDidChangeBufferedAmount', 'mediaStreamTrackMuteChanged'];
|
|
24
|
+
const eventEmitter = new _EventEmitter.default();
|
|
25
|
+
|
|
26
|
+
function setupNativeEvents() {
|
|
27
|
+
for (const eventName of NATIVE_EVENTS) {
|
|
28
|
+
nativeEmitter.addListener(eventName, function () {
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
args[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
eventEmitter.emit(eventName, ...args);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
18
37
|
|
|
19
38
|
const _subscriptions = new Map();
|
|
20
39
|
|
|
21
40
|
function addListener(listener, eventName, eventHandler) {
|
|
22
41
|
var _subscriptions$get;
|
|
23
42
|
|
|
43
|
+
if (!NATIVE_EVENTS.includes(eventName)) {
|
|
44
|
+
throw new Error(`Invalid event: ${eventName}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
24
47
|
if (!_subscriptions.has(listener)) {
|
|
25
48
|
_subscriptions.set(listener, []);
|
|
26
49
|
}
|
|
27
50
|
|
|
28
|
-
(_subscriptions$get = _subscriptions.get(listener)) === null || _subscriptions$get === void 0 ? void 0 : _subscriptions$get.push(
|
|
51
|
+
(_subscriptions$get = _subscriptions.get(listener)) === null || _subscriptions$get === void 0 ? void 0 : _subscriptions$get.push(eventEmitter.addListener(eventName, eventHandler));
|
|
29
52
|
}
|
|
30
53
|
|
|
31
54
|
function removeListener(listener) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["EventEmitter.ts"],"names":["WebRTCModule","NativeModules","
|
|
1
|
+
{"version":3,"sources":["EventEmitter.ts"],"names":["WebRTCModule","NativeModules","nativeEmitter","NativeEventEmitter","NATIVE_EVENTS","eventEmitter","EventEmitter","setupNativeEvents","eventName","addListener","args","emit","_subscriptions","Map","listener","eventHandler","includes","Error","has","set","get","push","removeListener","forEach","sub","remove","delete"],"mappings":";;;;;;;;;AAAA;;AAEA;;;;AADA;AAGA,MAAM;AAAEA,EAAAA;AAAF,IAAmBC,0BAAzB,C,CAEA;AACA;;AACA,MAAMC,aAAa,GAAG,IAAIC,+BAAJ,CAAuBH,YAAvB,CAAtB;AAEA,MAAMI,aAAa,GAAG,CAClB,qCADkB,EAElB,4BAFkB,EAGlB,qCAHkB,EAIlB,oCAJkB,EAKlB,mCALkB,EAMlB,+BANkB,EAOlB,kCAPkB,EAQlB,6BARkB,EASlB,uBATkB,EAUlB,yBAVkB,EAWlB,2BAXkB,EAYlB,oCAZkB,EAalB,6BAbkB,CAAtB;AAgBA,MAAMC,YAAY,GAAG,IAAIC,qBAAJ,EAArB;;AAEO,SAASC,iBAAT,GAA6B;AAChC,OAAK,MAAMC,SAAX,IAAwBJ,aAAxB,EAAuC;AACnCF,IAAAA,aAAa,CAACO,WAAd,CAA0BD,SAA1B,EAAqC,YAAa;AAAA,wCAATE,IAAS;AAATA,QAAAA,IAAS;AAAA;;AAC9CL,MAAAA,YAAY,CAACM,IAAb,CAAkBH,SAAlB,EAA6B,GAAGE,IAAhC;AACH,KAFD;AAGH;AACJ;;AAKD,MAAME,cAAoD,GAAG,IAAIC,GAAJ,EAA7D;;AAEO,SAASJ,WAAT,CAAqBK,QAArB,EAAyCN,SAAzC,EAA4DO,YAA5D,EAA8F;AAAA;;AACjG,MAAI,CAACX,aAAa,CAACY,QAAd,CAAuBR,SAAvB,CAAL,EAAwC;AACpC,UAAM,IAAIS,KAAJ,CAAW,kBAAiBT,SAAU,EAAtC,CAAN;AACH;;AAED,MAAI,CAACI,cAAc,CAACM,GAAf,CAAmBJ,QAAnB,CAAL,EAAmC;AAC/BF,IAAAA,cAAc,CAACO,GAAf,CAAmBL,QAAnB,EAA6B,EAA7B;AACH;;AAED,wBAAAF,cAAc,CAACQ,GAAf,CAAmBN,QAAnB,2EAA8BO,IAA9B,CAAmChB,YAAY,CAACI,WAAb,CAAyBD,SAAzB,EAAoCO,YAApC,CAAnC;AACH;;AAEM,SAASO,cAAT,CAAwBR,QAAxB,EAAkD;AAAA;;AACrD,yBAAAF,cAAc,CAACQ,GAAf,CAAmBN,QAAnB,6EAA8BS,OAA9B,CAAsCC,GAAG,IAAI;AACzCA,IAAAA,GAAG,CAACC,MAAJ;AACH,GAFD;;AAIAb,EAAAA,cAAc,CAACc,MAAf,CAAsBZ,QAAtB;AACH","sourcesContent":["import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';\n// @ts-ignore\nimport EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';\n\nconst { WebRTCModule } = NativeModules;\n\n// This emitter is going to be used to listen to all the native events (once) and then\n// re-emit them on a JS-only emitter.\nconst nativeEmitter = new NativeEventEmitter(WebRTCModule);\n\nconst NATIVE_EVENTS = [\n 'peerConnectionSignalingStateChanged',\n 'peerConnectionStateChanged',\n 'peerConnectionOnRenegotiationNeeded',\n 'peerConnectionIceConnectionChanged',\n 'peerConnectionIceGatheringChanged',\n 'peerConnectionGotICECandidate',\n 'peerConnectionDidOpenDataChannel',\n 'peerConnectionOnRemoveTrack',\n 'peerConnectionOnTrack',\n 'dataChannelStateChanged',\n 'dataChannelReceiveMessage',\n 'dataChannelDidChangeBufferedAmount',\n 'mediaStreamTrackMuteChanged',\n];\n\nconst eventEmitter = new EventEmitter();\n\nexport function setupNativeEvents() {\n for (const eventName of NATIVE_EVENTS) {\n nativeEmitter.addListener(eventName, (...args) => {\n eventEmitter.emit(eventName, ...args);\n });\n }\n}\n\ntype EventHandler = (event: unknown) => void;\ntype Listener = unknown;\n\nconst _subscriptions: Map<Listener, EmitterSubscription[]> = new Map();\n\nexport function addListener(listener: Listener, eventName: string, eventHandler: EventHandler): void {\n if (!NATIVE_EVENTS.includes(eventName)) {\n throw new Error(`Invalid event: ${eventName}`);\n }\n\n if (!_subscriptions.has(listener)) {\n _subscriptions.set(listener, []);\n }\n\n _subscriptions.get(listener)?.push(eventEmitter.addListener(eventName, eventHandler));\n}\n\nexport function removeListener(listener: Listener): void {\n _subscriptions.get(listener)?.forEach(sub => {\n sub.remove();\n });\n\n _subscriptions.delete(listener);\n}\n"]}
|