react-native-webrtc 1.100.1 → 106.0.0-beta.1
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/ISSUE_TEMPLATE.md +17 -13
- package/README.md +46 -129
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +160 -165
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +279 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +361 -56
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +5 -1
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +2 -6
- package/ios/RCTWebRTC/ScreenCapturer.m +0 -1
- package/ios/RCTWebRTC/SerializeUtils.h +25 -0
- package/ios/RCTWebRTC/SerializeUtils.m +219 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +284 -128
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +216 -0
- package/ios/RCTWebRTC/WebRTCModule.h +15 -4
- package/ios/RCTWebRTC/WebRTCModule.m +26 -6
- package/lib/commonjs/EventEmitter.js +24 -0
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Logger.js +65 -0
- package/lib/commonjs/Logger.js.map +1 -0
- package/lib/commonjs/MediaStream.js +1 -1
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +4 -2
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/Permissions.js +1 -1
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +33 -0
- package/lib/commonjs/RTCErrorEvent.js.map +1 -0
- package/lib/commonjs/RTCPeerConnection.js +354 -103
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtcpParameters.js +24 -0
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpCapabilities.js +79 -0
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecCapability.js +25 -0
- package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecParameters.js +33 -0
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js +81 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/commonjs/RTCRtpParameters.js +26 -0
- package/lib/commonjs/RTCRtpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js +20 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiver.js +51 -0
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
- package/lib/commonjs/RTCRtpSendParameters.js +60 -0
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpSender.js +85 -0
- package/lib/commonjs/RTCRtpSender.js.map +1 -0
- package/lib/commonjs/RTCRtpTransceiver.js +141 -0
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
- package/lib/commonjs/RTCSessionDescription.js.map +1 -1
- package/lib/commonjs/RTCTrackEvent.js +32 -0
- package/lib/commonjs/RTCTrackEvent.js.map +1 -0
- package/lib/commonjs/RTCUtil.js +20 -37
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js +127 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/EventEmitter.js +21 -0
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Logger.js +53 -0
- package/lib/module/Logger.js.map +1 -0
- package/lib/module/MediaStream.js +1 -1
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +4 -2
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/Permissions.js +1 -1
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +22 -0
- package/lib/module/RTCErrorEvent.js.map +1 -0
- package/lib/module/RTCPeerConnection.js +348 -103
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtcpParameters.js +15 -0
- package/lib/module/RTCRtcpParameters.js.map +1 -0
- package/lib/module/RTCRtpCapabilities.js +63 -0
- package/lib/module/RTCRtpCapabilities.js.map +1 -0
- package/lib/module/RTCRtpCodecCapability.js +16 -0
- package/lib/module/RTCRtpCodecCapability.js.map +1 -0
- package/lib/module/RTCRtpCodecParameters.js +24 -0
- package/lib/module/RTCRtpCodecParameters.js.map +1 -0
- package/lib/module/RTCRtpEncodingParameters.js +72 -0
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/module/RTCRtpHeaderExtension.js +18 -0
- package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/module/RTCRtpParameters.js +17 -0
- package/lib/module/RTCRtpParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiveParameters.js +8 -0
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiver.js +39 -0
- package/lib/module/RTCRtpReceiver.js.map +1 -0
- package/lib/module/RTCRtpSendParameters.js +49 -0
- package/lib/module/RTCRtpSendParameters.js.map +1 -0
- package/lib/module/RTCRtpSender.js +70 -0
- package/lib/module/RTCRtpSender.js.map +1 -0
- package/lib/module/RTCRtpTransceiver.js +125 -0
- package/lib/module/RTCRtpTransceiver.js.map +1 -0
- package/lib/module/RTCSessionDescription.js.map +1 -1
- package/lib/module/RTCTrackEvent.js +23 -0
- package/lib/module/RTCTrackEvent.js.map +1 -0
- package/lib/module/RTCUtil.js +18 -36
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js +35 -4
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/EventEmitter.d.ts +3 -0
- package/lib/typescript/Logger.d.ts +13 -0
- package/lib/typescript/MediaDevices.d.ts +2 -2
- package/lib/typescript/MediaStream.d.ts +6 -6
- package/lib/typescript/MediaStreamTrack.d.ts +10 -9
- package/lib/typescript/RTCDataChannel.d.ts +4 -2
- package/lib/typescript/RTCErrorEvent.d.ts +12 -0
- package/lib/typescript/RTCPeerConnection.d.ts +42 -11
- package/lib/typescript/RTCRtcpParameters.d.ts +8 -0
- package/lib/typescript/RTCRtpCapabilities.d.ts +19 -0
- package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
- package/lib/typescript/RTCRtpCodecParameters.d.ts +14 -0
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +21 -0
- package/lib/typescript/RTCRtpHeaderExtension.d.ts +10 -0
- package/lib/typescript/RTCRtpParameters.d.ts +14 -0
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
- package/lib/typescript/RTCRtpReceiver.d.ts +15 -0
- package/lib/typescript/RTCRtpSendParameters.d.ts +17 -0
- package/lib/typescript/RTCRtpSender.d.ts +21 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +35 -0
- package/lib/typescript/RTCTrackEvent.d.ts +15 -0
- package/lib/typescript/RTCUtil.d.ts +5 -9
- package/lib/typescript/getDisplayMedia.d.ts +2 -1
- package/lib/typescript/getUserMedia.d.ts +2 -1
- package/lib/typescript/index.d.ts +16 -3
- package/package.json +6 -4
- package/react-native-webrtc.podspec +1 -1
- package/src/EventEmitter.ts +21 -1
- package/src/Logger.ts +49 -0
- package/src/MediaStream.ts +11 -11
- package/src/MediaStreamTrack.ts +14 -13
- package/src/Permissions.ts +1 -1
- package/src/RTCDataChannel.ts +11 -8
- package/src/RTCErrorEvent.ts +21 -0
- package/src/RTCPeerConnection.ts +400 -158
- package/src/RTCRtcpParameters.ts +14 -0
- package/src/RTCRtpCapabilities.ts +54 -0
- package/src/RTCRtpCodecCapability.ts +13 -0
- package/src/RTCRtpCodecParameters.ts +23 -0
- package/src/RTCRtpEncodingParameters.ts +67 -0
- package/src/RTCRtpHeaderExtension.ts +18 -0
- package/src/RTCRtpParameters.ts +21 -0
- package/src/RTCRtpReceiveParameters.ts +7 -0
- package/src/RTCRtpReceiver.ts +35 -0
- package/src/RTCRtpSendParameters.ts +51 -0
- package/src/RTCRtpSender.ts +72 -0
- package/src/RTCRtpTransceiver.ts +125 -0
- package/src/RTCSessionDescription.ts +3 -3
- package/src/RTCTrackEvent.ts +21 -0
- package/src/RTCUtil.ts +20 -40
- package/src/getDisplayMedia.ts +1 -1
- package/src/getUserMedia.ts +2 -2
- package/src/index.ts +51 -6
- package/tools/build-webrtc.py +32 -33
- package/tools/downloadBitcode.sh +2 -12
- package/tools/downloadWebRTC.js +21 -12
|
@@ -19,11 +19,15 @@
|
|
|
19
19
|
#import <WebRTC/RTCIceCandidate.h>
|
|
20
20
|
#import <WebRTC/RTCSessionDescription.h>
|
|
21
21
|
#import <WebRTC/RTCStatisticsReport.h>
|
|
22
|
+
#import <WebRTC/RTCMediaStreamTrack.h>
|
|
23
|
+
#import <WebRTC/RTCRtpReceiver.h>
|
|
24
|
+
#import <WebRTC/RTCRtpTransceiver.h>
|
|
22
25
|
|
|
23
26
|
#import "WebRTCModule.h"
|
|
24
27
|
#import "WebRTCModule+RTCDataChannel.h"
|
|
25
28
|
#import "WebRTCModule+RTCPeerConnection.h"
|
|
26
29
|
#import "WebRTCModule+VideoTrackAdapter.h"
|
|
30
|
+
#import "SerializeUtils.h"
|
|
27
31
|
|
|
28
32
|
@implementation RTCPeerConnection (React)
|
|
29
33
|
|
|
@@ -81,6 +85,8 @@
|
|
|
81
85
|
|
|
82
86
|
@implementation WebRTCModule (RTCPeerConnection)
|
|
83
87
|
|
|
88
|
+
int _transceiverNextId = 0;
|
|
89
|
+
|
|
84
90
|
/*
|
|
85
91
|
* This method is synchronous and blocking. This is done so we can implement createDataChannel
|
|
86
92
|
* in the same way (synchronous) since the peer connection needs to exist before.
|
|
@@ -119,35 +125,6 @@ RCT_EXPORT_METHOD(peerConnectionSetConfiguration:(RTCConfiguration*)configuratio
|
|
|
119
125
|
[peerConnection setConfiguration:configuration];
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
RCT_EXPORT_METHOD(peerConnectionAddStream:(nonnull NSString *)streamID objectID:(nonnull NSNumber *)objectID)
|
|
123
|
-
{
|
|
124
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
125
|
-
if (!peerConnection) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
RTCMediaStream *stream = self.localStreams[streamID];
|
|
129
|
-
if (!stream) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
[peerConnection addStream:stream];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
RCT_EXPORT_METHOD(peerConnectionRemoveStream:(nonnull NSString *)streamID objectID:(nonnull NSNumber *)objectID)
|
|
137
|
-
{
|
|
138
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
139
|
-
if (!peerConnection) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
RTCMediaStream *stream = self.localStreams[streamID];
|
|
143
|
-
if (!stream) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
[peerConnection removeStream:stream];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
128
|
RCT_EXPORT_METHOD(peerConnectionCreateOffer:(nonnull NSNumber *)objectID
|
|
152
129
|
options:(NSDictionary *)options
|
|
153
130
|
callback:(RCTResponseSenderBlock)callback)
|
|
@@ -174,16 +151,22 @@ RCT_EXPORT_METHOD(peerConnectionCreateOffer:(nonnull NSNumber *)objectID
|
|
|
174
151
|
]);
|
|
175
152
|
} else {
|
|
176
153
|
NSString *type = [RTCSessionDescription stringForType:sdp.type];
|
|
177
|
-
callback(@[@(YES), @{
|
|
154
|
+
callback(@[@(YES), @{
|
|
155
|
+
@"sdpInfo": @{
|
|
156
|
+
@"sdp": sdp.sdp,
|
|
157
|
+
@"type": type
|
|
158
|
+
},
|
|
159
|
+
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
160
|
+
}]);
|
|
178
161
|
}
|
|
179
162
|
}];
|
|
180
163
|
}
|
|
181
164
|
|
|
182
|
-
RCT_EXPORT_METHOD(peerConnectionCreateAnswer:(nonnull NSNumber *)
|
|
165
|
+
RCT_EXPORT_METHOD(peerConnectionCreateAnswer:(nonnull NSNumber *)objectID
|
|
183
166
|
options:(NSDictionary *)options
|
|
184
167
|
callback:(RCTResponseSenderBlock)callback)
|
|
185
168
|
{
|
|
186
|
-
RTCPeerConnection *peerConnection = self.peerConnections[
|
|
169
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
187
170
|
if (!peerConnection) {
|
|
188
171
|
return;
|
|
189
172
|
}
|
|
@@ -205,7 +188,11 @@ RCT_EXPORT_METHOD(peerConnectionCreateAnswer:(nonnull NSNumber *)peerConnectionI
|
|
|
205
188
|
]);
|
|
206
189
|
} else {
|
|
207
190
|
NSString *type = [RTCSessionDescription stringForType:sdp.type];
|
|
208
|
-
callback(@[@(YES), @{
|
|
191
|
+
callback(@[@(YES), @{
|
|
192
|
+
@"sdpInfo": @{@"sdp": sdp.sdp,
|
|
193
|
+
@"type": type},
|
|
194
|
+
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
195
|
+
}]);
|
|
209
196
|
}
|
|
210
197
|
}];
|
|
211
198
|
}
|
|
@@ -229,8 +216,11 @@ RCT_EXPORT_METHOD(peerConnectionSetLocalDescription:(nonnull NSNumber *)objectID
|
|
|
229
216
|
} else {
|
|
230
217
|
RTCPeerConnection *strongPc = weakPc;
|
|
231
218
|
id newSdp = @{
|
|
232
|
-
|
|
233
|
-
@"
|
|
219
|
+
|
|
220
|
+
@"sdpInfo": @{@"type": [RTCSessionDescription stringForType:strongPc.localDescription.type],
|
|
221
|
+
@"sdp": strongPc.localDescription.sdp
|
|
222
|
+
},
|
|
223
|
+
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
234
224
|
};
|
|
235
225
|
resolve(newSdp);
|
|
236
226
|
}
|
|
@@ -251,19 +241,21 @@ RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(RTCSessionDescription *)sd
|
|
|
251
241
|
}
|
|
252
242
|
|
|
253
243
|
[peerConnection setRemoteDescription: sdp completionHandler: ^(NSError *error) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
244
|
+
if (error) {
|
|
245
|
+
id errorResponse = @{
|
|
246
|
+
@"name": @"SetRemoteDescriptionFailed",
|
|
247
|
+
@"message": error.localizedDescription ?: [NSNull null]
|
|
248
|
+
};
|
|
249
|
+
callback(@[@(NO), errorResponse]);
|
|
250
|
+
} else {
|
|
251
|
+
id newSdp = @{
|
|
252
|
+
@"sdpInfo": @{
|
|
253
|
+
@"type": [RTCSessionDescription stringForType:peerConnection.remoteDescription.type],
|
|
254
|
+
@"sdp": peerConnection.remoteDescription.sdp},
|
|
255
|
+
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection peerConnectionId: objectID]
|
|
256
|
+
};
|
|
257
|
+
callback(@[@(YES), newSdp]);
|
|
258
|
+
}
|
|
267
259
|
}];
|
|
268
260
|
}
|
|
269
261
|
|
|
@@ -302,10 +294,11 @@ RCT_EXPORT_METHOD(peerConnectionClose:(nonnull NSNumber *)objectID)
|
|
|
302
294
|
}
|
|
303
295
|
|
|
304
296
|
// Remove video track adapters
|
|
305
|
-
for(
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
297
|
+
for (NSString *key in peerConnection.remoteTracks.allKeys) {
|
|
298
|
+
RTCMediaStreamTrack *track = peerConnection.remoteTracks[key];
|
|
299
|
+
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
300
|
+
[peerConnection removeVideoTrackAdapter: (RTCVideoTrack*) track];
|
|
301
|
+
}
|
|
309
302
|
}
|
|
310
303
|
|
|
311
304
|
[peerConnection close];
|
|
@@ -351,6 +344,163 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
351
344
|
[peerConnection restartIce];
|
|
352
345
|
}
|
|
353
346
|
|
|
347
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTrack:(nonnull NSNumber *)objectID
|
|
348
|
+
trackId:(NSString *)trackId
|
|
349
|
+
options:(NSDictionary *)options)
|
|
350
|
+
{
|
|
351
|
+
__block id params;
|
|
352
|
+
|
|
353
|
+
dispatch_sync(self.workerQueue, ^{
|
|
354
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
355
|
+
if (!peerConnection) {
|
|
356
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTrack()", objectID);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
361
|
+
|
|
362
|
+
NSArray *streamIds = [options objectForKey:@"streamIds"];
|
|
363
|
+
RTCRtpSender *sender = [peerConnection addTrack: track streamIds: streamIds];
|
|
364
|
+
RTCRtpTransceiver *transceiver = nil;
|
|
365
|
+
|
|
366
|
+
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
367
|
+
if([t.sender.senderId isEqual: sender.senderId]) {
|
|
368
|
+
transceiver = t;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (!transceiver) {
|
|
374
|
+
RCTLogWarn(@"Transceiver not found in peerConnectionAddTrack()");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
params = @{
|
|
379
|
+
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
380
|
+
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver],
|
|
381
|
+
@"sender": [SerializeUtils senderToJSONWithPeerConnectionId: objectID sender: sender]
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
return params;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver:(nonnull NSNumber *)objectID
|
|
389
|
+
options:(NSDictionary *)options)
|
|
390
|
+
{
|
|
391
|
+
__block id params;
|
|
392
|
+
|
|
393
|
+
dispatch_sync(self.workerQueue, ^{
|
|
394
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
395
|
+
if (!peerConnection) {
|
|
396
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTransceiver()", objectID);
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
RTCRtpTransceiver *transceiver = nil;
|
|
401
|
+
NSString *kind = [options objectForKey:@"type"];
|
|
402
|
+
NSString *trackId = [options objectForKey:@"trackId"];
|
|
403
|
+
RTCRtpMediaType type = RTCRtpMediaTypeUnsupported;
|
|
404
|
+
|
|
405
|
+
if (kind) {
|
|
406
|
+
if ([kind isEqual: @"audio"]) {
|
|
407
|
+
type = RTCRtpMediaTypeAudio;
|
|
408
|
+
} else if ([kind isEqual: @"video"]) {
|
|
409
|
+
type = RTCRtpMediaTypeVideo;
|
|
410
|
+
}
|
|
411
|
+
transceiver = [peerConnection addTransceiverOfType:type];
|
|
412
|
+
} else if (trackId) {
|
|
413
|
+
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
414
|
+
|
|
415
|
+
if(!track) {
|
|
416
|
+
track = peerConnection.remoteTracks[trackId];
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
NSDictionary *initOptions = [options objectForKey:@"init"];
|
|
420
|
+
RTCRtpTransceiverInit *transceiverInit = [RTCRtpTransceiverInit new];
|
|
421
|
+
|
|
422
|
+
if (initOptions) {
|
|
423
|
+
NSString *dirrection = [initOptions objectForKey:@"direction"];
|
|
424
|
+
if ([dirrection isEqual: @"sendrecv"]) {
|
|
425
|
+
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendRecv];
|
|
426
|
+
} else if ([dirrection isEqual: @"sendonly"]) {
|
|
427
|
+
[transceiverInit setDirection:RTCRtpTransceiverDirectionSendOnly];
|
|
428
|
+
} else if ([dirrection isEqual: @"recvonly"]) {
|
|
429
|
+
[transceiverInit setDirection:RTCRtpTransceiverDirectionRecvOnly];
|
|
430
|
+
} else if ([dirrection isEqual: @"inactive"]) {
|
|
431
|
+
[transceiverInit setDirection:RTCRtpTransceiverDirectionInactive];
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
NSArray *streamIds = [initOptions objectForKey:@"streamIds"];
|
|
435
|
+
if (streamIds) {
|
|
436
|
+
[transceiverInit setStreamIds:streamIds];
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
|
|
441
|
+
} else {
|
|
442
|
+
RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
if (transceiver == nil) {
|
|
447
|
+
RCTLogWarn(@"peerConnectionAddTransceiver() Error adding transceiver");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
params = @{
|
|
452
|
+
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
453
|
+
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId: objectID transceiver: transceiver ]
|
|
454
|
+
};
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
return params;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
RCT_EXPORT_METHOD(peerConnectionRemoveTrack:(nonnull NSNumber *)objectID
|
|
461
|
+
senderId:(nonnull NSString *)senderId)
|
|
462
|
+
{
|
|
463
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
464
|
+
if (!peerConnection) {
|
|
465
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionRemoveTrack()", objectID);
|
|
466
|
+
[self sendErrorWithEventName: kEventPeerConnectionOnError
|
|
467
|
+
funcName: @"removeTrack"
|
|
468
|
+
message: @"Peer Connection is not initialized"
|
|
469
|
+
info: nil];
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
RTCRtpTransceiver *transceiver = nil;
|
|
474
|
+
|
|
475
|
+
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
476
|
+
if (t.sender.senderId == senderId) {
|
|
477
|
+
transceiver = t;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (!transceiver) {
|
|
483
|
+
RCTLogWarn(@"Transceiver not found in peerConnectionRemoveTrack()");
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
NSMutableDictionary *identifier = [NSMutableDictionary new];
|
|
488
|
+
identifier[@"peerConnectionId"] = objectID;
|
|
489
|
+
identifier[@"senderId"] = senderId;
|
|
490
|
+
|
|
491
|
+
if ([peerConnection removeTrack: transceiver.sender]) {
|
|
492
|
+
[self sendEventWithName: kEventPeerConnectionOnRemoveTrackSuccessful
|
|
493
|
+
body: identifier];
|
|
494
|
+
} else {
|
|
495
|
+
[self sendErrorWithEventName: kEventPeerConnectionOnError
|
|
496
|
+
funcName: @"removeTrack"
|
|
497
|
+
message: @"Cannot remove track"
|
|
498
|
+
info: identifier];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// TODO: move these below to some SerializeUrils file
|
|
503
|
+
|
|
354
504
|
/**
|
|
355
505
|
* Constructs a JSON <tt>NSString</tt> representation of a specific
|
|
356
506
|
* <tt>RTCStatisticsReport</tt>s.
|
|
@@ -362,14 +512,14 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
362
512
|
*/
|
|
363
513
|
- (NSString *)statsToJSON:(RTCStatisticsReport *)report
|
|
364
514
|
{
|
|
365
|
-
/*
|
|
515
|
+
/*
|
|
366
516
|
The initial capacity matters, of course, because it determines how many
|
|
367
517
|
times the NSMutableString will have grow. But walking through the reports
|
|
368
518
|
to compute an initial capacity which exactly matches the requirements of
|
|
369
519
|
the reports is too much work without real-world bang here. An improvement
|
|
370
|
-
should be caching the required capacity from the previous invocation of the
|
|
371
|
-
method and using it as the initial capacity in the next invocation.
|
|
372
|
-
As I didn't want to go even through that,choosing just about any initial
|
|
520
|
+
should be caching the required capacity from the previous invocation of the
|
|
521
|
+
method and using it as the initial capacity in the next invocation.
|
|
522
|
+
As I didn't want to go even through that,choosing just about any initial
|
|
373
523
|
capacity is OK because NSMutableCopy doesn't have too bad a strategy of growing.
|
|
374
524
|
*/
|
|
375
525
|
NSMutableString *s = [NSMutableString stringWithCapacity:16 * 1024];
|
|
@@ -390,7 +540,7 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
390
540
|
RTCStatistics *statistics = report.statistics[key];
|
|
391
541
|
[s appendString:@"\"timestamp\":"];
|
|
392
542
|
[s appendFormat:@"%f", statistics.timestamp_us / 1000.0];
|
|
393
|
-
[s appendString:@",\"type\":\""];
|
|
543
|
+
[s appendString:@",\"type\":\""];
|
|
394
544
|
[s appendString:statistics.type];
|
|
395
545
|
[s appendString:@"\",\"id\":\""];
|
|
396
546
|
[s appendString:statistics.id];
|
|
@@ -406,7 +556,7 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
406
556
|
}
|
|
407
557
|
|
|
408
558
|
[s appendString:@"}]"];
|
|
409
|
-
}
|
|
559
|
+
}
|
|
410
560
|
|
|
411
561
|
[s appendString:@"]"];
|
|
412
562
|
|
|
@@ -434,7 +584,7 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
434
584
|
NSError *error;
|
|
435
585
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue
|
|
436
586
|
options:0
|
|
437
|
-
|
|
587
|
+
error:&error];
|
|
438
588
|
|
|
439
589
|
if (!jsonData) {
|
|
440
590
|
[s appendString:@"\""];
|
|
@@ -510,74 +660,6 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
510
660
|
}];
|
|
511
661
|
}
|
|
512
662
|
|
|
513
|
-
- (void)peerConnection:(RTCPeerConnection *)peerConnection didAddStream:(RTCMediaStream *)stream {
|
|
514
|
-
NSString *streamReactTag = [[NSUUID UUID] UUIDString];
|
|
515
|
-
NSMutableArray *tracks = [NSMutableArray array];
|
|
516
|
-
for (RTCVideoTrack *track in stream.videoTracks) {
|
|
517
|
-
peerConnection.remoteTracks[track.trackId] = track;
|
|
518
|
-
[peerConnection addVideoTrackAdapter:track];
|
|
519
|
-
[tracks addObject:@{@"id": track.trackId, @"kind": track.kind, @"label": track.trackId, @"enabled": @(track.isEnabled), @"remote": @(YES), @"readyState": @"live"}];
|
|
520
|
-
}
|
|
521
|
-
for (RTCAudioTrack *track in stream.audioTracks) {
|
|
522
|
-
peerConnection.remoteTracks[track.trackId] = track;
|
|
523
|
-
[tracks addObject:@{@"id": track.trackId, @"kind": track.kind, @"label": track.trackId, @"enabled": @(track.isEnabled), @"remote": @(YES), @"readyState": @"live"}];
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
peerConnection.remoteStreams[streamReactTag] = stream;
|
|
527
|
-
|
|
528
|
-
id newSdp = @{
|
|
529
|
-
@"type": [RTCSessionDescription stringForType:peerConnection.remoteDescription.type],
|
|
530
|
-
@"sdp": peerConnection.remoteDescription.sdp
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
[self sendEventWithName:kEventPeerConnectionAddedStream
|
|
534
|
-
body:@{
|
|
535
|
-
@"id": peerConnection.reactTag,
|
|
536
|
-
@"streamId": stream.streamId,
|
|
537
|
-
@"streamReactTag": streamReactTag,
|
|
538
|
-
@"tracks": tracks,
|
|
539
|
-
@"sdp": newSdp
|
|
540
|
-
}];
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
- (void)peerConnection:(RTCPeerConnection *)peerConnection didRemoveStream:(RTCMediaStream *)stream {
|
|
544
|
-
// XXX Find the stream by comparing the 'streamId' values. It turns out that WebRTC (as of M69) creates new wrapper
|
|
545
|
-
// instance for the native media stream before invoking the 'didRemoveStream' callback. This means it's a different
|
|
546
|
-
// RTCMediaStream instance passed to 'didAddStream' and 'didRemoveStream'.
|
|
547
|
-
NSString *streamReactTag = nil;
|
|
548
|
-
for (NSString *aReactTag in peerConnection.remoteStreams) {
|
|
549
|
-
RTCMediaStream *aStream = peerConnection.remoteStreams[aReactTag];
|
|
550
|
-
if ([aStream.streamId isEqualToString:stream.streamId]) {
|
|
551
|
-
streamReactTag = aReactTag;
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
if (!streamReactTag) {
|
|
556
|
-
RCTLogWarn(@"didRemoveStream - stream not found, id: %@", stream.streamId);
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
for (RTCVideoTrack *track in stream.videoTracks) {
|
|
560
|
-
[peerConnection removeVideoTrackAdapter:track];
|
|
561
|
-
[peerConnection.remoteTracks removeObjectForKey:track.trackId];
|
|
562
|
-
}
|
|
563
|
-
for (RTCAudioTrack *track in stream.audioTracks) {
|
|
564
|
-
[peerConnection.remoteTracks removeObjectForKey:track.trackId];
|
|
565
|
-
}
|
|
566
|
-
[peerConnection.remoteStreams removeObjectForKey:streamReactTag];
|
|
567
|
-
|
|
568
|
-
id newSdp = @{
|
|
569
|
-
@"type": [RTCSessionDescription stringForType:peerConnection.remoteDescription.type],
|
|
570
|
-
@"sdp": peerConnection.remoteDescription.sdp
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
[self sendEventWithName:kEventPeerConnectionRemovedStream
|
|
574
|
-
body:@{
|
|
575
|
-
@"id": peerConnection.reactTag,
|
|
576
|
-
@"streamId": streamReactTag,
|
|
577
|
-
@"sdp": newSdp
|
|
578
|
-
}];
|
|
579
|
-
}
|
|
580
|
-
|
|
581
663
|
- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection {
|
|
582
664
|
[self sendEventWithName:kEventPeerConnectionOnRenegotiationNeeded
|
|
583
665
|
body:@{ @"id": peerConnection.reactTag }];
|
|
@@ -654,8 +736,82 @@ RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
|
654
736
|
[self sendEventWithName:kEventPeerConnectionDidOpenDataChannel body:body];
|
|
655
737
|
}
|
|
656
738
|
|
|
739
|
+
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection didAddReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)rtpReceiver
|
|
740
|
+
streams:(NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *)mediaStreams {
|
|
741
|
+
dispatch_async(self.workerQueue, ^{
|
|
742
|
+
RTCRtpTransceiver *transceiver = nil;
|
|
743
|
+
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
744
|
+
if ([rtpReceiver.receiverId isEqual: t.receiver.receiverId]) {
|
|
745
|
+
transceiver = t;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (!transceiver) {
|
|
751
|
+
RCTLogWarn(@"Transceiver not found in didAddReceiver()");
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
RTCMediaStreamTrack *track = rtpReceiver.track;
|
|
756
|
+
|
|
757
|
+
if (peerConnection.remoteTracks[track.trackId]) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
762
|
+
RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
|
|
763
|
+
[peerConnection addVideoTrackAdapter: videoTrack];
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
peerConnection.remoteTracks[track.trackId] = track;
|
|
767
|
+
|
|
768
|
+
NSMutableDictionary *params = [NSMutableDictionary new];
|
|
769
|
+
NSMutableArray *streams = [NSMutableArray new];
|
|
770
|
+
|
|
771
|
+
for (RTCMediaStream * stream in mediaStreams) {
|
|
772
|
+
NSString *streamReactTag = nil;
|
|
773
|
+
|
|
774
|
+
for (NSString * key in [peerConnection.remoteStreams allKeys]) {
|
|
775
|
+
if ([[peerConnection.remoteStreams objectForKey:key] isEqual:stream]) {
|
|
776
|
+
streamReactTag = key;
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
if (!peerConnection.remoteStreams[stream.streamId]) {
|
|
782
|
+
peerConnection.remoteStreams[stream.streamId] = stream;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
if (!streamReactTag) {
|
|
786
|
+
NSUUID *uuid = [NSUUID UUID];
|
|
787
|
+
streamReactTag = [uuid UUIDString];
|
|
788
|
+
peerConnection.remoteStreams[streamReactTag] = stream;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
[streams addObject:[SerializeUtils streamToJSONWithPeerConnectionId:peerConnection.reactTag stream:stream streamReactTag:streamReactTag]];
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
params[@"streams"] = streams;
|
|
795
|
+
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId: peerConnection.reactTag receiver: rtpReceiver];
|
|
796
|
+
params[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
797
|
+
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId: peerConnection.reactTag transceiver: transceiver];
|
|
798
|
+
params[@"id"] = peerConnection.reactTag;
|
|
799
|
+
|
|
800
|
+
[self sendEventWithName: kEventPeerConnectionOnTrack
|
|
801
|
+
body: params];
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
|
|
657
805
|
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection didRemoveIceCandidates:(nonnull NSArray<RTCIceCandidate *> *)candidates {
|
|
658
|
-
|
|
806
|
+
// Unimplemented, there is no matching web API.
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection didAddStream:(nonnull RTCMediaStream *)stream {
|
|
810
|
+
// Unused in Unified Plan.
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection didRemoveStream:(nonnull RTCMediaStream *)stream {
|
|
814
|
+
// Unused in Unified Plan.
|
|
659
815
|
}
|
|
660
816
|
|
|
661
817
|
@end
|