react-native-webrtc 106.0.4 → 106.0.6
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/.clang-format +11 -0
- package/.github/workflows/android_ci.yml +29 -0
- package/.github/workflows/ci.yml +1 -1
- package/.github/workflows/ios_ci.yml +50 -0
- package/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +11 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +4 -13
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +12 -16
- package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +1 -1
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +37 -47
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +123 -116
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +60 -61
- package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +12 -9
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -121
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +8 -14
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +1 -2
- package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -0
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +383 -378
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +4 -10
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +74 -98
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +10 -9
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +2 -6
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +4 -5
- package/ios/RCTWebRTC/CaptureController.h +4 -8
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
- package/ios/RCTWebRTC/DataChannelWrapper.h +9 -13
- package/ios/RCTWebRTC/DataChannelWrapper.m +4 -5
- package/ios/RCTWebRTC/RCTConvert+WebRTC.h +2 -2
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +166 -171
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +1 -1
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +1 -1
- package/ios/RCTWebRTC/RTCVideoViewManager.h +0 -8
- package/ios/RCTWebRTC/RTCVideoViewManager.m +207 -239
- package/ios/RCTWebRTC/ScreenCaptureController.h +3 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +20 -15
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +4 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +57 -55
- package/ios/RCTWebRTC/SerializeUtils.h +16 -16
- package/ios/RCTWebRTC/SerializeUtils.m +98 -99
- package/ios/RCTWebRTC/SocketConnection.h +1 -8
- package/ios/RCTWebRTC/SocketConnection.m +31 -38
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +6 -7
- package/ios/RCTWebRTC/VideoCaptureController.m +54 -53
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +14 -13
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +3 -3
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +105 -100
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +8 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +218 -173
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -595
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +128 -139
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +4 -5
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +26 -35
- package/ios/RCTWebRTC/WebRTCModule.h +14 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -83
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +10 -1
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/EventEmitter.js +1 -1
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +25 -0
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +169 -162
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/EventEmitter.js +1 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +21 -0
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +169 -162
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js +1 -1
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/typescript/MediaStreamTrack.d.ts +1 -0
- package/lib/typescript/RTCPeerConnection.d.ts +5 -4
- package/package.json +3 -2
- package/src/EventEmitter.ts +1 -0
- package/src/MediaStreamTrack.ts +23 -0
- package/src/RTCPeerConnection.ts +168 -174
- package/src/RTCRtpTransceiver.ts +1 -1
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/RCTWebRTC.xcodeproj/project.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
//
|
|
2
|
-
// WebRTCModule+RTCPeerConnection.m
|
|
3
|
-
//
|
|
4
|
-
// Created by one on 2015/9/24.
|
|
5
|
-
// Copyright © 2015 One. All rights reserved.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
1
|
#import <objc/runtime.h>
|
|
9
2
|
|
|
10
3
|
#import <React/RCTBridge.h>
|
|
@@ -16,68 +9,57 @@
|
|
|
16
9
|
#import <WebRTC/RTCIceCandidate.h>
|
|
17
10
|
#import <WebRTC/RTCIceServer.h>
|
|
18
11
|
#import <WebRTC/RTCMediaConstraints.h>
|
|
19
|
-
#import <WebRTC/RTCIceCandidate.h>
|
|
20
|
-
#import <WebRTC/RTCSessionDescription.h>
|
|
21
|
-
#import <WebRTC/RTCStatisticsReport.h>
|
|
22
12
|
#import <WebRTC/RTCMediaStreamTrack.h>
|
|
23
13
|
#import <WebRTC/RTCRtpReceiver.h>
|
|
24
14
|
#import <WebRTC/RTCRtpTransceiver.h>
|
|
15
|
+
#import <WebRTC/RTCSessionDescription.h>
|
|
16
|
+
#import <WebRTC/RTCStatisticsReport.h>
|
|
25
17
|
|
|
26
|
-
#import "
|
|
18
|
+
#import "SerializeUtils.h"
|
|
27
19
|
#import "WebRTCModule+RTCDataChannel.h"
|
|
28
20
|
#import "WebRTCModule+RTCPeerConnection.h"
|
|
29
21
|
#import "WebRTCModule+VideoTrackAdapter.h"
|
|
30
|
-
#import "
|
|
22
|
+
#import "WebRTCModule.h"
|
|
31
23
|
|
|
32
24
|
@implementation RTCPeerConnection (React)
|
|
33
25
|
|
|
34
|
-
- (NSMutableDictionary<NSString *, DataChannelWrapper *> *)dataChannels
|
|
35
|
-
|
|
36
|
-
return objc_getAssociatedObject(self, _cmd);
|
|
26
|
+
- (NSMutableDictionary<NSString *, DataChannelWrapper *> *)dataChannels {
|
|
27
|
+
return objc_getAssociatedObject(self, _cmd);
|
|
37
28
|
}
|
|
38
29
|
|
|
39
|
-
- (void)setDataChannels:(NSMutableDictionary<NSString *, DataChannelWrapper *> *)dataChannels
|
|
40
|
-
|
|
41
|
-
objc_setAssociatedObject(self, @selector(dataChannels), dataChannels, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
30
|
+
- (void)setDataChannels:(NSMutableDictionary<NSString *, DataChannelWrapper *> *)dataChannels {
|
|
31
|
+
objc_setAssociatedObject(self, @selector(dataChannels), dataChannels, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
- (NSNumber *)reactTag
|
|
45
|
-
|
|
46
|
-
return objc_getAssociatedObject(self, _cmd);
|
|
34
|
+
- (NSNumber *)reactTag {
|
|
35
|
+
return objc_getAssociatedObject(self, _cmd);
|
|
47
36
|
}
|
|
48
37
|
|
|
49
|
-
- (void)setReactTag:(NSNumber *)reactTag
|
|
50
|
-
|
|
51
|
-
objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
38
|
+
- (void)setReactTag:(NSNumber *)reactTag {
|
|
39
|
+
objc_setAssociatedObject(self, @selector(reactTag), reactTag, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
52
40
|
}
|
|
53
41
|
|
|
54
|
-
- (NSMutableDictionary<NSString *, RTCMediaStream *> *)remoteStreams
|
|
55
|
-
{
|
|
42
|
+
- (NSMutableDictionary<NSString *, RTCMediaStream *> *)remoteStreams {
|
|
56
43
|
return objc_getAssociatedObject(self, _cmd);
|
|
57
44
|
}
|
|
58
45
|
|
|
59
|
-
- (void)setRemoteStreams:(NSMutableDictionary<NSString *,RTCMediaStream *> *)remoteStreams
|
|
60
|
-
{
|
|
46
|
+
- (void)setRemoteStreams:(NSMutableDictionary<NSString *, RTCMediaStream *> *)remoteStreams {
|
|
61
47
|
objc_setAssociatedObject(self, @selector(remoteStreams), remoteStreams, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
62
48
|
}
|
|
63
49
|
|
|
64
|
-
- (NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *)remoteTracks
|
|
65
|
-
{
|
|
50
|
+
- (NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *)remoteTracks {
|
|
66
51
|
return objc_getAssociatedObject(self, _cmd);
|
|
67
52
|
}
|
|
68
53
|
|
|
69
|
-
- (void)setRemoteTracks:(NSMutableDictionary<NSString *,RTCMediaStreamTrack *> *)remoteTracks
|
|
70
|
-
{
|
|
54
|
+
- (void)setRemoteTracks:(NSMutableDictionary<NSString *, RTCMediaStreamTrack *> *)remoteTracks {
|
|
71
55
|
objc_setAssociatedObject(self, @selector(remoteTracks), remoteTracks, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
72
56
|
}
|
|
73
57
|
|
|
74
|
-
- (id)webRTCModule
|
|
75
|
-
{
|
|
58
|
+
- (id)webRTCModule {
|
|
76
59
|
return objc_getAssociatedObject(self, _cmd);
|
|
77
60
|
}
|
|
78
61
|
|
|
79
|
-
- (void)setWebRTCModule:(id)webRTCModule
|
|
80
|
-
{
|
|
62
|
+
- (void)setWebRTCModule:(id)webRTCModule {
|
|
81
63
|
objc_setAssociatedObject(self, @selector(webRTCModule), webRTCModule, OBJC_ASSOCIATION_ASSIGN);
|
|
82
64
|
}
|
|
83
65
|
|
|
@@ -85,461 +67,470 @@
|
|
|
85
67
|
|
|
86
68
|
@implementation WebRTCModule (RTCPeerConnection)
|
|
87
69
|
|
|
88
|
-
|
|
70
|
+
int _transceiverNextId = 0;
|
|
89
71
|
|
|
90
72
|
/*
|
|
91
73
|
* This method is synchronous and blocking. This is done so we can implement createDataChannel
|
|
92
74
|
* in the same way (synchronous) since the peer connection needs to exist before.
|
|
93
75
|
*/
|
|
94
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionInit
|
|
95
|
-
|
|
96
|
-
{
|
|
76
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionInit
|
|
77
|
+
: (RTCConfiguration *)configuration objectID
|
|
78
|
+
: (nonnull NSNumber *)objectID) {
|
|
97
79
|
dispatch_sync(self.workerQueue, ^{
|
|
98
|
-
NSDictionary *optionalConstraints = @{
|
|
99
|
-
RTCMediaConstraints*
|
|
100
|
-
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
self.peerConnections[objectID] = peerConnection;
|
|
80
|
+
NSDictionary *optionalConstraints = @{@"DtlsSrtpKeyAgreement" : @"true"};
|
|
81
|
+
RTCMediaConstraints *constraints =
|
|
82
|
+
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:optionalConstraints];
|
|
83
|
+
RTCPeerConnection *peerConnection = [self.peerConnectionFactory peerConnectionWithConfiguration:configuration
|
|
84
|
+
constraints:constraints
|
|
85
|
+
delegate:self];
|
|
86
|
+
peerConnection.dataChannels = [NSMutableDictionary new];
|
|
87
|
+
peerConnection.reactTag = objectID;
|
|
88
|
+
peerConnection.remoteStreams = [NSMutableDictionary new];
|
|
89
|
+
peerConnection.remoteTracks = [NSMutableDictionary new];
|
|
90
|
+
peerConnection.videoTrackAdapters = [NSMutableDictionary new];
|
|
91
|
+
peerConnection.webRTCModule = self;
|
|
92
|
+
|
|
93
|
+
self.peerConnections[objectID] = peerConnection;
|
|
114
94
|
});
|
|
115
95
|
|
|
116
96
|
return nil;
|
|
117
97
|
}
|
|
118
98
|
|
|
119
|
-
RCT_EXPORT_METHOD(peerConnectionSetConfiguration
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
99
|
+
RCT_EXPORT_METHOD(peerConnectionSetConfiguration
|
|
100
|
+
: (RTCConfiguration *)configuration objectID
|
|
101
|
+
: (nonnull NSNumber *)objectID) {
|
|
102
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
103
|
+
if (!peerConnection) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
[peerConnection setConfiguration:configuration];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
RCT_EXPORT_METHOD(peerConnectionCreateOffer
|
|
110
|
+
: (nonnull NSNumber *)objectID options
|
|
111
|
+
: (NSDictionary *)options resolver
|
|
112
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
113
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
114
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
115
|
+
if (!peerConnection) {
|
|
116
|
+
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:options
|
|
121
|
+
optionalConstraints:nil];
|
|
122
|
+
|
|
123
|
+
RTCCreateSessionDescriptionCompletionHandler handler = ^(RTCSessionDescription *desc, NSError *error) {
|
|
124
|
+
dispatch_async(self.workerQueue, ^{
|
|
125
|
+
if (error) {
|
|
126
|
+
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
127
|
+
} else {
|
|
128
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
129
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:desc.type];
|
|
130
|
+
sdpInfo[@"sdp"] = desc.sdp;
|
|
131
|
+
id data = @{
|
|
132
|
+
@"sdpInfo" : sdpInfo,
|
|
133
|
+
@"transceiversInfo" :
|
|
134
|
+
[SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection]
|
|
135
|
+
};
|
|
136
|
+
resolve(data);
|
|
150
137
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
{
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
[peerConnection offerForConstraints:constraints completionHandler:handler];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
RCT_EXPORT_METHOD(peerConnectionCreateAnswer
|
|
145
|
+
: (nonnull NSNumber *)objectID options
|
|
146
|
+
: (NSDictionary *)options resolver
|
|
147
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
148
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
149
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
150
|
+
if (!peerConnection) {
|
|
151
|
+
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
RTCMediaConstraints *constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:options
|
|
156
|
+
optionalConstraints:nil];
|
|
157
|
+
|
|
158
|
+
RTCCreateSessionDescriptionCompletionHandler handler = ^(RTCSessionDescription *desc, NSError *error) {
|
|
159
|
+
dispatch_async(self.workerQueue, ^{
|
|
160
|
+
if (error) {
|
|
161
|
+
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
162
|
+
} else {
|
|
163
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
164
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:desc.type];
|
|
165
|
+
sdpInfo[@"sdp"] = desc.sdp;
|
|
166
|
+
id data = @{
|
|
167
|
+
@"sdpInfo" : sdpInfo,
|
|
168
|
+
@"transceiversInfo" :
|
|
169
|
+
[SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection]
|
|
170
|
+
};
|
|
171
|
+
resolve(data);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
[peerConnection answerForConstraints:constraints completionHandler:handler];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
RCT_EXPORT_METHOD(peerConnectionSetLocalDescription
|
|
180
|
+
: (nonnull NSNumber *)objectID desc
|
|
181
|
+
: (RTCSessionDescription *)desc resolver
|
|
182
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
183
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
184
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
185
|
+
if (!peerConnection) {
|
|
186
|
+
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
RTCSetSessionDescriptionCompletionHandler handler = ^(NSError *error) {
|
|
191
|
+
dispatch_async(self.workerQueue, ^{
|
|
192
|
+
if (error) {
|
|
193
|
+
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
194
|
+
} else {
|
|
195
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
196
|
+
RTCSessionDescription *localDesc = peerConnection.localDescription;
|
|
197
|
+
if (localDesc) {
|
|
198
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:localDesc.type];
|
|
199
|
+
sdpInfo[@"sdp"] = localDesc.sdp;
|
|
200
|
+
}
|
|
201
|
+
id data = @{
|
|
202
|
+
@"sdpInfo" : sdpInfo,
|
|
203
|
+
@"transceiversInfo" :
|
|
204
|
+
[SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection]
|
|
205
|
+
};
|
|
206
|
+
resolve(data);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
if (desc == nil) {
|
|
212
|
+
[peerConnection setLocalDescriptionWithCompletionHandler:handler];
|
|
213
|
+
} else {
|
|
214
|
+
[peerConnection setLocalDescription:desc completionHandler:handler];
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription
|
|
219
|
+
: (nonnull NSNumber *)objectID desc
|
|
220
|
+
: (RTCSessionDescription *)desc resolver
|
|
221
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
222
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
223
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
224
|
+
if (!peerConnection) {
|
|
225
|
+
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
NSMutableArray *receiversIds = [NSMutableArray new];
|
|
230
|
+
for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
|
|
231
|
+
[receiversIds addObject:transceiver.receiver.receiverId];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
RTCSetSessionDescriptionCompletionHandler handler = ^(NSError *error) {
|
|
235
|
+
dispatch_async(self.workerQueue, ^{
|
|
236
|
+
if (error) {
|
|
237
|
+
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
238
|
+
} else {
|
|
239
|
+
NSMutableArray *newTransceivers = [NSMutableArray new];
|
|
240
|
+
for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
|
|
241
|
+
if (![receiversIds containsObject:transceiver.receiver.receiverId]) {
|
|
242
|
+
NSMutableDictionary *newTransceiver = [NSMutableDictionary new];
|
|
243
|
+
newTransceiver[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
244
|
+
newTransceiver[@"transceiver"] =
|
|
245
|
+
[SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver];
|
|
246
|
+
[newTransceivers addObject:newTransceiver];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
251
|
+
RTCSessionDescription *remoteDesc = peerConnection.remoteDescription;
|
|
252
|
+
if (remoteDesc) {
|
|
253
|
+
sdpInfo[@"type"] = [RTCSessionDescription stringForType:remoteDesc.type];
|
|
254
|
+
sdpInfo[@"sdp"] = remoteDesc.sdp;
|
|
255
|
+
}
|
|
256
|
+
id data = @{
|
|
257
|
+
@"sdpInfo" : sdpInfo,
|
|
258
|
+
@"transceiversInfo" :
|
|
259
|
+
[SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection],
|
|
260
|
+
@"newTransceivers" : newTransceivers
|
|
261
|
+
};
|
|
262
|
+
resolve(data);
|
|
266
263
|
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
[peerConnection setRemoteDescription:desc completionHandler:handler];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
RCT_EXPORT_METHOD(peerConnectionAddICECandidate
|
|
271
|
+
: (nonnull NSNumber *)objectID candidate
|
|
272
|
+
: (RTCIceCandidate *)candidate resolver
|
|
273
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
274
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
275
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
276
|
+
if (!peerConnection) {
|
|
277
|
+
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
id handler = ^(NSError *error) {
|
|
282
|
+
dispatch_async(self.workerQueue, ^{
|
|
283
|
+
if (error) {
|
|
284
|
+
reject(@"E_OPERATION_ERROR", @"addIceCandidate failed", error);
|
|
285
|
+
} else {
|
|
286
|
+
RTCSessionDescription *remoteDesc = peerConnection.remoteDescription;
|
|
287
|
+
id newSdp = @{@"type" : [RTCSessionDescription stringForType:remoteDesc.type], @"sdp" : remoteDesc.sdp};
|
|
288
|
+
resolve(newSdp);
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
[peerConnection addIceCandidate:candidate completionHandler:handler];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
RCT_EXPORT_METHOD(peerConnectionClose : (nonnull NSNumber *)objectID) {
|
|
297
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
298
|
+
if (!peerConnection) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
[peerConnection close];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
RCT_EXPORT_METHOD(peerConnectionDispose : (nonnull NSNumber *)objectID) {
|
|
306
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
307
|
+
if (!peerConnection) {
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Remove video track adapters
|
|
312
|
+
for (NSString *key in peerConnection.remoteTracks.allKeys) {
|
|
313
|
+
RTCMediaStreamTrack *track = peerConnection.remoteTracks[key];
|
|
314
|
+
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
315
|
+
[peerConnection removeVideoTrackAdapter:(RTCVideoTrack *)track];
|
|
267
316
|
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Clean up peerConnection's streams and tracks
|
|
320
|
+
[peerConnection.remoteStreams removeAllObjects];
|
|
321
|
+
[peerConnection.remoteTracks removeAllObjects];
|
|
322
|
+
|
|
323
|
+
// Clean up peerConnection's dataChannels.
|
|
324
|
+
NSMutableDictionary<NSString *, DataChannelWrapper *> *dataChannels = peerConnection.dataChannels;
|
|
325
|
+
for (NSString *tag in dataChannels) {
|
|
326
|
+
dataChannels[tag].delegate = nil;
|
|
327
|
+
// There is no need to close the RTCDataChannel because it is owned by the
|
|
328
|
+
// RTCPeerConnection and the latter will close the former.
|
|
329
|
+
}
|
|
330
|
+
[dataChannels removeAllObjects];
|
|
331
|
+
|
|
332
|
+
[self.peerConnections removeObjectForKey:objectID];
|
|
333
|
+
}
|
|
268
334
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
335
|
+
RCT_EXPORT_METHOD(peerConnectionGetStats
|
|
336
|
+
: (nonnull NSNumber *)objectID resolver
|
|
337
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
338
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
339
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
340
|
+
if (!peerConnection) {
|
|
341
|
+
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
[peerConnection statisticsWithCompletionHandler:^(RTCStatisticsReport *report) {
|
|
346
|
+
resolve([self statsToJSON:report]);
|
|
347
|
+
}];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
RCT_EXPORT_METHOD(receiverGetStats
|
|
351
|
+
: (nonnull NSNumber *)pcId receiverId
|
|
352
|
+
: (nonnull NSString *)receiverId resolver
|
|
353
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
354
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
355
|
+
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
|
|
356
|
+
if (!peerConnection) {
|
|
357
|
+
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
RTCRtpReceiver *receiver;
|
|
362
|
+
for (RTCRtpReceiver *findRecv in peerConnection.receivers) {
|
|
363
|
+
if ([findRecv.receiverId isEqualToString:receiverId]) {
|
|
364
|
+
receiver = findRecv;
|
|
365
|
+
break;
|
|
274
366
|
}
|
|
275
|
-
id data = @{
|
|
276
|
-
@"sdpInfo": sdpInfo,
|
|
277
|
-
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection],
|
|
278
|
-
@"newTransceivers": newTransceivers
|
|
279
|
-
};
|
|
280
|
-
callback(@[@(YES), data]);
|
|
281
|
-
}
|
|
282
|
-
}];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
RCT_EXPORT_METHOD(peerConnectionAddICECandidate:(nonnull NSNumber *)objectID
|
|
286
|
-
candidate:(RTCIceCandidate*)candidate
|
|
287
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
288
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
289
|
-
{
|
|
290
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
291
|
-
if (!peerConnection) {
|
|
292
|
-
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
293
|
-
return;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
__weak RTCPeerConnection *weakPc = peerConnection;
|
|
297
|
-
[peerConnection addIceCandidate:candidate
|
|
298
|
-
completionHandler:^(NSError *error) {
|
|
299
|
-
if (error) {
|
|
300
|
-
reject(@"E_OPERATION_ERROR", @"addIceCandidate failed", error);
|
|
301
|
-
} else {
|
|
302
|
-
RTCPeerConnection *strongPc = weakPc;
|
|
303
|
-
id newSdp = @{
|
|
304
|
-
@"type": [RTCSessionDescription stringForType:strongPc.remoteDescription.type],
|
|
305
|
-
@"sdp": strongPc.remoteDescription.sdp
|
|
306
|
-
};
|
|
307
|
-
resolve(newSdp);
|
|
308
|
-
}
|
|
309
|
-
}];
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
RCT_EXPORT_METHOD(peerConnectionClose:(nonnull NSNumber *)objectID)
|
|
313
|
-
{
|
|
314
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
315
|
-
if (!peerConnection) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Remove video track adapters
|
|
320
|
-
for (NSString *key in peerConnection.remoteTracks.allKeys) {
|
|
321
|
-
RTCMediaStreamTrack *track = peerConnection.remoteTracks[key];
|
|
322
|
-
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
323
|
-
[peerConnection removeVideoTrackAdapter: (RTCVideoTrack*) track];
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
[peerConnection close];
|
|
328
|
-
|
|
329
|
-
// Clean up peerConnection's streams and tracks
|
|
330
|
-
[peerConnection.remoteStreams removeAllObjects];
|
|
331
|
-
[peerConnection.remoteTracks removeAllObjects];
|
|
332
|
-
|
|
333
|
-
// Clean up peerConnection's dataChannels.
|
|
334
|
-
NSMutableDictionary<NSString *, DataChannelWrapper *> *dataChannels = peerConnection.dataChannels;
|
|
335
|
-
for (NSString *tag in dataChannels) {
|
|
336
|
-
dataChannels[tag].delegate = nil;
|
|
337
|
-
// There is no need to close the RTCDataChannel because it is owned by the
|
|
338
|
-
// RTCPeerConnection and the latter will close the former.
|
|
339
|
-
}
|
|
340
|
-
[dataChannels removeAllObjects];
|
|
341
|
-
|
|
342
|
-
[self.peerConnections removeObjectForKey:objectID];
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
RCT_EXPORT_METHOD(peerConnectionGetStats:(nonnull NSNumber *) objectID
|
|
346
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
347
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
348
|
-
{
|
|
349
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
350
|
-
if (!peerConnection) {
|
|
351
|
-
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
[peerConnection statisticsWithCompletionHandler:^(RTCStatisticsReport *report) {
|
|
356
|
-
resolve([self statsToJSON:report]);
|
|
357
|
-
}];
|
|
358
|
-
}
|
|
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
367
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
RCT_EXPORT_METHOD(senderGetStats
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
{
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
RTCRtpSender *sender;
|
|
401
|
-
for (RTCRtpSender *findSend in peerConnection.senders) {
|
|
402
|
-
if ([findSend.senderId isEqualToString:senderId]) {
|
|
403
|
-
sender = findSend;
|
|
404
|
-
break;
|
|
368
|
+
|
|
369
|
+
if (!receiver) {
|
|
370
|
+
reject(@"invalid_id", @"Receiver ID not found", nil);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
[peerConnection statisticsForReceiver:receiver
|
|
375
|
+
completionHandler:^(RTCStatisticsReport *report) {
|
|
376
|
+
resolve([self statsToJSON:report]);
|
|
377
|
+
}];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
RCT_EXPORT_METHOD(senderGetStats
|
|
381
|
+
: (nonnull NSNumber *)pcId senderId
|
|
382
|
+
: (nonnull NSString *)senderId resolver
|
|
383
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
384
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
385
|
+
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
|
|
386
|
+
if (!peerConnection) {
|
|
387
|
+
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
388
|
+
return;
|
|
405
389
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
390
|
+
|
|
391
|
+
RTCRtpSender *sender;
|
|
392
|
+
for (RTCRtpSender *findSend in peerConnection.senders) {
|
|
393
|
+
if ([findSend.senderId isEqualToString:senderId]) {
|
|
394
|
+
sender = findSend;
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
if (!sender) {
|
|
400
|
+
reject(@"invalid_id", @"Sender ID not found", nil);
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
[peerConnection statisticsForSender:sender
|
|
405
|
+
completionHandler:^(RTCStatisticsReport *report) {
|
|
406
|
+
resolve([self statsToJSON:report]);
|
|
407
|
+
}];
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
RCT_EXPORT_METHOD(peerConnectionRestartIce : (nonnull NSNumber *)objectID) {
|
|
411
|
+
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
412
|
+
if (!peerConnection) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
[peerConnection restartIce];
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTrack
|
|
420
|
+
: (nonnull NSNumber *)objectID trackId
|
|
421
|
+
: (NSString *)trackId options
|
|
422
|
+
: (NSDictionary *)options) {
|
|
423
|
+
__block id params = nil;
|
|
433
424
|
|
|
434
425
|
dispatch_sync(self.workerQueue, ^{
|
|
435
426
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
436
427
|
if (!peerConnection) {
|
|
437
|
-
|
|
438
|
-
|
|
428
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTrack()", objectID);
|
|
429
|
+
return;
|
|
439
430
|
}
|
|
440
431
|
|
|
441
432
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
442
433
|
|
|
443
434
|
NSArray *streamIds = [options objectForKey:@"streamIds"];
|
|
444
|
-
RTCRtpSender *sender = [peerConnection addTrack:
|
|
435
|
+
RTCRtpSender *sender = [peerConnection addTrack:track streamIds:streamIds];
|
|
445
436
|
RTCRtpTransceiver *transceiver = nil;
|
|
446
|
-
|
|
437
|
+
|
|
447
438
|
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
439
|
+
if ([t.sender.senderId isEqual:sender.senderId]) {
|
|
440
|
+
transceiver = t;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
452
443
|
}
|
|
453
|
-
|
|
444
|
+
|
|
454
445
|
if (!transceiver) {
|
|
455
446
|
RCTLogWarn(@"Transceiver not found in peerConnectionAddTrack()");
|
|
456
447
|
return;
|
|
457
448
|
}
|
|
458
|
-
|
|
449
|
+
|
|
459
450
|
params = @{
|
|
460
|
-
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
461
|
-
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId:
|
|
462
|
-
@"sender": [SerializeUtils senderToJSONWithPeerConnectionId:
|
|
451
|
+
@"transceiverOrder" : [NSNumber numberWithInt:_transceiverNextId++],
|
|
452
|
+
@"transceiver" : [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver],
|
|
453
|
+
@"sender" : [SerializeUtils senderToJSONWithPeerConnectionId:objectID sender:sender]
|
|
463
454
|
};
|
|
464
455
|
});
|
|
465
456
|
|
|
466
457
|
return params;
|
|
467
458
|
}
|
|
468
459
|
|
|
469
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver
|
|
470
|
-
|
|
471
|
-
{
|
|
460
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver
|
|
461
|
+
: (nonnull NSNumber *)objectID options
|
|
462
|
+
: (NSDictionary *)options) {
|
|
472
463
|
__block id params = nil;
|
|
473
464
|
|
|
474
465
|
dispatch_sync(self.workerQueue, ^{
|
|
475
466
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
476
467
|
if (!peerConnection) {
|
|
477
|
-
|
|
478
|
-
|
|
468
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTransceiver()", objectID);
|
|
469
|
+
return;
|
|
479
470
|
}
|
|
480
471
|
|
|
481
472
|
RTCRtpTransceiver *transceiver = nil;
|
|
482
473
|
NSString *kind = [options objectForKey:@"type"];
|
|
483
474
|
NSString *trackId = [options objectForKey:@"trackId"];
|
|
484
475
|
RTCRtpMediaType type = RTCRtpMediaTypeUnsupported;
|
|
485
|
-
|
|
476
|
+
|
|
486
477
|
if (kind) {
|
|
487
|
-
if ([kind isEqual
|
|
478
|
+
if ([kind isEqual:@"audio"]) {
|
|
488
479
|
type = RTCRtpMediaTypeAudio;
|
|
489
|
-
} else if ([kind isEqual
|
|
480
|
+
} else if ([kind isEqual:@"video"]) {
|
|
490
481
|
type = RTCRtpMediaTypeVideo;
|
|
491
482
|
}
|
|
492
483
|
|
|
493
|
-
NSDictionary *initOptions = [options objectForKey
|
|
494
|
-
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:
|
|
484
|
+
NSDictionary *initOptions = [options objectForKey:@"init"];
|
|
485
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:initOptions];
|
|
495
486
|
|
|
496
|
-
transceiver = [peerConnection addTransceiverOfType:
|
|
487
|
+
transceiver = [peerConnection addTransceiverOfType:type init:transceiverInit];
|
|
497
488
|
} else if (trackId) {
|
|
498
489
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
499
|
-
|
|
490
|
+
|
|
500
491
|
if (!track) {
|
|
501
492
|
track = peerConnection.remoteTracks[trackId];
|
|
502
493
|
}
|
|
503
|
-
|
|
504
|
-
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
505
|
-
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
506
494
|
|
|
507
|
-
|
|
495
|
+
NSDictionary *initOptions = [options objectForKey:@"init"];
|
|
496
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:initOptions];
|
|
497
|
+
|
|
498
|
+
transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
|
|
508
499
|
} else {
|
|
509
500
|
RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
510
501
|
return;
|
|
511
502
|
}
|
|
512
|
-
|
|
503
|
+
|
|
513
504
|
if (transceiver == nil) {
|
|
514
505
|
RCTLogWarn(@"peerConnectionAddTransceiver() Error adding transceiver");
|
|
515
506
|
return;
|
|
516
507
|
}
|
|
517
|
-
|
|
508
|
+
|
|
518
509
|
params = @{
|
|
519
|
-
|
|
520
|
-
|
|
510
|
+
@"transceiverOrder" : [NSNumber numberWithInt:_transceiverNextId++],
|
|
511
|
+
@"transceiver" : [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver]
|
|
521
512
|
};
|
|
522
513
|
});
|
|
523
514
|
|
|
524
515
|
return params;
|
|
525
516
|
}
|
|
526
517
|
|
|
527
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack
|
|
528
|
-
|
|
529
|
-
{
|
|
518
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack
|
|
519
|
+
: (nonnull NSNumber *)objectID senderId
|
|
520
|
+
: (nonnull NSString *)senderId) {
|
|
530
521
|
__block BOOL ret = NO;
|
|
531
522
|
|
|
532
523
|
dispatch_sync(self.workerQueue, ^{
|
|
533
524
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
534
525
|
if (!peerConnection) {
|
|
535
|
-
|
|
536
|
-
|
|
526
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionRemoveTrack()", objectID);
|
|
527
|
+
return;
|
|
537
528
|
}
|
|
538
529
|
|
|
539
530
|
RTCRtpSender *sender = nil;
|
|
540
531
|
|
|
541
532
|
for (RTCRtpSender *s in peerConnection.senders) {
|
|
542
|
-
if ([s.senderId isEqual:
|
|
533
|
+
if ([s.senderId isEqual:senderId]) {
|
|
543
534
|
sender = s;
|
|
544
535
|
break;
|
|
545
536
|
}
|
|
@@ -550,7 +541,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
550
541
|
return;
|
|
551
542
|
}
|
|
552
543
|
|
|
553
|
-
ret = [peerConnection removeTrack:
|
|
544
|
+
ret = [peerConnection removeTrack:sender];
|
|
554
545
|
});
|
|
555
546
|
|
|
556
547
|
return @(ret);
|
|
@@ -567,57 +558,56 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
567
558
|
* @return an <tt>NSString</tt> which represents the specified <tt>report</tt> in
|
|
568
559
|
* JSON format
|
|
569
560
|
*/
|
|
570
|
-
- (NSString *)statsToJSON:(RTCStatisticsReport *)report
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
[s appendString:@"[\""];
|
|
594
|
-
[s appendString: key];
|
|
595
|
-
[s appendString:@"\",{"];
|
|
596
|
-
|
|
597
|
-
RTCStatistics *statistics = report.statistics[key];
|
|
598
|
-
[s appendString:@"\"timestamp\":"];
|
|
599
|
-
[s appendFormat:@"%f", statistics.timestamp_us / 1000.0];
|
|
600
|
-
[s appendString:@",\"type\":\""];
|
|
601
|
-
[s appendString:statistics.type];
|
|
602
|
-
[s appendString:@"\",\"id\":\""];
|
|
603
|
-
[s appendString:statistics.id];
|
|
604
|
-
[s appendString:@"\""];
|
|
605
|
-
|
|
606
|
-
for (id key in statistics.values) {
|
|
607
|
-
[s appendString:@","];
|
|
608
|
-
[s appendString:@"\""];
|
|
561
|
+
- (NSString *)statsToJSON:(RTCStatisticsReport *)report {
|
|
562
|
+
/*
|
|
563
|
+
The initial capacity matters, of course, because it determines how many
|
|
564
|
+
times the NSMutableString will have grow. But walking through the reports
|
|
565
|
+
to compute an initial capacity which exactly matches the requirements of
|
|
566
|
+
the reports is too much work without real-world bang here. An improvement
|
|
567
|
+
should be caching the required capacity from the previous invocation of the
|
|
568
|
+
method and using it as the initial capacity in the next invocation.
|
|
569
|
+
As I didn't want to go even through that,choosing just about any initial
|
|
570
|
+
capacity is OK because NSMutableCopy doesn't have too bad a strategy of growing.
|
|
571
|
+
*/
|
|
572
|
+
NSMutableString *s = [NSMutableString stringWithCapacity:16 * 1024];
|
|
573
|
+
|
|
574
|
+
[s appendString:@"["];
|
|
575
|
+
BOOL firstReport = YES;
|
|
576
|
+
for (NSString *key in report.statistics.allKeys) {
|
|
577
|
+
if (firstReport) {
|
|
578
|
+
firstReport = NO;
|
|
579
|
+
} else {
|
|
580
|
+
[s appendString:@","];
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
[s appendString:@"[\""];
|
|
609
584
|
[s appendString:key];
|
|
610
|
-
[s appendString:@"\"
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
585
|
+
[s appendString:@"\",{"];
|
|
586
|
+
|
|
587
|
+
RTCStatistics *statistics = report.statistics[key];
|
|
588
|
+
[s appendString:@"\"timestamp\":"];
|
|
589
|
+
[s appendFormat:@"%f", statistics.timestamp_us / 1000.0];
|
|
590
|
+
[s appendString:@",\"type\":\""];
|
|
591
|
+
[s appendString:statistics.type];
|
|
592
|
+
[s appendString:@"\",\"id\":\""];
|
|
593
|
+
[s appendString:statistics.id];
|
|
594
|
+
[s appendString:@"\""];
|
|
614
595
|
|
|
615
|
-
|
|
616
|
-
|
|
596
|
+
for (id key in statistics.values) {
|
|
597
|
+
[s appendString:@","];
|
|
598
|
+
[s appendString:@"\""];
|
|
599
|
+
[s appendString:key];
|
|
600
|
+
[s appendString:@"\":"];
|
|
601
|
+
NSObject *statisticsValue = [statistics.values objectForKey:key];
|
|
602
|
+
[self appendValue:statisticsValue toString:s];
|
|
603
|
+
}
|
|
617
604
|
|
|
618
|
-
|
|
605
|
+
[s appendString:@"}]"];
|
|
606
|
+
}
|
|
619
607
|
|
|
620
|
-
|
|
608
|
+
[s appendString:@"]"];
|
|
609
|
+
|
|
610
|
+
return s;
|
|
621
611
|
}
|
|
622
612
|
|
|
623
613
|
- (void)appendValue:(NSObject *)statisticsValue toString:(NSMutableString *)s {
|
|
@@ -625,7 +615,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
625
615
|
[s appendString:@"["];
|
|
626
616
|
BOOL firstValue = YES;
|
|
627
617
|
for (NSObject *element in (NSArray *)statisticsValue) {
|
|
628
|
-
if(firstValue) {
|
|
618
|
+
if (firstValue) {
|
|
629
619
|
firstValue = NO;
|
|
630
620
|
} else {
|
|
631
621
|
[s appendString:@","];
|
|
@@ -634,14 +624,12 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
634
624
|
[s appendString:@"\""];
|
|
635
625
|
[s appendString:[NSString stringWithFormat:@"%@", element]];
|
|
636
626
|
[s appendString:@"\""];
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
[s appendString:@"]"];
|
|
640
630
|
} else if ([statisticsValue isKindOfClass:[NSDictionary class]]) {
|
|
641
631
|
NSError *error;
|
|
642
|
-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue
|
|
643
|
-
options:0
|
|
644
|
-
error:&error];
|
|
632
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue options:0 error:&error];
|
|
645
633
|
|
|
646
634
|
if (!jsonData) {
|
|
647
635
|
[s appendString:@"\""];
|
|
@@ -661,164 +649,204 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
661
649
|
}
|
|
662
650
|
|
|
663
651
|
- (NSString *)stringForPeerConnectionState:(RTCPeerConnectionState)state {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
652
|
+
switch (state) {
|
|
653
|
+
case RTCPeerConnectionStateNew:
|
|
654
|
+
return @"new";
|
|
655
|
+
case RTCPeerConnectionStateConnecting:
|
|
656
|
+
return @"connecting";
|
|
657
|
+
case RTCPeerConnectionStateConnected:
|
|
658
|
+
return @"connected";
|
|
659
|
+
case RTCPeerConnectionStateDisconnected:
|
|
660
|
+
return @"disconnected";
|
|
661
|
+
case RTCPeerConnectionStateFailed:
|
|
662
|
+
return @"failed";
|
|
663
|
+
case RTCPeerConnectionStateClosed:
|
|
664
|
+
return @"closed";
|
|
665
|
+
}
|
|
666
|
+
return nil;
|
|
673
667
|
}
|
|
674
668
|
|
|
675
669
|
- (NSString *)stringForICEConnectionState:(RTCIceConnectionState)state {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
670
|
+
switch (state) {
|
|
671
|
+
case RTCIceConnectionStateNew:
|
|
672
|
+
return @"new";
|
|
673
|
+
case RTCIceConnectionStateChecking:
|
|
674
|
+
return @"checking";
|
|
675
|
+
case RTCIceConnectionStateConnected:
|
|
676
|
+
return @"connected";
|
|
677
|
+
case RTCIceConnectionStateCompleted:
|
|
678
|
+
return @"completed";
|
|
679
|
+
case RTCIceConnectionStateFailed:
|
|
680
|
+
return @"failed";
|
|
681
|
+
case RTCIceConnectionStateDisconnected:
|
|
682
|
+
return @"disconnected";
|
|
683
|
+
case RTCIceConnectionStateClosed:
|
|
684
|
+
return @"closed";
|
|
685
|
+
case RTCIceConnectionStateCount:
|
|
686
|
+
return @"count";
|
|
687
|
+
}
|
|
688
|
+
return nil;
|
|
687
689
|
}
|
|
688
690
|
|
|
689
691
|
- (NSString *)stringForICEGatheringState:(RTCIceGatheringState)state {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
692
|
+
switch (state) {
|
|
693
|
+
case RTCIceGatheringStateNew:
|
|
694
|
+
return @"new";
|
|
695
|
+
case RTCIceGatheringStateGathering:
|
|
696
|
+
return @"gathering";
|
|
697
|
+
case RTCIceGatheringStateComplete:
|
|
698
|
+
return @"complete";
|
|
699
|
+
}
|
|
700
|
+
return nil;
|
|
696
701
|
}
|
|
697
702
|
|
|
698
703
|
- (NSString *)stringForSignalingState:(RTCSignalingState)state {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
704
|
+
switch (state) {
|
|
705
|
+
case RTCSignalingStateStable:
|
|
706
|
+
return @"stable";
|
|
707
|
+
case RTCSignalingStateHaveLocalOffer:
|
|
708
|
+
return @"have-local-offer";
|
|
709
|
+
case RTCSignalingStateHaveLocalPrAnswer:
|
|
710
|
+
return @"have-local-pranswer";
|
|
711
|
+
case RTCSignalingStateHaveRemoteOffer:
|
|
712
|
+
return @"have-remote-offer";
|
|
713
|
+
case RTCSignalingStateHaveRemotePrAnswer:
|
|
714
|
+
return @"have-remote-pranswer";
|
|
715
|
+
case RTCSignalingStateClosed:
|
|
716
|
+
return @"closed";
|
|
717
|
+
}
|
|
718
|
+
return nil;
|
|
708
719
|
}
|
|
709
720
|
|
|
710
721
|
#pragma mark - RTCPeerConnectionDelegate methods
|
|
711
722
|
|
|
712
723
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeSignalingState:(RTCSignalingState)newState {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
724
|
+
dispatch_async(self.workerQueue, ^{
|
|
725
|
+
[self sendEventWithName:kEventPeerConnectionSignalingStateChanged
|
|
726
|
+
body:@{
|
|
727
|
+
@"pcId" : peerConnection.reactTag,
|
|
728
|
+
@"signalingState" : [self stringForSignalingState:newState]
|
|
729
|
+
}];
|
|
730
|
+
});
|
|
718
731
|
}
|
|
719
732
|
|
|
720
733
|
- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection {
|
|
721
|
-
|
|
722
|
-
|
|
734
|
+
dispatch_async(self.workerQueue, ^{
|
|
735
|
+
[self sendEventWithName:kEventPeerConnectionOnRenegotiationNeeded body:@{@"pcId" : peerConnection.reactTag}];
|
|
736
|
+
});
|
|
723
737
|
}
|
|
724
738
|
|
|
725
739
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeConnectionState:(RTCPeerConnectionState)newState {
|
|
726
|
-
|
|
727
|
-
|
|
740
|
+
dispatch_async(self.workerQueue, ^{
|
|
741
|
+
[self sendEventWithName:kEventPeerConnectionStateChanged
|
|
742
|
+
body:@{
|
|
743
|
+
@"pcId" : peerConnection.reactTag,
|
|
744
|
+
@"connectionState" : [self stringForPeerConnectionState:newState]
|
|
745
|
+
}];
|
|
746
|
+
});
|
|
728
747
|
}
|
|
729
748
|
|
|
730
749
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeIceConnectionState:(RTCIceConnectionState)newState {
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
750
|
+
dispatch_async(self.workerQueue, ^{
|
|
751
|
+
[self sendEventWithName:kEventPeerConnectionIceConnectionChanged
|
|
752
|
+
body:@{
|
|
753
|
+
@"pcId" : peerConnection.reactTag,
|
|
754
|
+
@"iceConnectionState" : [self stringForICEConnectionState:newState]
|
|
755
|
+
}];
|
|
756
|
+
});
|
|
736
757
|
}
|
|
737
758
|
|
|
738
759
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeIceGatheringState:(RTCIceGatheringState)newState {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
760
|
+
dispatch_async(self.workerQueue, ^{
|
|
761
|
+
id newSdp = @{};
|
|
762
|
+
if (newState == RTCIceGatheringStateComplete) {
|
|
763
|
+
// Can happen when doing a rollback.
|
|
764
|
+
if (peerConnection.localDescription) {
|
|
765
|
+
newSdp = @{
|
|
766
|
+
@"type" : [RTCSessionDescription stringForType:peerConnection.localDescription.type],
|
|
767
|
+
@"sdp" : peerConnection.localDescription.sdp
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
[self sendEventWithName:kEventPeerConnectionIceGatheringChanged
|
|
773
|
+
body:@{
|
|
774
|
+
@"pcId" : peerConnection.reactTag,
|
|
775
|
+
@"iceGatheringState" : [self stringForICEGatheringState:newState],
|
|
776
|
+
@"sdp" : newSdp
|
|
777
|
+
}];
|
|
778
|
+
});
|
|
755
779
|
}
|
|
756
780
|
|
|
757
781
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didGenerateIceCandidate:(RTCIceCandidate *)candidate {
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
NSString *reactTag = [[NSUUID UUID] UUIDString];
|
|
780
|
-
DataChannelWrapper *dcw = [[DataChannelWrapper alloc] initWithChannel:dataChannel reactTag:reactTag];
|
|
781
|
-
dcw.pcId = peerConnection.reactTag;
|
|
782
|
-
peerConnection.dataChannels[reactTag] = dcw;
|
|
783
|
-
dcw.delegate = self;
|
|
784
|
-
|
|
785
|
-
NSDictionary *dataChannelInfo = @{
|
|
786
|
-
@"peerConnectionId": peerConnection.reactTag,
|
|
787
|
-
@"reactTag": reactTag,
|
|
788
|
-
@"label": dataChannel.label,
|
|
789
|
-
@"id": @(dataChannel.channelId),
|
|
790
|
-
@"ordered": @(dataChannel.isOrdered),
|
|
791
|
-
@"maxPacketLifeTime": @(dataChannel.maxPacketLifeTime),
|
|
792
|
-
@"maxRetransmits": @(dataChannel.maxRetransmits),
|
|
793
|
-
@"protocol": dataChannel.protocol,
|
|
794
|
-
@"negotiated": @(dataChannel.isNegotiated),
|
|
795
|
-
@"readyState": [self stringForDataChannelState:dataChannel.readyState]
|
|
796
|
-
};
|
|
797
|
-
NSDictionary *body = @{
|
|
798
|
-
@"pcId": peerConnection.reactTag,
|
|
799
|
-
@"dataChannel": dataChannelInfo
|
|
800
|
-
};
|
|
801
|
-
[self sendEventWithName:kEventPeerConnectionDidOpenDataChannel body:body];
|
|
782
|
+
dispatch_async(self.workerQueue, ^{
|
|
783
|
+
id newSdp = @{};
|
|
784
|
+
// Can happen when doing a rollback.
|
|
785
|
+
if (peerConnection.localDescription) {
|
|
786
|
+
newSdp = @{
|
|
787
|
+
@"type" : [RTCSessionDescription stringForType:peerConnection.localDescription.type],
|
|
788
|
+
@"sdp" : peerConnection.localDescription.sdp
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
[self sendEventWithName:kEventPeerConnectionGotICECandidate
|
|
793
|
+
body:@{
|
|
794
|
+
@"pcId" : peerConnection.reactTag,
|
|
795
|
+
@"candidate" : @{
|
|
796
|
+
@"candidate" : candidate.sdp,
|
|
797
|
+
@"sdpMLineIndex" : @(candidate.sdpMLineIndex),
|
|
798
|
+
@"sdpMid" : candidate.sdpMid
|
|
799
|
+
},
|
|
800
|
+
@"sdp" : newSdp
|
|
801
|
+
}];
|
|
802
|
+
});
|
|
802
803
|
}
|
|
803
804
|
|
|
804
|
-
- (void)peerConnection:(
|
|
805
|
+
- (void)peerConnection:(RTCPeerConnection *)peerConnection didOpenDataChannel:(RTCDataChannel *)dataChannel {
|
|
806
|
+
dispatch_async(self.workerQueue, ^{
|
|
807
|
+
NSString *reactTag = [[NSUUID UUID] UUIDString];
|
|
808
|
+
DataChannelWrapper *dcw = [[DataChannelWrapper alloc] initWithChannel:dataChannel reactTag:reactTag];
|
|
809
|
+
dcw.pcId = peerConnection.reactTag;
|
|
810
|
+
peerConnection.dataChannels[reactTag] = dcw;
|
|
811
|
+
dcw.delegate = self;
|
|
812
|
+
|
|
813
|
+
NSDictionary *dataChannelInfo = @{
|
|
814
|
+
@"peerConnectionId" : peerConnection.reactTag,
|
|
815
|
+
@"reactTag" : reactTag,
|
|
816
|
+
@"label" : dataChannel.label,
|
|
817
|
+
@"id" : @(dataChannel.channelId),
|
|
818
|
+
@"ordered" : @(dataChannel.isOrdered),
|
|
819
|
+
@"maxPacketLifeTime" : @(dataChannel.maxPacketLifeTime),
|
|
820
|
+
@"maxRetransmits" : @(dataChannel.maxRetransmits),
|
|
821
|
+
@"protocol" : dataChannel.protocol,
|
|
822
|
+
@"negotiated" : @(dataChannel.isNegotiated),
|
|
823
|
+
@"readyState" : [self stringForDataChannelState:dataChannel.readyState]
|
|
824
|
+
};
|
|
825
|
+
NSDictionary *body = @{@"pcId" : peerConnection.reactTag, @"dataChannel" : dataChannelInfo};
|
|
826
|
+
|
|
827
|
+
[self sendEventWithName:kEventPeerConnectionDidOpenDataChannel body:body];
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
- (void)peerConnection:(RTC_OBJC_TYPE(RTCPeerConnection) *)peerConnection
|
|
832
|
+
didAddReceiver:(RTC_OBJC_TYPE(RTCRtpReceiver) *)rtpReceiver
|
|
805
833
|
streams:(NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *)mediaStreams {
|
|
806
834
|
dispatch_async(self.workerQueue, ^{
|
|
807
835
|
RTCRtpTransceiver *transceiver = nil;
|
|
808
836
|
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
809
|
-
if ([rtpReceiver.receiverId isEqual:
|
|
837
|
+
if ([rtpReceiver.receiverId isEqual:t.receiver.receiverId]) {
|
|
810
838
|
transceiver = t;
|
|
811
839
|
break;
|
|
812
840
|
}
|
|
813
841
|
}
|
|
814
|
-
|
|
842
|
+
|
|
815
843
|
if (!transceiver) {
|
|
816
844
|
RCTLogWarn(@"Transceiver not found in didAddReceiver()");
|
|
817
845
|
return;
|
|
818
846
|
}
|
|
819
|
-
|
|
847
|
+
|
|
820
848
|
RTCMediaStreamTrack *track = rtpReceiver.track;
|
|
821
|
-
|
|
849
|
+
|
|
822
850
|
// We need to fire this event for an existing track sometimes, like
|
|
823
851
|
// when the transceiver direction (on the sending side) switches from
|
|
824
852
|
// sendrecv to recvonly and then back.
|
|
@@ -827,45 +855,46 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
827
855
|
if (!existingTrack) {
|
|
828
856
|
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
829
857
|
RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
|
|
830
|
-
[peerConnection addVideoTrackAdapter:
|
|
858
|
+
[peerConnection addVideoTrackAdapter:videoTrack];
|
|
831
859
|
}
|
|
832
|
-
|
|
860
|
+
|
|
833
861
|
peerConnection.remoteTracks[track.trackId] = track;
|
|
834
862
|
}
|
|
835
|
-
|
|
863
|
+
|
|
836
864
|
NSMutableDictionary *params = [NSMutableDictionary new];
|
|
837
865
|
NSMutableArray *streams = [NSMutableArray new];
|
|
838
|
-
|
|
839
|
-
for (RTCMediaStream *
|
|
866
|
+
|
|
867
|
+
for (RTCMediaStream *stream in mediaStreams) {
|
|
840
868
|
NSString *streamReactTag = nil;
|
|
841
869
|
|
|
842
|
-
for (NSString *
|
|
843
|
-
if ([[peerConnection.remoteStreams objectForKey:key] isEqual:stream]) {
|
|
870
|
+
for (NSString *key in [peerConnection.remoteStreams allKeys]) {
|
|
871
|
+
if ([[peerConnection.remoteStreams objectForKey:key].streamId isEqual:stream.streamId]) {
|
|
844
872
|
streamReactTag = key;
|
|
845
873
|
break;
|
|
846
874
|
}
|
|
847
875
|
}
|
|
848
|
-
|
|
849
|
-
if (!peerConnection.remoteStreams[stream.streamId]) {
|
|
850
|
-
peerConnection.remoteStreams[stream.streamId] = stream;
|
|
851
|
-
}
|
|
852
|
-
|
|
876
|
+
|
|
853
877
|
if (!streamReactTag) {
|
|
854
|
-
|
|
855
|
-
streamReactTag = [uuid UUIDString];
|
|
856
|
-
peerConnection.remoteStreams[streamReactTag] = stream;
|
|
878
|
+
streamReactTag = [[NSUUID UUID] UUIDString];
|
|
857
879
|
}
|
|
858
|
-
|
|
859
|
-
|
|
880
|
+
|
|
881
|
+
// Make sure the stored stream is updated in case we get a new reference.
|
|
882
|
+
peerConnection.remoteStreams[streamReactTag] = stream;
|
|
883
|
+
|
|
884
|
+
[streams addObject:[SerializeUtils streamToJSONWithPeerConnectionId:peerConnection.reactTag
|
|
885
|
+
stream:stream
|
|
886
|
+
streamReactTag:streamReactTag]];
|
|
860
887
|
}
|
|
861
|
-
|
|
888
|
+
|
|
862
889
|
params[@"streams"] = streams;
|
|
863
|
-
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId:
|
|
890
|
+
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId:peerConnection.reactTag
|
|
891
|
+
receiver:rtpReceiver];
|
|
864
892
|
params[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
865
|
-
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:
|
|
893
|
+
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:peerConnection.reactTag
|
|
894
|
+
transceiver:transceiver];
|
|
866
895
|
params[@"pcId"] = peerConnection.reactTag;
|
|
867
|
-
|
|
868
|
-
[self sendEventWithName:
|
|
896
|
+
|
|
897
|
+
[self sendEventWithName:kEventPeerConnectionOnTrack body:params];
|
|
869
898
|
});
|
|
870
899
|
}
|
|
871
900
|
|
|
@@ -877,11 +906,12 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
877
906
|
params[@"pcId"] = peerConnection.reactTag;
|
|
878
907
|
params[@"receiverId"] = rtpReceiver.receiverId;
|
|
879
908
|
|
|
880
|
-
[self sendEventWithName:
|
|
909
|
+
[self sendEventWithName:kEventPeerConnectionOnRemoveTrack body:params];
|
|
881
910
|
});
|
|
882
911
|
}
|
|
883
912
|
|
|
884
|
-
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
|
|
913
|
+
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
|
|
914
|
+
didRemoveIceCandidates:(nonnull NSArray<RTCIceCandidate *> *)candidates {
|
|
885
915
|
// Unimplemented, there is no matching web API.
|
|
886
916
|
}
|
|
887
917
|
|