react-native-webrtc 106.0.0-beta.6 → 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/GetUserMediaImpl.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +145 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +45 -6
- package/ios/RCTWebRTC/DataChannelWrapper.h +2 -0
- package/ios/RCTWebRTC/DataChannelWrapper.m +6 -0
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +10 -0
- package/ios/RCTWebRTC/SerializeUtils.h +2 -1
- package/ios/RCTWebRTC/SerializeUtils.m +55 -7
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +91 -72
- 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/MediaStreamTrack.js +8 -7
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +28 -17
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js +14 -4
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +40 -26
- package/lib/commonjs/RTCPeerConnection.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/RTCRtpTransceiver.js +2 -9
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCView.js +0 -55
- package/lib/commonjs/RTCView.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/MediaStreamTrack.js +8 -7
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCDataChannel.js +28 -17
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCIceCandidate.js +14 -4
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +40 -26
- package/lib/module/RTCPeerConnection.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/RTCRtpTransceiver.js +2 -9
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCView.js +0 -49
- package/lib/module/RTCView.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/MediaStreamTrack.d.ts +2 -1
- package/lib/typescript/RTCDataChannel.d.ts +2 -4
- package/lib/typescript/RTCIceCandidate.d.ts +5 -1
- package/lib/typescript/RTCRtpReceiver.d.ts +1 -0
- package/lib/typescript/RTCRtpSender.d.ts +1 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +0 -3
- package/lib/typescript/RTCView.d.ts +53 -46
- package/package.json +1 -1
- package/src/EventEmitter.ts +36 -4
- package/src/MediaStreamTrack.ts +7 -6
- package/src/RTCDataChannel.ts +62 -47
- package/src/RTCIceCandidate.ts +8 -5
- package/src/RTCPeerConnection.ts +41 -14
- package/src/RTCRtpReceiver.ts +17 -0
- package/src/RTCRtpSender.ts +14 -0
- package/src/RTCRtpTransceiver.ts +2 -9
- package/src/RTCView.ts +53 -49
- 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
|
}
|
|
@@ -331,7 +331,7 @@ class GetUserMediaImpl {
|
|
|
331
331
|
trackInfo.putString("id", trackId);
|
|
332
332
|
trackInfo.putString("kind", track.kind());
|
|
333
333
|
trackInfo.putString("label", trackId);
|
|
334
|
-
trackInfo.putString("readyState", track.state().toString());
|
|
334
|
+
trackInfo.putString("readyState", track.state().toString().toLowerCase());
|
|
335
335
|
trackInfo.putBoolean("remote", false);
|
|
336
336
|
|
|
337
337
|
if (track instanceof VideoTrack) {
|
|
@@ -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");
|
|
@@ -107,6 +107,10 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
107
107
|
.setInjectableLogger(injectableLogger, loggingSeverity)
|
|
108
108
|
.createInitializationOptions());
|
|
109
109
|
|
|
110
|
+
if (injectableLogger == null && loggingSeverity != null) {
|
|
111
|
+
Logging.enableLogToDebugOutput(loggingSeverity);
|
|
112
|
+
}
|
|
113
|
+
|
|
110
114
|
if (encoderFactory == null || decoderFactory == null) {
|
|
111
115
|
// Initialize EGL context required for HW acceleration.
|
|
112
116
|
EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
|
|
@@ -991,11 +995,16 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
991
995
|
|
|
992
996
|
@Override
|
|
993
997
|
public void onSetSuccess() {
|
|
994
|
-
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
995
998
|
WritableMap newSdpMap = Arguments.createMap();
|
|
996
999
|
WritableMap params = Arguments.createMap();
|
|
997
|
-
|
|
998
|
-
|
|
1000
|
+
|
|
1001
|
+
SessionDescription newSdp = peerConnection.getLocalDescription();
|
|
1002
|
+
// Can happen when doing a rollback.
|
|
1003
|
+
if (newSdp != null) {
|
|
1004
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
1005
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
999
1008
|
params.putMap("sdpInfo", newSdpMap);
|
|
1000
1009
|
params.putArray("transceiversInfo", getTransceiversInfo(pcId));
|
|
1001
1010
|
promise.resolve(params);
|
|
@@ -1054,11 +1063,16 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1054
1063
|
|
|
1055
1064
|
@Override
|
|
1056
1065
|
public void onSetSuccess() {
|
|
1057
|
-
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
1058
1066
|
WritableMap newSdpMap = Arguments.createMap();
|
|
1059
1067
|
WritableMap params = Arguments.createMap();
|
|
1060
|
-
|
|
1061
|
-
|
|
1068
|
+
|
|
1069
|
+
SessionDescription newSdp = peerConnection.getRemoteDescription();
|
|
1070
|
+
// Be defensive for the rollback cases.
|
|
1071
|
+
if (newSdp != null) {
|
|
1072
|
+
newSdpMap.putString("type", newSdp.type.canonicalForm());
|
|
1073
|
+
newSdpMap.putString("sdp", newSdp.description);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1062
1076
|
params.putArray("transceiversInfo", getTransceiversInfo(id));
|
|
1063
1077
|
params.putMap("sdpInfo", newSdpMap);
|
|
1064
1078
|
|
|
@@ -1129,6 +1143,31 @@ public class WebRTCModule extends ReactContextBaseJavaModule {
|
|
|
1129
1143
|
}
|
|
1130
1144
|
}
|
|
1131
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
|
+
|
|
1132
1171
|
@ReactMethod
|
|
1133
1172
|
public void peerConnectionAddICECandidate(int pcId,
|
|
1134
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
|
|
|
@@ -45,6 +45,16 @@
|
|
|
45
45
|
RCTLogConvertError(json, @".candidate must not be null");
|
|
46
46
|
return nil;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
if (json[@"sdpMid"] == nil) {
|
|
50
|
+
RCTLogConvertError(json, @".sdpMid must not be null");
|
|
51
|
+
return nil;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (json[@"sdpMLineIndex"] == nil) {
|
|
55
|
+
RCTLogConvertError(json, @".sdpMLineIndex must not be null");
|
|
56
|
+
return nil;
|
|
57
|
+
}
|
|
48
58
|
|
|
49
59
|
NSString *sdp = json[@"candidate"];
|
|
50
60
|
RCTLogTrace(@"%@ <- candidate", sdp);
|
|
@@ -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;
|
|
@@ -160,9 +160,11 @@
|
|
|
160
160
|
NSString *readyState;
|
|
161
161
|
switch (track.readyState) {
|
|
162
162
|
case RTCMediaStreamTrackStateLive:
|
|
163
|
-
readyState = @"
|
|
163
|
+
readyState = @"live";
|
|
164
|
+
break;
|
|
164
165
|
case RTCMediaStreamTrackStateEnded:
|
|
165
|
-
readyState = @"
|
|
166
|
+
readyState = @"ended";
|
|
167
|
+
break;
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
return @{
|
|
@@ -191,21 +193,67 @@
|
|
|
191
193
|
}
|
|
192
194
|
|
|
193
195
|
+ (RTCRtpTransceiverDirection) parseDirection: (NSString *) direction {
|
|
194
|
-
if ([direction
|
|
196
|
+
if ([direction isEqual: @"inactive"]) {
|
|
195
197
|
return RTCRtpTransceiverDirectionInactive;
|
|
196
|
-
} else if ([direction
|
|
198
|
+
} else if ([direction isEqual: @"recvonly"]) {
|
|
197
199
|
return RTCRtpTransceiverDirectionRecvOnly;
|
|
198
|
-
} else if ([direction
|
|
200
|
+
} else if ([direction isEqual: @"sendonly"]) {
|
|
199
201
|
return RTCRtpTransceiverDirectionSendOnly;
|
|
200
|
-
} else if ([direction
|
|
202
|
+
} else if ([direction isEqual: @"sendrecv"]) {
|
|
201
203
|
return RTCRtpTransceiverDirectionSendRecv;
|
|
202
|
-
} else if ([direction
|
|
204
|
+
} else if ([direction isEqual: @"stopped"]) {
|
|
203
205
|
return RTCRtpTransceiverDirectionStopped;
|
|
204
206
|
}
|
|
205
207
|
|
|
206
208
|
return RTCRtpTransceiverDirectionInactive;
|
|
207
209
|
}
|
|
208
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
|
+
}
|
|
209
257
|
|
|
210
258
|
+ (NSDictionary *)streamToJSONWithPeerConnectionId: (NSNumber *) id
|
|
211
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
|
|
@@ -215,14 +215,17 @@ RCT_EXPORT_METHOD(peerConnectionSetLocalDescription:(nonnull NSNumber *)objectID
|
|
|
215
215
|
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
216
216
|
} else {
|
|
217
217
|
RTCPeerConnection *strongPc = weakPc;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
218
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
219
|
+
RTCSessionDescription *localDesc = strongPc.localDescription;
|
|
220
|
+
if (localDesc) {
|
|
221
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:localDesc.type];
|
|
222
|
+
sdpInfo[@"sdp"] = localDesc.sdp;
|
|
223
|
+
}
|
|
224
|
+
id data = @{
|
|
225
|
+
@"sdpInfo": sdpInfo,
|
|
223
226
|
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
224
227
|
};
|
|
225
|
-
resolve(
|
|
228
|
+
resolve(data);
|
|
226
229
|
}
|
|
227
230
|
};
|
|
228
231
|
|
|
@@ -262,15 +265,19 @@ RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(RTCSessionDescription *)sd
|
|
|
262
265
|
[newTransceivers addObject:newTransceiver];
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
|
|
269
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
270
|
+
RTCSessionDescription *remoteDesc = peerConnection.remoteDescription;
|
|
271
|
+
if (remoteDesc) {
|
|
272
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:remoteDesc.type];
|
|
273
|
+
sdpInfo[@"sdp"] = remoteDesc.sdp;
|
|
274
|
+
}
|
|
275
|
+
id data = @{
|
|
276
|
+
@"sdpInfo": sdpInfo,
|
|
270
277
|
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID],
|
|
271
278
|
@"newTransceivers": newTransceivers
|
|
272
279
|
};
|
|
273
|
-
callback(@[@(YES),
|
|
280
|
+
callback(@[@(YES), data]);
|
|
274
281
|
}
|
|
275
282
|
}];
|
|
276
283
|
}
|
|
@@ -350,6 +357,64 @@ RCT_EXPORT_METHOD(peerConnectionGetStats:(nonnull NSNumber *) objectID
|
|
|
350
357
|
}];
|
|
351
358
|
}
|
|
352
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
|
+
|
|
353
418
|
RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
354
419
|
{
|
|
355
420
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
@@ -419,50 +484,27 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
|
|
|
419
484
|
RTCRtpMediaType type = RTCRtpMediaTypeUnsupported;
|
|
420
485
|
|
|
421
486
|
if (kind) {
|
|
422
|
-
if ([kind
|
|
487
|
+
if ([kind isEqual: @"audio"]) {
|
|
423
488
|
type = RTCRtpMediaTypeAudio;
|
|
424
|
-
} else if ([kind
|
|
489
|
+
} else if ([kind isEqual: @"video"]) {
|
|
425
490
|
type = RTCRtpMediaTypeVideo;
|
|
426
491
|
}
|
|
427
|
-
|
|
492
|
+
|
|
493
|
+
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
494
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
495
|
+
|
|
496
|
+
transceiver = [peerConnection addTransceiverOfType: type init: transceiverInit];
|
|
428
497
|
} else if (trackId) {
|
|
429
498
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
430
499
|
|
|
431
|
-
if(!track) {
|
|
500
|
+
if (!track) {
|
|
432
501
|
track = peerConnection.remoteTracks[trackId];
|
|
433
502
|
}
|
|
434
503
|
|
|
435
|
-
NSDictionary *initOptions = [options objectForKey
|
|
436
|
-
RTCRtpTransceiverInit *transceiverInit = [
|
|
437
|
-
|
|
438
|
-
if (initOptions) {
|
|
439
|
-
NSString *dirrection = [initOptions objectForKey:@"direction"];
|
|
440
|
-
if ([dirrection isEqual: @"sendrecv"]) {
|
|
441
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendRecv];
|
|
442
|
-
} else if ([dirrection isEqual: @"sendonly"]) {
|
|
443
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendOnly];
|
|
444
|
-
} else if ([dirrection isEqual: @"recvonly"]) {
|
|
445
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionRecvOnly];
|
|
446
|
-
} else if ([dirrection isEqual: @"inactive"]) {
|
|
447
|
-
[transceiverInit setDirection:RTCRtpTransceiverDirectionInactive];
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
NSArray *streamIds = [initOptions objectForKey:@"streamIds"];
|
|
451
|
-
if (streamIds) {
|
|
452
|
-
[transceiverInit setStreamIds:streamIds];
|
|
453
|
-
}
|
|
504
|
+
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
505
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
454
506
|
|
|
455
|
-
|
|
456
|
-
if (encodingsArray) {
|
|
457
|
-
NSMutableArray<RTCRtpEncodingParameters *> *sendEncodings = [NSMutableArray new];
|
|
458
|
-
for (NSDictionary* encoding in encodingsArray) {
|
|
459
|
-
[sendEncodings addObject:[self parseEncoding:encoding]];
|
|
460
|
-
}
|
|
461
|
-
[transceiverInit setSendEncodings:sendEncodings];
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
|
|
507
|
+
transceiver = [peerConnection addTransceiverWithTrack: track init: transceiverInit];
|
|
466
508
|
} else {
|
|
467
509
|
RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
468
510
|
return;
|
|
@@ -474,8 +516,8 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSN
|
|
|
474
516
|
}
|
|
475
517
|
|
|
476
518
|
params = @{
|
|
477
|
-
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
478
|
-
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver
|
|
519
|
+
@"transceiverOrder": [NSNumber numberWithInt: _transceiverNextId++],
|
|
520
|
+
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver]
|
|
479
521
|
};
|
|
480
522
|
});
|
|
481
523
|
|
|
@@ -514,30 +556,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
514
556
|
return @(ret);
|
|
515
557
|
}
|
|
516
558
|
|
|
517
|
-
// TODO: move these below to some
|
|
518
|
-
|
|
519
|
-
- (RTCRtpEncodingParameters*)parseEncoding:(NSDictionary*)params
|
|
520
|
-
{
|
|
521
|
-
RTCRtpEncodingParameters *encoding = [RTCRtpEncodingParameters new];
|
|
522
|
-
|
|
523
|
-
if (params[@"rid"] != nil) {
|
|
524
|
-
[encoding setRid:params[@"rid"]];
|
|
525
|
-
}
|
|
526
|
-
if (params[@"active"] != nil) {
|
|
527
|
-
[encoding setIsActive:((NSNumber*)params[@"active"]).boolValue];
|
|
528
|
-
}
|
|
529
|
-
if (params[@"maxBitrate"] != nil) {
|
|
530
|
-
[encoding setMaxBitrateBps:(NSNumber*)params[@"maxBitrate"]];
|
|
531
|
-
}
|
|
532
|
-
if (params[@"maxFramerate"] != nil) {
|
|
533
|
-
[encoding setMaxFramerate:(NSNumber*)params[@"maxFramerate"]];
|
|
534
|
-
}
|
|
535
|
-
if (params[@"scaleResolutionDownBy"] != nil) {
|
|
536
|
-
[encoding setScaleResolutionDownBy:(NSNumber*)params[@"scaleResolutionDownBy"]];
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
return encoding;
|
|
540
|
-
}
|
|
559
|
+
// TODO: move these below to some SerializeUtils file
|
|
541
560
|
|
|
542
561
|
/**
|
|
543
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
|
|