react-native-webrtc 1.100.1 → 106.0.0-beta.2

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.
Files changed (166) hide show
  1. package/ISSUE_TEMPLATE.md +17 -13
  2. package/README.md +46 -129
  3. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +160 -165
  4. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +279 -0
  5. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +361 -56
  6. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +5 -1
  7. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +2 -6
  8. package/ios/RCTWebRTC/ScreenCapturer.m +0 -1
  9. package/ios/RCTWebRTC/SerializeUtils.h +25 -0
  10. package/ios/RCTWebRTC/SerializeUtils.m +219 -0
  11. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +284 -128
  12. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +216 -0
  13. package/ios/RCTWebRTC/WebRTCModule.h +15 -4
  14. package/ios/RCTWebRTC/WebRTCModule.m +26 -6
  15. package/lib/commonjs/EventEmitter.js +24 -0
  16. package/lib/commonjs/EventEmitter.js.map +1 -1
  17. package/lib/commonjs/Logger.js +65 -0
  18. package/lib/commonjs/Logger.js.map +1 -0
  19. package/lib/commonjs/MediaStream.js +1 -1
  20. package/lib/commonjs/MediaStream.js.map +1 -1
  21. package/lib/commonjs/MediaStreamTrack.js +4 -2
  22. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  23. package/lib/commonjs/Permissions.js +1 -1
  24. package/lib/commonjs/Permissions.js.map +1 -1
  25. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  26. package/lib/commonjs/RTCErrorEvent.js +33 -0
  27. package/lib/commonjs/RTCErrorEvent.js.map +1 -0
  28. package/lib/commonjs/RTCPeerConnection.js +380 -102
  29. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  30. package/lib/commonjs/RTCRtcpParameters.js +24 -0
  31. package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
  32. package/lib/commonjs/RTCRtpCapabilities.js +79 -0
  33. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
  34. package/lib/commonjs/RTCRtpCodecCapability.js +25 -0
  35. package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
  36. package/lib/commonjs/RTCRtpCodecParameters.js +33 -0
  37. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
  38. package/lib/commonjs/RTCRtpEncodingParameters.js +81 -0
  39. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
  40. package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
  41. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
  42. package/lib/commonjs/RTCRtpParameters.js +26 -0
  43. package/lib/commonjs/RTCRtpParameters.js.map +1 -0
  44. package/lib/commonjs/RTCRtpReceiveParameters.js +20 -0
  45. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
  46. package/lib/commonjs/RTCRtpReceiver.js +51 -0
  47. package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
  48. package/lib/commonjs/RTCRtpSendParameters.js +60 -0
  49. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
  50. package/lib/commonjs/RTCRtpSender.js +85 -0
  51. package/lib/commonjs/RTCRtpSender.js.map +1 -0
  52. package/lib/commonjs/RTCRtpTransceiver.js +141 -0
  53. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
  54. package/lib/commonjs/RTCSessionDescription.js.map +1 -1
  55. package/lib/commonjs/RTCTrackEvent.js +32 -0
  56. package/lib/commonjs/RTCTrackEvent.js.map +1 -0
  57. package/lib/commonjs/RTCUtil.js +20 -37
  58. package/lib/commonjs/RTCUtil.js.map +1 -1
  59. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  60. package/lib/commonjs/getUserMedia.js.map +1 -1
  61. package/lib/commonjs/index.js +127 -3
  62. package/lib/commonjs/index.js.map +1 -1
  63. package/lib/module/EventEmitter.js +21 -0
  64. package/lib/module/EventEmitter.js.map +1 -1
  65. package/lib/module/Logger.js +53 -0
  66. package/lib/module/Logger.js.map +1 -0
  67. package/lib/module/MediaStream.js +1 -1
  68. package/lib/module/MediaStream.js.map +1 -1
  69. package/lib/module/MediaStreamTrack.js +4 -2
  70. package/lib/module/MediaStreamTrack.js.map +1 -1
  71. package/lib/module/Permissions.js +1 -1
  72. package/lib/module/Permissions.js.map +1 -1
  73. package/lib/module/RTCDataChannel.js.map +1 -1
  74. package/lib/module/RTCErrorEvent.js +22 -0
  75. package/lib/module/RTCErrorEvent.js.map +1 -0
  76. package/lib/module/RTCPeerConnection.js +373 -102
  77. package/lib/module/RTCPeerConnection.js.map +1 -1
  78. package/lib/module/RTCRtcpParameters.js +15 -0
  79. package/lib/module/RTCRtcpParameters.js.map +1 -0
  80. package/lib/module/RTCRtpCapabilities.js +63 -0
  81. package/lib/module/RTCRtpCapabilities.js.map +1 -0
  82. package/lib/module/RTCRtpCodecCapability.js +16 -0
  83. package/lib/module/RTCRtpCodecCapability.js.map +1 -0
  84. package/lib/module/RTCRtpCodecParameters.js +24 -0
  85. package/lib/module/RTCRtpCodecParameters.js.map +1 -0
  86. package/lib/module/RTCRtpEncodingParameters.js +72 -0
  87. package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
  88. package/lib/module/RTCRtpHeaderExtension.js +18 -0
  89. package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
  90. package/lib/module/RTCRtpParameters.js +17 -0
  91. package/lib/module/RTCRtpParameters.js.map +1 -0
  92. package/lib/module/RTCRtpReceiveParameters.js +8 -0
  93. package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
  94. package/lib/module/RTCRtpReceiver.js +39 -0
  95. package/lib/module/RTCRtpReceiver.js.map +1 -0
  96. package/lib/module/RTCRtpSendParameters.js +49 -0
  97. package/lib/module/RTCRtpSendParameters.js.map +1 -0
  98. package/lib/module/RTCRtpSender.js +70 -0
  99. package/lib/module/RTCRtpSender.js.map +1 -0
  100. package/lib/module/RTCRtpTransceiver.js +125 -0
  101. package/lib/module/RTCRtpTransceiver.js.map +1 -0
  102. package/lib/module/RTCSessionDescription.js.map +1 -1
  103. package/lib/module/RTCTrackEvent.js +23 -0
  104. package/lib/module/RTCTrackEvent.js.map +1 -0
  105. package/lib/module/RTCUtil.js +18 -36
  106. package/lib/module/RTCUtil.js.map +1 -1
  107. package/lib/module/getDisplayMedia.js.map +1 -1
  108. package/lib/module/getUserMedia.js.map +1 -1
  109. package/lib/module/index.js +35 -4
  110. package/lib/module/index.js.map +1 -1
  111. package/lib/typescript/EventEmitter.d.ts +3 -0
  112. package/lib/typescript/Logger.d.ts +13 -0
  113. package/lib/typescript/MediaDevices.d.ts +2 -2
  114. package/lib/typescript/MediaStream.d.ts +6 -6
  115. package/lib/typescript/MediaStreamTrack.d.ts +10 -9
  116. package/lib/typescript/RTCDataChannel.d.ts +4 -2
  117. package/lib/typescript/RTCErrorEvent.d.ts +12 -0
  118. package/lib/typescript/RTCPeerConnection.d.ts +42 -11
  119. package/lib/typescript/RTCRtcpParameters.d.ts +8 -0
  120. package/lib/typescript/RTCRtpCapabilities.d.ts +19 -0
  121. package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
  122. package/lib/typescript/RTCRtpCodecParameters.d.ts +14 -0
  123. package/lib/typescript/RTCRtpEncodingParameters.d.ts +21 -0
  124. package/lib/typescript/RTCRtpHeaderExtension.d.ts +10 -0
  125. package/lib/typescript/RTCRtpParameters.d.ts +14 -0
  126. package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
  127. package/lib/typescript/RTCRtpReceiver.d.ts +15 -0
  128. package/lib/typescript/RTCRtpSendParameters.d.ts +17 -0
  129. package/lib/typescript/RTCRtpSender.d.ts +21 -0
  130. package/lib/typescript/RTCRtpTransceiver.d.ts +35 -0
  131. package/lib/typescript/RTCTrackEvent.d.ts +15 -0
  132. package/lib/typescript/RTCUtil.d.ts +5 -9
  133. package/lib/typescript/getDisplayMedia.d.ts +2 -1
  134. package/lib/typescript/getUserMedia.d.ts +2 -1
  135. package/lib/typescript/index.d.ts +16 -3
  136. package/package.json +6 -4
  137. package/react-native-webrtc.podspec +1 -1
  138. package/src/EventEmitter.ts +21 -1
  139. package/src/Logger.ts +49 -0
  140. package/src/MediaStream.ts +11 -11
  141. package/src/MediaStreamTrack.ts +14 -13
  142. package/src/Permissions.ts +1 -1
  143. package/src/RTCDataChannel.ts +11 -8
  144. package/src/RTCErrorEvent.ts +21 -0
  145. package/src/RTCPeerConnection.ts +423 -156
  146. package/src/RTCRtcpParameters.ts +14 -0
  147. package/src/RTCRtpCapabilities.ts +54 -0
  148. package/src/RTCRtpCodecCapability.ts +13 -0
  149. package/src/RTCRtpCodecParameters.ts +23 -0
  150. package/src/RTCRtpEncodingParameters.ts +67 -0
  151. package/src/RTCRtpHeaderExtension.ts +18 -0
  152. package/src/RTCRtpParameters.ts +21 -0
  153. package/src/RTCRtpReceiveParameters.ts +7 -0
  154. package/src/RTCRtpReceiver.ts +35 -0
  155. package/src/RTCRtpSendParameters.ts +51 -0
  156. package/src/RTCRtpSender.ts +72 -0
  157. package/src/RTCRtpTransceiver.ts +125 -0
  158. package/src/RTCSessionDescription.ts +3 -3
  159. package/src/RTCTrackEvent.ts +21 -0
  160. package/src/RTCUtil.ts +20 -40
  161. package/src/getDisplayMedia.ts +1 -1
  162. package/src/getUserMedia.ts +2 -2
  163. package/src/index.ts +51 -6
  164. package/tools/build-webrtc.py +32 -33
  165. package/tools/downloadBitcode.sh +2 -12
  166. package/tools/downloadWebRTC.js +21 -12
