react-native-webrtc 106.0.5 → 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/LICENSE +2 -1
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +0 -1
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +7 -15
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +3 -12
- 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 +29 -43
- 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 +11 -13
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +116 -119
- 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 +3 -4
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +5 -9
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +335 -350
- 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 +2 -9
- package/ios/RCTWebRTC/CaptureController.m +0 -7
- 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 +205 -214
- package/ios/RCTWebRTC/ScreenCaptureController.h +2 -9
- package/ios/RCTWebRTC/ScreenCaptureController.m +10 -16
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +0 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +26 -34
- package/ios/RCTWebRTC/ScreenCapturer.h +1 -8
- package/ios/RCTWebRTC/ScreenCapturer.m +56 -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 +4 -4
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +5 -6
- 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 +3 -2
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +196 -226
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +7 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +625 -603
- 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 +13 -20
- package/ios/RCTWebRTC/WebRTCModule.m +69 -84
- package/ios/RCTWebRTC.xcworkspace/xcuserdata/saghul.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/RTCPeerConnection.js +79 -56
- 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/RTCPeerConnection.js +79 -56
- 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/RTCPeerConnection.d.ts +4 -4
- package/package.json +3 -2
- package/src/RTCPeerConnection.ts +70 -63
- 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,469 +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
|
-
@"type": @"CreateAnswerFailed",
|
|
186
|
-
@"message": error.localizedDescription ?: [NSNull null]
|
|
187
|
-
}
|
|
188
|
-
]);
|
|
189
|
-
} else {
|
|
190
|
-
NSString *type = [RTCSessionDescription stringForType:sdp.type];
|
|
191
|
-
callback(@[@(YES), @{
|
|
192
|
-
@"sdpInfo": @{@"sdp": sdp.sdp,
|
|
193
|
-
@"type": type},
|
|
194
|
-
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection]
|
|
195
|
-
}]);
|
|
196
|
-
}
|
|
197
|
-
}];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
RCT_EXPORT_METHOD(peerConnectionSetLocalDescription:(nonnull NSNumber *)objectID
|
|
201
|
-
desc:(RTCSessionDescription *)desc
|
|
202
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
203
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
204
|
-
{
|
|
205
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
206
|
-
if (!peerConnection) {
|
|
207
|
-
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
__weak RTCPeerConnection *weakPc = peerConnection;
|
|
212
|
-
|
|
213
|
-
RTCSetSessionDescriptionCompletionHandler handler = ^(NSError *error) {
|
|
214
|
-
dispatch_async(self.workerQueue, ^{
|
|
215
|
-
if (error) {
|
|
216
|
-
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
217
|
-
} else {
|
|
218
|
-
RTCPeerConnection *strongPc = weakPc;
|
|
219
|
-
NSMutableDictionary *sdpInfo = [NSMutableDictionary new];
|
|
220
|
-
RTCSessionDescription *localDesc = strongPc.localDescription;
|
|
221
|
-
if (localDesc) {
|
|
222
|
-
sdpInfo[@"type"] = [RTCSessionDescription stringForType:localDesc.type];
|
|
223
|
-
sdpInfo[@"sdp"] = localDesc.sdp;
|
|
224
|
-
}
|
|
225
|
-
id data = @{
|
|
226
|
-
@"sdpInfo": sdpInfo,
|
|
227
|
-
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection]
|
|
228
|
-
};
|
|
229
|
-
resolve(data);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
if (desc == nil) {
|
|
235
|
-
[peerConnection setLocalDescriptionWithCompletionHandler:handler];
|
|
236
|
-
} else {
|
|
237
|
-
[peerConnection setLocalDescription:desc completionHandler:handler];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
RCT_EXPORT_METHOD(peerConnectionSetRemoteDescription:(nonnull NSNumber *)objectID
|
|
242
|
-
desc:(RTCSessionDescription *)desc
|
|
243
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
244
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
245
|
-
{
|
|
246
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
247
|
-
if (!peerConnection) {
|
|
248
|
-
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
NSMutableArray *receiversIds = [NSMutableArray new];
|
|
253
|
-
for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
|
|
254
|
-
[receiversIds addObject:transceiver.receiver.receiverId];
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
__weak RTCPeerConnection *weakPc = peerConnection;
|
|
258
|
-
|
|
259
|
-
RTCSetSessionDescriptionCompletionHandler handler = ^(NSError *error) {
|
|
260
|
-
dispatch_async(self.workerQueue, ^{
|
|
261
|
-
if (error) {
|
|
262
|
-
reject(@"E_OPERATION_ERROR", error.localizedDescription, nil);
|
|
263
|
-
} else {
|
|
264
|
-
NSMutableArray *newTransceivers = [NSMutableArray new];
|
|
265
|
-
for (RTCRtpTransceiver *transceiver in peerConnection.transceivers) {
|
|
266
|
-
if (![receiversIds containsObject:transceiver.receiver.receiverId]) {
|
|
267
|
-
NSMutableDictionary *newTransceiver = [NSMutableDictionary new];
|
|
268
|
-
newTransceiver[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
269
|
-
newTransceiver[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver];
|
|
270
|
-
[newTransceivers addObject:newTransceiver];
|
|
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);
|
|
271
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);
|
|
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];
|
|
272
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
|
+
}
|
|
334
|
+
|
|
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
|
+
}
|
|
273
344
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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;
|
|
279
366
|
}
|
|
280
|
-
id data = @{
|
|
281
|
-
@"sdpInfo": sdpInfo,
|
|
282
|
-
@"transceiversInfo": [SerializeUtils constructTransceiversInfoArrayWithPeerConnection:peerConnection],
|
|
283
|
-
@"newTransceivers": newTransceivers
|
|
284
|
-
};
|
|
285
|
-
resolve(data);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
[peerConnection setRemoteDescription:desc completionHandler:handler];
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
RCT_EXPORT_METHOD(peerConnectionAddICECandidate:(nonnull NSNumber *)objectID
|
|
294
|
-
candidate:(RTCIceCandidate*)candidate
|
|
295
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
296
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
297
|
-
{
|
|
298
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
299
|
-
if (!peerConnection) {
|
|
300
|
-
reject(@"E_INVALID", @"PeerConnection not found", nil);
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
__weak RTCPeerConnection *weakPc = peerConnection;
|
|
305
|
-
[peerConnection addIceCandidate:candidate
|
|
306
|
-
completionHandler:^(NSError *error) {
|
|
307
|
-
if (error) {
|
|
308
|
-
reject(@"E_OPERATION_ERROR", @"addIceCandidate failed", error);
|
|
309
|
-
} else {
|
|
310
|
-
RTCPeerConnection *strongPc = weakPc;
|
|
311
|
-
id newSdp = @{
|
|
312
|
-
@"type": [RTCSessionDescription stringForType:strongPc.remoteDescription.type],
|
|
313
|
-
@"sdp": strongPc.remoteDescription.sdp
|
|
314
|
-
};
|
|
315
|
-
resolve(newSdp);
|
|
316
|
-
}
|
|
317
|
-
}];
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
RCT_EXPORT_METHOD(peerConnectionClose:(nonnull NSNumber *)objectID)
|
|
321
|
-
{
|
|
322
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
323
|
-
if (!peerConnection) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Remove video track adapters
|
|
328
|
-
for (NSString *key in peerConnection.remoteTracks.allKeys) {
|
|
329
|
-
RTCMediaStreamTrack *track = peerConnection.remoteTracks[key];
|
|
330
|
-
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
331
|
-
[peerConnection removeVideoTrackAdapter: (RTCVideoTrack*) track];
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
[peerConnection close];
|
|
336
|
-
|
|
337
|
-
// Clean up peerConnection's streams and tracks
|
|
338
|
-
[peerConnection.remoteStreams removeAllObjects];
|
|
339
|
-
[peerConnection.remoteTracks removeAllObjects];
|
|
340
|
-
|
|
341
|
-
// Clean up peerConnection's dataChannels.
|
|
342
|
-
NSMutableDictionary<NSString *, DataChannelWrapper *> *dataChannels = peerConnection.dataChannels;
|
|
343
|
-
for (NSString *tag in dataChannels) {
|
|
344
|
-
dataChannels[tag].delegate = nil;
|
|
345
|
-
// There is no need to close the RTCDataChannel because it is owned by the
|
|
346
|
-
// RTCPeerConnection and the latter will close the former.
|
|
347
|
-
}
|
|
348
|
-
[dataChannels removeAllObjects];
|
|
349
|
-
|
|
350
|
-
[self.peerConnections removeObjectForKey:objectID];
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
RCT_EXPORT_METHOD(peerConnectionGetStats:(nonnull NSNumber *) objectID
|
|
354
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
355
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
356
|
-
{
|
|
357
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
358
|
-
if (!peerConnection) {
|
|
359
|
-
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
[peerConnection statisticsWithCompletionHandler:^(RTCStatisticsReport *report) {
|
|
364
|
-
resolve([self statsToJSON:report]);
|
|
365
|
-
}];
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
RCT_EXPORT_METHOD(receiverGetStats:(nonnull NSNumber *) pcId
|
|
369
|
-
receiverId:(nonnull NSString *) receiverId
|
|
370
|
-
resolver:(RCTPromiseResolveBlock)resolve
|
|
371
|
-
rejecter:(RCTPromiseRejectBlock)reject)
|
|
372
|
-
{
|
|
373
|
-
RTCPeerConnection *peerConnection = self.peerConnections[pcId];
|
|
374
|
-
if (!peerConnection) {
|
|
375
|
-
reject(@"invalid_id", @"PeerConnection ID not found", nil);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
RTCRtpReceiver *receiver;
|
|
380
|
-
for (RTCRtpReceiver *findRecv in peerConnection.receivers) {
|
|
381
|
-
if ([findRecv.receiverId isEqualToString:receiverId]) {
|
|
382
|
-
receiver = findRecv;
|
|
383
|
-
break;
|
|
384
367
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
RCT_EXPORT_METHOD(senderGetStats
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
{
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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;
|
|
389
|
+
}
|
|
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;
|
|
413
414
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}];
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
RCT_EXPORT_METHOD(peerConnectionRestartIce:(nonnull NSNumber *)objectID)
|
|
427
|
-
{
|
|
428
|
-
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
429
|
-
if (!peerConnection) {
|
|
430
|
-
return;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
[peerConnection restartIce];
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTrack:(nonnull NSNumber *)objectID
|
|
437
|
-
trackId:(NSString *)trackId
|
|
438
|
-
options:(NSDictionary *)options)
|
|
439
|
-
{
|
|
440
|
-
__block id params = nil;
|
|
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;
|
|
441
424
|
|
|
442
425
|
dispatch_sync(self.workerQueue, ^{
|
|
443
426
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
444
427
|
if (!peerConnection) {
|
|
445
|
-
|
|
446
|
-
|
|
428
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTrack()", objectID);
|
|
429
|
+
return;
|
|
447
430
|
}
|
|
448
431
|
|
|
449
432
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
450
433
|
|
|
451
434
|
NSArray *streamIds = [options objectForKey:@"streamIds"];
|
|
452
|
-
RTCRtpSender *sender = [peerConnection addTrack:
|
|
435
|
+
RTCRtpSender *sender = [peerConnection addTrack:track streamIds:streamIds];
|
|
453
436
|
RTCRtpTransceiver *transceiver = nil;
|
|
454
|
-
|
|
437
|
+
|
|
455
438
|
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
439
|
+
if ([t.sender.senderId isEqual:sender.senderId]) {
|
|
440
|
+
transceiver = t;
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
460
443
|
}
|
|
461
|
-
|
|
444
|
+
|
|
462
445
|
if (!transceiver) {
|
|
463
446
|
RCTLogWarn(@"Transceiver not found in peerConnectionAddTrack()");
|
|
464
447
|
return;
|
|
465
448
|
}
|
|
466
|
-
|
|
449
|
+
|
|
467
450
|
params = @{
|
|
468
|
-
@"transceiverOrder": [NSNumber numberWithInt:_transceiverNextId++],
|
|
469
|
-
@"transceiver": [SerializeUtils transceiverToJSONWithPeerConnectionId:
|
|
470
|
-
@"sender": [SerializeUtils senderToJSONWithPeerConnectionId:
|
|
451
|
+
@"transceiverOrder" : [NSNumber numberWithInt:_transceiverNextId++],
|
|
452
|
+
@"transceiver" : [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver],
|
|
453
|
+
@"sender" : [SerializeUtils senderToJSONWithPeerConnectionId:objectID sender:sender]
|
|
471
454
|
};
|
|
472
455
|
});
|
|
473
456
|
|
|
474
457
|
return params;
|
|
475
458
|
}
|
|
476
459
|
|
|
477
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver
|
|
478
|
-
|
|
479
|
-
{
|
|
460
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionAddTransceiver
|
|
461
|
+
: (nonnull NSNumber *)objectID options
|
|
462
|
+
: (NSDictionary *)options) {
|
|
480
463
|
__block id params = nil;
|
|
481
464
|
|
|
482
465
|
dispatch_sync(self.workerQueue, ^{
|
|
483
466
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
484
467
|
if (!peerConnection) {
|
|
485
|
-
|
|
486
|
-
|
|
468
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionAddTransceiver()", objectID);
|
|
469
|
+
return;
|
|
487
470
|
}
|
|
488
471
|
|
|
489
472
|
RTCRtpTransceiver *transceiver = nil;
|
|
490
473
|
NSString *kind = [options objectForKey:@"type"];
|
|
491
474
|
NSString *trackId = [options objectForKey:@"trackId"];
|
|
492
475
|
RTCRtpMediaType type = RTCRtpMediaTypeUnsupported;
|
|
493
|
-
|
|
476
|
+
|
|
494
477
|
if (kind) {
|
|
495
|
-
if ([kind isEqual
|
|
478
|
+
if ([kind isEqual:@"audio"]) {
|
|
496
479
|
type = RTCRtpMediaTypeAudio;
|
|
497
|
-
} else if ([kind isEqual
|
|
480
|
+
} else if ([kind isEqual:@"video"]) {
|
|
498
481
|
type = RTCRtpMediaTypeVideo;
|
|
499
482
|
}
|
|
500
483
|
|
|
501
|
-
NSDictionary *initOptions = [options objectForKey
|
|
502
|
-
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:
|
|
484
|
+
NSDictionary *initOptions = [options objectForKey:@"init"];
|
|
485
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:initOptions];
|
|
503
486
|
|
|
504
|
-
transceiver = [peerConnection addTransceiverOfType:
|
|
487
|
+
transceiver = [peerConnection addTransceiverOfType:type init:transceiverInit];
|
|
505
488
|
} else if (trackId) {
|
|
506
489
|
RTCMediaStreamTrack *track = self.localTracks[trackId];
|
|
507
|
-
|
|
490
|
+
|
|
508
491
|
if (!track) {
|
|
509
492
|
track = peerConnection.remoteTracks[trackId];
|
|
510
493
|
}
|
|
511
|
-
|
|
512
|
-
NSDictionary *initOptions = [options objectForKey: @"init"];
|
|
513
|
-
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions: initOptions];
|
|
514
494
|
|
|
515
|
-
|
|
495
|
+
NSDictionary *initOptions = [options objectForKey:@"init"];
|
|
496
|
+
RTCRtpTransceiverInit *transceiverInit = [SerializeUtils parseTransceiverOptions:initOptions];
|
|
497
|
+
|
|
498
|
+
transceiver = [peerConnection addTransceiverWithTrack:track init:transceiverInit];
|
|
516
499
|
} else {
|
|
517
500
|
RCTLogWarn(@"peerConnectionAddTransceiver() no type nor trackId provided in options");
|
|
518
501
|
return;
|
|
519
502
|
}
|
|
520
|
-
|
|
503
|
+
|
|
521
504
|
if (transceiver == nil) {
|
|
522
505
|
RCTLogWarn(@"peerConnectionAddTransceiver() Error adding transceiver");
|
|
523
506
|
return;
|
|
524
507
|
}
|
|
525
|
-
|
|
508
|
+
|
|
526
509
|
params = @{
|
|
527
|
-
|
|
528
|
-
|
|
510
|
+
@"transceiverOrder" : [NSNumber numberWithInt:_transceiverNextId++],
|
|
511
|
+
@"transceiver" : [SerializeUtils transceiverToJSONWithPeerConnectionId:objectID transceiver:transceiver]
|
|
529
512
|
};
|
|
530
513
|
});
|
|
531
514
|
|
|
532
515
|
return params;
|
|
533
516
|
}
|
|
534
517
|
|
|
535
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack
|
|
536
|
-
|
|
537
|
-
{
|
|
518
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack
|
|
519
|
+
: (nonnull NSNumber *)objectID senderId
|
|
520
|
+
: (nonnull NSString *)senderId) {
|
|
538
521
|
__block BOOL ret = NO;
|
|
539
522
|
|
|
540
523
|
dispatch_sync(self.workerQueue, ^{
|
|
541
524
|
RTCPeerConnection *peerConnection = self.peerConnections[objectID];
|
|
542
525
|
if (!peerConnection) {
|
|
543
|
-
|
|
544
|
-
|
|
526
|
+
RCTLogWarn(@"PeerConnection %@ not found in peerConnectionRemoveTrack()", objectID);
|
|
527
|
+
return;
|
|
545
528
|
}
|
|
546
529
|
|
|
547
530
|
RTCRtpSender *sender = nil;
|
|
548
531
|
|
|
549
532
|
for (RTCRtpSender *s in peerConnection.senders) {
|
|
550
|
-
if ([s.senderId isEqual:
|
|
533
|
+
if ([s.senderId isEqual:senderId]) {
|
|
551
534
|
sender = s;
|
|
552
535
|
break;
|
|
553
536
|
}
|
|
@@ -558,7 +541,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
558
541
|
return;
|
|
559
542
|
}
|
|
560
543
|
|
|
561
|
-
ret = [peerConnection removeTrack:
|
|
544
|
+
ret = [peerConnection removeTrack:sender];
|
|
562
545
|
});
|
|
563
546
|
|
|
564
547
|
return @(ret);
|
|
@@ -575,57 +558,56 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
575
558
|
* @return an <tt>NSString</tt> which represents the specified <tt>report</tt> in
|
|
576
559
|
* JSON format
|
|
577
560
|
*/
|
|
578
|
-
- (NSString *)statsToJSON:(RTCStatisticsReport *)report
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
[s appendString:@"[\""];
|
|
602
|
-
[s appendString: key];
|
|
603
|
-
[s appendString:@"\",{"];
|
|
604
|
-
|
|
605
|
-
RTCStatistics *statistics = report.statistics[key];
|
|
606
|
-
[s appendString:@"\"timestamp\":"];
|
|
607
|
-
[s appendFormat:@"%f", statistics.timestamp_us / 1000.0];
|
|
608
|
-
[s appendString:@",\"type\":\""];
|
|
609
|
-
[s appendString:statistics.type];
|
|
610
|
-
[s appendString:@"\",\"id\":\""];
|
|
611
|
-
[s appendString:statistics.id];
|
|
612
|
-
[s appendString:@"\""];
|
|
613
|
-
|
|
614
|
-
for (id key in statistics.values) {
|
|
615
|
-
[s appendString:@","];
|
|
616
|
-
[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:@"[\""];
|
|
617
584
|
[s appendString:key];
|
|
618
|
-
[s appendString:@"\"
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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:@"\""];
|
|
622
595
|
|
|
623
|
-
|
|
624
|
-
|
|
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
|
+
}
|
|
625
604
|
|
|
626
|
-
|
|
605
|
+
[s appendString:@"}]"];
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
[s appendString:@"]"];
|
|
627
609
|
|
|
628
|
-
|
|
610
|
+
return s;
|
|
629
611
|
}
|
|
630
612
|
|
|
631
613
|
- (void)appendValue:(NSObject *)statisticsValue toString:(NSMutableString *)s {
|
|
@@ -633,7 +615,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
633
615
|
[s appendString:@"["];
|
|
634
616
|
BOOL firstValue = YES;
|
|
635
617
|
for (NSObject *element in (NSArray *)statisticsValue) {
|
|
636
|
-
if(firstValue) {
|
|
618
|
+
if (firstValue) {
|
|
637
619
|
firstValue = NO;
|
|
638
620
|
} else {
|
|
639
621
|
[s appendString:@","];
|
|
@@ -642,14 +624,12 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
642
624
|
[s appendString:@"\""];
|
|
643
625
|
[s appendString:[NSString stringWithFormat:@"%@", element]];
|
|
644
626
|
[s appendString:@"\""];
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
[s appendString:@"]"];
|
|
648
630
|
} else if ([statisticsValue isKindOfClass:[NSDictionary class]]) {
|
|
649
631
|
NSError *error;
|
|
650
|
-
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue
|
|
651
|
-
options:0
|
|
652
|
-
error:&error];
|
|
632
|
+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:statisticsValue options:0 error:&error];
|
|
653
633
|
|
|
654
634
|
if (!jsonData) {
|
|
655
635
|
[s appendString:@"\""];
|
|
@@ -669,164 +649,204 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
669
649
|
}
|
|
670
650
|
|
|
671
651
|
- (NSString *)stringForPeerConnectionState:(RTCPeerConnectionState)state {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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;
|
|
681
667
|
}
|
|
682
668
|
|
|
683
669
|
- (NSString *)stringForICEConnectionState:(RTCIceConnectionState)state {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
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;
|
|
695
689
|
}
|
|
696
690
|
|
|
697
691
|
- (NSString *)stringForICEGatheringState:(RTCIceGatheringState)state {
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
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;
|
|
704
701
|
}
|
|
705
702
|
|
|
706
703
|
- (NSString *)stringForSignalingState:(RTCSignalingState)state {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
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;
|
|
716
719
|
}
|
|
717
720
|
|
|
718
721
|
#pragma mark - RTCPeerConnectionDelegate methods
|
|
719
722
|
|
|
720
723
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeSignalingState:(RTCSignalingState)newState {
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
724
|
+
dispatch_async(self.workerQueue, ^{
|
|
725
|
+
[self sendEventWithName:kEventPeerConnectionSignalingStateChanged
|
|
726
|
+
body:@{
|
|
727
|
+
@"pcId" : peerConnection.reactTag,
|
|
728
|
+
@"signalingState" : [self stringForSignalingState:newState]
|
|
729
|
+
}];
|
|
730
|
+
});
|
|
726
731
|
}
|
|
727
732
|
|
|
728
733
|
- (void)peerConnectionShouldNegotiate:(RTCPeerConnection *)peerConnection {
|
|
729
|
-
|
|
730
|
-
|
|
734
|
+
dispatch_async(self.workerQueue, ^{
|
|
735
|
+
[self sendEventWithName:kEventPeerConnectionOnRenegotiationNeeded body:@{@"pcId" : peerConnection.reactTag}];
|
|
736
|
+
});
|
|
731
737
|
}
|
|
732
738
|
|
|
733
739
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeConnectionState:(RTCPeerConnectionState)newState {
|
|
734
|
-
|
|
735
|
-
|
|
740
|
+
dispatch_async(self.workerQueue, ^{
|
|
741
|
+
[self sendEventWithName:kEventPeerConnectionStateChanged
|
|
742
|
+
body:@{
|
|
743
|
+
@"pcId" : peerConnection.reactTag,
|
|
744
|
+
@"connectionState" : [self stringForPeerConnectionState:newState]
|
|
745
|
+
}];
|
|
746
|
+
});
|
|
736
747
|
}
|
|
737
748
|
|
|
738
749
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeIceConnectionState:(RTCIceConnectionState)newState {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
750
|
+
dispatch_async(self.workerQueue, ^{
|
|
751
|
+
[self sendEventWithName:kEventPeerConnectionIceConnectionChanged
|
|
752
|
+
body:@{
|
|
753
|
+
@"pcId" : peerConnection.reactTag,
|
|
754
|
+
@"iceConnectionState" : [self stringForICEConnectionState:newState]
|
|
755
|
+
}];
|
|
756
|
+
});
|
|
744
757
|
}
|
|
745
758
|
|
|
746
759
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didChangeIceGatheringState:(RTCIceGatheringState)newState {
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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
|
+
});
|
|
763
779
|
}
|
|
764
780
|
|
|
765
781
|
- (void)peerConnection:(RTCPeerConnection *)peerConnection didGenerateIceCandidate:(RTCIceCandidate *)candidate {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
NSString *reactTag = [[NSUUID UUID] UUIDString];
|
|
788
|
-
DataChannelWrapper *dcw = [[DataChannelWrapper alloc] initWithChannel:dataChannel reactTag:reactTag];
|
|
789
|
-
dcw.pcId = peerConnection.reactTag;
|
|
790
|
-
peerConnection.dataChannels[reactTag] = dcw;
|
|
791
|
-
dcw.delegate = self;
|
|
792
|
-
|
|
793
|
-
NSDictionary *dataChannelInfo = @{
|
|
794
|
-
@"peerConnectionId": peerConnection.reactTag,
|
|
795
|
-
@"reactTag": reactTag,
|
|
796
|
-
@"label": dataChannel.label,
|
|
797
|
-
@"id": @(dataChannel.channelId),
|
|
798
|
-
@"ordered": @(dataChannel.isOrdered),
|
|
799
|
-
@"maxPacketLifeTime": @(dataChannel.maxPacketLifeTime),
|
|
800
|
-
@"maxRetransmits": @(dataChannel.maxRetransmits),
|
|
801
|
-
@"protocol": dataChannel.protocol,
|
|
802
|
-
@"negotiated": @(dataChannel.isNegotiated),
|
|
803
|
-
@"readyState": [self stringForDataChannelState:dataChannel.readyState]
|
|
804
|
-
};
|
|
805
|
-
NSDictionary *body = @{
|
|
806
|
-
@"pcId": peerConnection.reactTag,
|
|
807
|
-
@"dataChannel": dataChannelInfo
|
|
808
|
-
};
|
|
809
|
-
[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
|
+
});
|
|
810
803
|
}
|
|
811
804
|
|
|
812
|
-
- (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
|
|
813
833
|
streams:(NSArray<RTC_OBJC_TYPE(RTCMediaStream) *> *)mediaStreams {
|
|
814
834
|
dispatch_async(self.workerQueue, ^{
|
|
815
835
|
RTCRtpTransceiver *transceiver = nil;
|
|
816
836
|
for (RTCRtpTransceiver *t in peerConnection.transceivers) {
|
|
817
|
-
if ([rtpReceiver.receiverId isEqual:
|
|
837
|
+
if ([rtpReceiver.receiverId isEqual:t.receiver.receiverId]) {
|
|
818
838
|
transceiver = t;
|
|
819
839
|
break;
|
|
820
840
|
}
|
|
821
841
|
}
|
|
822
|
-
|
|
842
|
+
|
|
823
843
|
if (!transceiver) {
|
|
824
844
|
RCTLogWarn(@"Transceiver not found in didAddReceiver()");
|
|
825
845
|
return;
|
|
826
846
|
}
|
|
827
|
-
|
|
847
|
+
|
|
828
848
|
RTCMediaStreamTrack *track = rtpReceiver.track;
|
|
829
|
-
|
|
849
|
+
|
|
830
850
|
// We need to fire this event for an existing track sometimes, like
|
|
831
851
|
// when the transceiver direction (on the sending side) switches from
|
|
832
852
|
// sendrecv to recvonly and then back.
|
|
@@ -835,45 +855,46 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
835
855
|
if (!existingTrack) {
|
|
836
856
|
if (track.kind == kRTCMediaStreamTrackKindVideo) {
|
|
837
857
|
RTCVideoTrack *videoTrack = (RTCVideoTrack *)track;
|
|
838
|
-
[peerConnection addVideoTrackAdapter:
|
|
858
|
+
[peerConnection addVideoTrackAdapter:videoTrack];
|
|
839
859
|
}
|
|
840
|
-
|
|
860
|
+
|
|
841
861
|
peerConnection.remoteTracks[track.trackId] = track;
|
|
842
862
|
}
|
|
843
|
-
|
|
863
|
+
|
|
844
864
|
NSMutableDictionary *params = [NSMutableDictionary new];
|
|
845
865
|
NSMutableArray *streams = [NSMutableArray new];
|
|
846
|
-
|
|
847
|
-
for (RTCMediaStream *
|
|
866
|
+
|
|
867
|
+
for (RTCMediaStream *stream in mediaStreams) {
|
|
848
868
|
NSString *streamReactTag = nil;
|
|
849
869
|
|
|
850
|
-
for (NSString *
|
|
851
|
-
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]) {
|
|
852
872
|
streamReactTag = key;
|
|
853
873
|
break;
|
|
854
874
|
}
|
|
855
875
|
}
|
|
856
|
-
|
|
857
|
-
if (!peerConnection.remoteStreams[stream.streamId]) {
|
|
858
|
-
peerConnection.remoteStreams[stream.streamId] = stream;
|
|
859
|
-
}
|
|
860
|
-
|
|
876
|
+
|
|
861
877
|
if (!streamReactTag) {
|
|
862
|
-
|
|
863
|
-
streamReactTag = [uuid UUIDString];
|
|
864
|
-
peerConnection.remoteStreams[streamReactTag] = stream;
|
|
878
|
+
streamReactTag = [[NSUUID UUID] UUIDString];
|
|
865
879
|
}
|
|
866
|
-
|
|
867
|
-
|
|
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]];
|
|
868
887
|
}
|
|
869
|
-
|
|
888
|
+
|
|
870
889
|
params[@"streams"] = streams;
|
|
871
|
-
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId:
|
|
890
|
+
params[@"receiver"] = [SerializeUtils receiverToJSONWithPeerConnectionId:peerConnection.reactTag
|
|
891
|
+
receiver:rtpReceiver];
|
|
872
892
|
params[@"transceiverOrder"] = [NSNumber numberWithInt:_transceiverNextId++];
|
|
873
|
-
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:
|
|
893
|
+
params[@"transceiver"] = [SerializeUtils transceiverToJSONWithPeerConnectionId:peerConnection.reactTag
|
|
894
|
+
transceiver:transceiver];
|
|
874
895
|
params[@"pcId"] = peerConnection.reactTag;
|
|
875
|
-
|
|
876
|
-
[self sendEventWithName:
|
|
896
|
+
|
|
897
|
+
[self sendEventWithName:kEventPeerConnectionOnTrack body:params];
|
|
877
898
|
});
|
|
878
899
|
}
|
|
879
900
|
|
|
@@ -885,11 +906,12 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(peerConnectionRemoveTrack:(nonnull NSNumb
|
|
|
885
906
|
params[@"pcId"] = peerConnection.reactTag;
|
|
886
907
|
params[@"receiverId"] = rtpReceiver.receiverId;
|
|
887
908
|
|
|
888
|
-
[self sendEventWithName:
|
|
909
|
+
[self sendEventWithName:kEventPeerConnectionOnRemoveTrack body:params];
|
|
889
910
|
});
|
|
890
911
|
}
|
|
891
912
|
|
|
892
|
-
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
|
|
913
|
+
- (void)peerConnection:(nonnull RTCPeerConnection *)peerConnection
|
|
914
|
+
didRemoveIceCandidates:(nonnull NSArray<RTCIceCandidate *> *)candidates {
|
|
893
915
|
// Unimplemented, there is no matching web API.
|
|
894
916
|
}
|
|
895
917
|
|