@@ -0,0 +1,279 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+
4
+ import java.util.ArrayList;
5
+ import java.util.HashMap;
6
+ import java.util.List;
7
+ import java.util.Map;
8
+
9
+ import org.webrtc.*;
10
+
11
+ import com.facebook.react.bridge.Arguments;
12
+ import com.facebook.react.bridge.ReadableArray;
13
+ import com.facebook.react.bridge.ReadableMap;
14
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
15
+ import com.facebook.react.bridge.ReadableType;
16
+ import com.facebook.react.bridge.WritableMap;
17
+ import com.facebook.react.bridge.WritableArray;
18
+
19
+ public class SerializeUtils {
20
+
21
+ /**
22
+ * Serialization APIs
23
+ */
24
+
25
+ public static ReadableMap serializeVideoCodecInfo(VideoCodecInfo info) {
26
+ WritableMap params = Arguments.createMap();
27
+ params.putString("mimeType", "video/" + info.name);
28
+ return params;
29
+ }
30
+
31
+ public static ReadableMap serializeStream(int pcId, String streamReactTag, MediaStream stream) {
32
+
33
+ WritableMap params = Arguments.createMap();
34
+ params.putString("streamId", stream.getId());
35
+ params.putString("streamReactTag", streamReactTag);
36
+
37
+ WritableArray tracks = Arguments.createArray();
38
+
39
+ for (VideoTrack track: stream.videoTracks) {
40
+ tracks.pushMap(SerializeUtils.serializeTrack(pcId, track));
41
+ }
42
+ for (AudioTrack track: stream.audioTracks) {
43
+ tracks.pushMap(SerializeUtils.serializeTrack(pcId, track));
44
+ }
45
+
46
+ params.putArray("tracks", tracks);
47
+
48
+ return params;
49
+ }
50
+
51
+ public static String serializeDirection(RtpTransceiver.RtpTransceiverDirection src) {
52
+ switch(src) {
53
+ case INACTIVE:
54
+ return "inactive";
55
+ case RECV_ONLY:
56
+ return "recvonly";
57
+ case SEND_ONLY:
58
+ return "sendonly";
59
+ case SEND_RECV:
60
+ return "sendrecv";
61
+ case STOPPED:
62
+ return "stopped";
63
+ default:
64
+ throw new Error("Invalid direction");
65
+ }
66
+ }
67
+
68
+ public static ReadableMap serializeTrack(int pcId, MediaStreamTrack track) {
69
+ WritableMap trackInfo = Arguments.createMap();
70
+ trackInfo.putString("id", track.id());
71
+ trackInfo.putInt("peerConnectionId", pcId);
72
+ trackInfo.putString("kind", track.kind());
73
+ trackInfo.putBoolean("enabled", track.enabled());
74
+ trackInfo.putString("readyState", track.state().toString().toLowerCase());
75
+ trackInfo.putBoolean("remote", true);
76
+ return trackInfo;
77
+ }
78
+
79
+ /**
80
+ * This method is currently missing serializing DtmfSender
81
+ * and transport.
82
+ * TODO: Add transport and dtmf fields to the serialized sender to match the web APIs.
83
+ */
84
+ public static ReadableMap serializeSender(int id, RtpSender sender) {
85
+ WritableMap res = Arguments.createMap();
86
+ res.putString("id", sender.id());
87
+ res.putInt("peerConnectionId", id);
88
+ if (sender.track() != null) {
89
+ res.putMap("track", SerializeUtils.serializeTrack(id, sender.track()));
90
+ }
91
+ res.putMap("rtpParameters", SerializeUtils.serializeRtpParameters(sender.getParameters()));
92
+ return res;
93
+ }
94
+
95
+ public static ReadableMap serializeReceiver(int id, RtpReceiver receiver) {
96
+ WritableMap res = Arguments.createMap();
97
+ res.putString("id", receiver.id());
98
+ res.putInt("peerConnectionId", id);
99
+ res.putMap("track", SerializeUtils.serializeTrack(id, receiver.track()));
100
+ return res;
101
+ }
102
+
103
+ public static ReadableMap serializeTransceiver(int id, RtpTransceiver transceiver) {
104
+ WritableMap res = Arguments.createMap();
105
+ res.putString("id", transceiver.getSender().id());
106
+ res.putInt("peerConnectionId", id);
107
+ String mid = transceiver.getMid();
108
+ res.putString("mid", mid);
109
+ res.putString("direction", serializeDirection(transceiver.getDirection()));
110
+ RtpTransceiver.RtpTransceiverDirection currentDirection = transceiver.getCurrentDirection();
111
+ if (currentDirection != null) {
112
+ res.putString("currentDirection", SerializeUtils.serializeDirection(transceiver.getCurrentDirection()));
113
+ }
114
+ res.putBoolean("isStopped", transceiver.isStopped());
115
+ res.putMap("receiver", SerializeUtils.serializeReceiver(id, transceiver.getReceiver()));
116
+ res.putMap("sender", SerializeUtils.serializeSender(id, transceiver.getSender()));
117
+ return res;
118
+ }
119
+
120
+ public static ReadableMap serializeRtpParameters(RtpParameters params) {
121
+ if (params == null) return null;
122
+
123
+ WritableMap result = Arguments.createMap();
124
+ WritableArray encodings = Arguments.createArray();
125
+ WritableArray codecs = Arguments.createArray();
126
+ WritableArray headerExtensions = Arguments.createArray();
127
+ WritableMap rtcp = Arguments.createMap();
128
+
129
+
130
+ // Preparing RTCP
131
+ rtcp.putString("cname", params.getRtcp().getCname());
132
+ rtcp.putBoolean("reducedSize", params.getRtcp().getReducedSize());
133
+
134
+
135
+ // Preparing header extensions
136
+ params.getHeaderExtensions().forEach(extension -> {
137
+ WritableMap extensionMap = Arguments.createMap();
138
+ extensionMap.putInt("id", extension.getId());
139
+ extensionMap.putString("uri", extension.getUri());
140
+ extensionMap.putBoolean("encrypted", extension.getEncrypted());
141
+ headerExtensions.pushMap(extensionMap);
142
+ });
143
+
144
+ // Preparing encodings
145
+ params.encodings.forEach(encoding -> {
146
+ WritableMap encodingMap = Arguments.createMap();
147
+ encodingMap.putBoolean("active", encoding.active);
148
+ // Since they return integer objects that are nullable,
149
+ // while the map does not accept nullable integer values.
150
+ if (encoding.maxBitrateBps != null) {
151
+ encodingMap.putInt("maxBitrate", encoding.maxBitrateBps);
152
+ }
153
+ if (encoding.maxFramerate != null) {
154
+ encodingMap.putInt("maxFramerate", encoding.maxFramerate);
155
+ }
156
+ if (encoding.scaleResolutionDownBy != null) {
157
+ encodingMap.putDouble("scaleResolutionDownBy", encoding.scaleResolutionDownBy);
158
+ }
159
+ encodings.pushMap(encodingMap);
160
+ });
161
+
162
+ // Preparing codecs
163
+ params.codecs.forEach(codec -> {
164
+ WritableMap codecMap = Arguments.createMap();
165
+ WritableMap sdpFmptLineParams = Arguments.createMap();
166
+ codecMap.putInt("payloadType", codec.payloadType);
167
+ codecMap.putString("mimeType", codec.name);
168
+ codecMap.putInt("clockRate", codec.clockRate);
169
+ if (codec.numChannels != null) {
170
+ codecMap.putInt("channels", codec.numChannels);
171
+ }
172
+ // Serializing sdpFmptLine.
173
+ codec.parameters.forEach((k, v) -> {
174
+ sdpFmptLineParams.putString((String) k, (String) v);
175
+ });
176
+ codecMap.putMap("sdpFmtpLine", sdpFmptLineParams);
177
+ codecs.pushMap(codecMap);
178
+ });
179
+
180
+ result.putString("transactionId", params.transactionId);
181
+ result.putMap("rtcp", rtcp);
182
+ result.putArray("encodings", encodings);
183
+ result.putArray("codecs", codecs);
184
+ result.putArray("headerExtensions", headerExtensions);
185
+ if (params.degradationPreference != null) {
186
+ result.putString("degradationPreference", params.degradationPreference
187
+ .toString());
188
+ }
189
+
190
+ return result;
191
+ }
192
+
193
+ /**
194
+ * Parsing APIs
195
+ */
196
+
197
+ public static RtpParameters updateRtpParameters(ReadableMap updateParams, RtpParameters rtpParams) {
198
+
199
+ // Preparing encodings
200
+ ReadableArray encodingsArray = updateParams.getArray("encodings");
201
+ List<RtpParameters.Encoding> encodings = rtpParams.encodings;
202
+ if (encodingsArray.size() != encodings.size()) {
203
+ return null;
204
+ }
205
+
206
+ for (int i = 0; i < encodingsArray.size(); i++) {
207
+ ReadableMap encodingUpdate = encodingsArray.getMap(i);
208
+ RtpParameters.Encoding encoding = encodings.get(i);
209
+ // Dealing with nullable Integers
210
+ Integer maxBitrate = encodingUpdate.hasKey("maxBitrate")? encodingUpdate.getInt("maxBitrate") : null;
211
+ Integer maxFramerate = encodingUpdate.hasKey("maxFramerate")? encodingUpdate.getInt("maxFramerate") : null;
212
+ Double scaleResolutionDownBy = encodingUpdate.hasKey("scaleResolutionDownBy")?
213
+ encodingUpdate.getDouble("scaleResolutionDownBy") : null;
214
+
215
+ encoding.active = encodingUpdate.getBoolean("active");
216
+ encoding.maxBitrateBps = maxBitrate;
217
+ encoding.maxFramerate = maxFramerate;
218
+ encoding.scaleResolutionDownBy = scaleResolutionDownBy;
219
+ }
220
+
221
+ if (updateParams.hasKey("degradationPreference")) {
222
+ rtpParams.degradationPreference =
223
+ RtpParameters.DegradationPreference.valueOf(updateParams.getString("degradationPreference"));
224
+ }
225
+
226
+ return rtpParams;
227
+ }
228
+
229
+ public static MediaStreamTrack.MediaType parseMediaType(String type) {
230
+ switch(type) {
231
+ case "audio":
232
+ return MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO;
233
+ case "video":
234
+ return MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO;
235
+ default:
236
+ throw new Error("Unknown media type");
237
+ }
238
+ }
239
+
240
+ public static RtpTransceiver.RtpTransceiverDirection parseDirection(String src) {
241
+ switch (src) {
242
+ case "sendrecv":
243
+ return RtpTransceiver.RtpTransceiverDirection.SEND_RECV;
244
+ case "sendonly":
245
+ return RtpTransceiver.RtpTransceiverDirection.SEND_ONLY;
246
+ case "recvonly":
247
+ return RtpTransceiver.RtpTransceiverDirection.RECV_ONLY;
248
+ case "inactive":
249
+ return RtpTransceiver.RtpTransceiverDirection.INACTIVE;
250
+ // Here we ignore the "stopped" direction because user code should
251
+ // never set it.
252
+ }
253
+ throw new Error("Invalid direction");
254
+ }
255
+
256
+ public static RtpTransceiver.RtpTransceiverInit parseTransceiverOptions(ReadableMap map) {
257
+ RtpTransceiver.RtpTransceiverDirection direction = RtpTransceiver.RtpTransceiverDirection.INACTIVE;
258
+ ArrayList<String> streamIds = new ArrayList<>();
259
+ if (map != null) {
260
+ if (map.hasKey("direction")) {
261
+ String directionRaw = map.getString("direction");
262
+ if (directionRaw != null) {
263
+ direction = SerializeUtils.parseDirection(directionRaw);
264
+ }
265
+ }
266
+ if (map.hasKey("streamIds")) {
267
+ ReadableArray rawStreamIds = map.getArray("streamIds");
268
+ if (rawStreamIds != null) {
269
+ for (int i = 0; i < rawStreamIds.size(); i++) {
270
+ streamIds.add(rawStreamIds.getString(i));
271
+ }
272
+ }
273
+ }
274
+ }
275
+
276
+ return new RtpTransceiver.RtpTransceiverInit(direction, streamIds);
277
+ }
278
+
279
+ }