@sbhjt-gr/react-native-webrtc 137.0.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 (377) hide show
  1. package/.clang-format +11 -0
  2. package/.eslintignore +6 -0
  3. package/.nvmrc +1 -0
  4. package/ISSUE_TEMPLATE.md +40 -0
  5. package/LICENSE +22 -0
  6. package/README.md +82 -0
  7. package/android/build.gradle +36 -0
  8. package/android/consumer-rules.pro +3 -0
  9. package/android/src/main/AndroidManifest.xml +11 -0
  10. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +113 -0
  11. package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +338 -0
  12. package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +49 -0
  13. package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +99 -0
  14. package/android/src/main/java/com/oney/WebRTCModule/DataPacketCryptorManager.java +63 -0
  15. package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +16 -0
  16. package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +66 -0
  17. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +539 -0
  18. package/android/src/main/java/com/oney/WebRTCModule/LibraryLoader.java +21 -0
  19. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +70 -0
  20. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +82 -0
  21. package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +588 -0
  22. package/android/src/main/java/com/oney/WebRTCModule/RTCCryptoManager.java +493 -0
  23. package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +98 -0
  24. package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +36 -0
  25. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +94 -0
  26. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +342 -0
  27. package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +101 -0
  28. package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +41 -0
  29. package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -0
  30. package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +137 -0
  31. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +1593 -0
  32. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java +33 -0
  33. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +21 -0
  34. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +583 -0
  35. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +38 -0
  36. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +59 -0
  37. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -0
  38. package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +12 -0
  39. package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoDecoderFactory.java +73 -0
  40. package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoEncoderFactory.java +73 -0
  41. package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoDecoderFactoryProxy.java +36 -0
  42. package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoEncoderFactoryProxy.java +36 -0
  43. package/android/src/main/java/org/webrtc/Camera1Helper.java +54 -0
  44. package/android/src/main/java/org/webrtc/Camera2Helper.java +52 -0
  45. package/android/src/main/res/values/strings.xml +5 -0
  46. package/android/src/main/res/values/styles.xml +8 -0
  47. package/apple/.placeholder +0 -0
  48. package/ios/RCTWebRTC/CaptureController.h +18 -0
  49. package/ios/RCTWebRTC/CaptureController.m +29 -0
  50. package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
  51. package/ios/RCTWebRTC/DataChannelWrapper.h +27 -0
  52. package/ios/RCTWebRTC/DataChannelWrapper.m +42 -0
  53. package/ios/RCTWebRTC/I420Converter.h +22 -0
  54. package/ios/RCTWebRTC/I420Converter.m +164 -0
  55. package/ios/RCTWebRTC/PIPController.h +24 -0
  56. package/ios/RCTWebRTC/PIPController.m +234 -0
  57. package/ios/RCTWebRTC/RCTConvert+WebRTC.h +16 -0
  58. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +206 -0
  59. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +10 -0
  60. package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +16 -0
  61. package/ios/RCTWebRTC/RTCVideoViewManager.h +29 -0
  62. package/ios/RCTWebRTC/RTCVideoViewManager.m +411 -0
  63. package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
  64. package/ios/RCTWebRTC/SampleBufferVideoCallView.m +178 -0
  65. package/ios/RCTWebRTC/ScreenCaptureController.h +20 -0
  66. package/ios/RCTWebRTC/ScreenCaptureController.m +83 -0
  67. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +7 -0
  68. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +60 -0
  69. package/ios/RCTWebRTC/ScreenCapturer.h +19 -0
  70. package/ios/RCTWebRTC/ScreenCapturer.m +264 -0
  71. package/ios/RCTWebRTC/SerializeUtils.h +28 -0
  72. package/ios/RCTWebRTC/SerializeUtils.m +314 -0
  73. package/ios/RCTWebRTC/SocketConnection.h +13 -0
  74. package/ios/RCTWebRTC/SocketConnection.m +137 -0
  75. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
  76. package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
  77. package/ios/RCTWebRTC/VideoCaptureController.h +21 -0
  78. package/ios/RCTWebRTC/VideoCaptureController.m +328 -0
  79. package/ios/RCTWebRTC/WebRTCModule+Permissions.m +75 -0
  80. package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
  81. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +14 -0
  82. package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +165 -0
  83. package/ios/RCTWebRTC/WebRTCModule+RTCFrameCryptor.m +611 -0
  84. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +14 -0
  85. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +545 -0
  86. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +24 -0
  87. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +1004 -0
  88. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +267 -0
  89. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +12 -0
  90. package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +166 -0
  91. package/ios/RCTWebRTC/WebRTCModule.h +45 -0
  92. package/ios/RCTWebRTC/WebRTCModule.m +149 -0
  93. package/ios/RCTWebRTC/WebRTCModuleOptions.h +24 -0
  94. package/ios/RCTWebRTC/WebRTCModuleOptions.m +31 -0
  95. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -0
  96. package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -0
  97. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -0
  98. package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -0
  99. package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -0
  100. package/ios/RCTWebRTC.xcodeproj/project.pbxproj +404 -0
  101. package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -0
  102. package/lib/commonjs/Constraints.js +2 -0
  103. package/lib/commonjs/Constraints.js.map +1 -0
  104. package/lib/commonjs/EventEmitter.js +69 -0
  105. package/lib/commonjs/EventEmitter.js.map +1 -0
  106. package/lib/commonjs/Logger.js +47 -0
  107. package/lib/commonjs/Logger.js.map +1 -0
  108. package/lib/commonjs/MediaDevices.js +54 -0
  109. package/lib/commonjs/MediaDevices.js.map +1 -0
  110. package/lib/commonjs/MediaStream.js +137 -0
  111. package/lib/commonjs/MediaStream.js.map +1 -0
  112. package/lib/commonjs/MediaStreamError.js +19 -0
  113. package/lib/commonjs/MediaStreamError.js.map +1 -0
  114. package/lib/commonjs/MediaStreamErrorEvent.js +17 -0
  115. package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -0
  116. package/lib/commonjs/MediaStreamTrack.js +239 -0
  117. package/lib/commonjs/MediaStreamTrack.js.map +1 -0
  118. package/lib/commonjs/MediaStreamTrackEvent.js +26 -0
  119. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -0
  120. package/lib/commonjs/MessageEvent.js +27 -0
  121. package/lib/commonjs/MessageEvent.js.map +1 -0
  122. package/lib/commonjs/Permissions.js +116 -0
  123. package/lib/commonjs/Permissions.js.map +1 -0
  124. package/lib/commonjs/RTCAudioSession.js +33 -0
  125. package/lib/commonjs/RTCAudioSession.js.map +1 -0
  126. package/lib/commonjs/RTCDataChannel.js +165 -0
  127. package/lib/commonjs/RTCDataChannel.js.map +1 -0
  128. package/lib/commonjs/RTCDataChannelEvent.js +26 -0
  129. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -0
  130. package/lib/commonjs/RTCDataPacketCryptor.js +76 -0
  131. package/lib/commonjs/RTCDataPacketCryptor.js.map +1 -0
  132. package/lib/commonjs/RTCDataPacketCryptorFactory.js +27 -0
  133. package/lib/commonjs/RTCDataPacketCryptorFactory.js.map +1 -0
  134. package/lib/commonjs/RTCErrorEvent.js +23 -0
  135. package/lib/commonjs/RTCErrorEvent.js.map +1 -0
  136. package/lib/commonjs/RTCFrameCryptor.js +138 -0
  137. package/lib/commonjs/RTCFrameCryptor.js.map +1 -0
  138. package/lib/commonjs/RTCFrameCryptorFactory.js +81 -0
  139. package/lib/commonjs/RTCFrameCryptorFactory.js.map +1 -0
  140. package/lib/commonjs/RTCIceCandidate.js +34 -0
  141. package/lib/commonjs/RTCIceCandidate.js.map +1 -0
  142. package/lib/commonjs/RTCIceCandidateEvent.js +28 -0
  143. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -0
  144. package/lib/commonjs/RTCKeyProvider.js +111 -0
  145. package/lib/commonjs/RTCKeyProvider.js.map +1 -0
  146. package/lib/commonjs/RTCPIPView.js +38 -0
  147. package/lib/commonjs/RTCPIPView.js.map +1 -0
  148. package/lib/commonjs/RTCPeerConnection.js +694 -0
  149. package/lib/commonjs/RTCPeerConnection.js.map +1 -0
  150. package/lib/commonjs/RTCRtcpParameters.js +24 -0
  151. package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
  152. package/lib/commonjs/RTCRtpCapabilities.js +22 -0
  153. package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
  154. package/lib/commonjs/RTCRtpCodecCapability.js +19 -0
  155. package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
  156. package/lib/commonjs/RTCRtpCodecParameters.js +38 -0
  157. package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
  158. package/lib/commonjs/RTCRtpEncodingParameters.js +78 -0
  159. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
  160. package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
  161. package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
  162. package/lib/commonjs/RTCRtpParameters.js +35 -0
  163. package/lib/commonjs/RTCRtpParameters.js.map +1 -0
  164. package/lib/commonjs/RTCRtpReceiveParameters.js +15 -0
  165. package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
  166. package/lib/commonjs/RTCRtpReceiver.js +53 -0
  167. package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
  168. package/lib/commonjs/RTCRtpSendParameters.js +49 -0
  169. package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
  170. package/lib/commonjs/RTCRtpSender.js +67 -0
  171. package/lib/commonjs/RTCRtpSender.js.map +1 -0
  172. package/lib/commonjs/RTCRtpTransceiver.js +81 -0
  173. package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
  174. package/lib/commonjs/RTCSessionDescription.js +33 -0
  175. package/lib/commonjs/RTCSessionDescription.js.map +1 -0
  176. package/lib/commonjs/RTCTrackEvent.js +38 -0
  177. package/lib/commonjs/RTCTrackEvent.js.map +1 -0
  178. package/lib/commonjs/RTCUtil.js +186 -0
  179. package/lib/commonjs/RTCUtil.js.map +1 -0
  180. package/lib/commonjs/RTCView.js +16 -0
  181. package/lib/commonjs/RTCView.js.map +1 -0
  182. package/lib/commonjs/ScreenCapturePickerView.js +10 -0
  183. package/lib/commonjs/ScreenCapturePickerView.js.map +1 -0
  184. package/lib/commonjs/getDisplayMedia.js +33 -0
  185. package/lib/commonjs/getDisplayMedia.js.map +1 -0
  186. package/lib/commonjs/getUserMedia.js +101 -0
  187. package/lib/commonjs/getUserMedia.js.map +1 -0
  188. package/lib/commonjs/index.js +224 -0
  189. package/lib/commonjs/index.js.map +1 -0
  190. package/lib/module/Constraints.js +2 -0
  191. package/lib/module/Constraints.js.map +1 -0
  192. package/lib/module/EventEmitter.js +58 -0
  193. package/lib/module/EventEmitter.js.map +1 -0
  194. package/lib/module/Logger.js +39 -0
  195. package/lib/module/Logger.js.map +1 -0
  196. package/lib/module/MediaDevices.js +46 -0
  197. package/lib/module/MediaDevices.js.map +1 -0
  198. package/lib/module/MediaStream.js +129 -0
  199. package/lib/module/MediaStream.js.map +1 -0
  200. package/lib/module/MediaStreamError.js +12 -0
  201. package/lib/module/MediaStreamError.js.map +1 -0
  202. package/lib/module/MediaStreamErrorEvent.js +10 -0
  203. package/lib/module/MediaStreamErrorEvent.js.map +1 -0
  204. package/lib/module/MediaStreamTrack.js +231 -0
  205. package/lib/module/MediaStreamTrack.js.map +1 -0
  206. package/lib/module/MediaStreamTrackEvent.js +19 -0
  207. package/lib/module/MediaStreamTrackEvent.js.map +1 -0
  208. package/lib/module/MessageEvent.js +20 -0
  209. package/lib/module/MessageEvent.js.map +1 -0
  210. package/lib/module/Permissions.js +109 -0
  211. package/lib/module/Permissions.js.map +1 -0
  212. package/lib/module/RTCAudioSession.js +26 -0
  213. package/lib/module/RTCAudioSession.js.map +1 -0
  214. package/lib/module/RTCDataChannel.js +155 -0
  215. package/lib/module/RTCDataChannel.js.map +1 -0
  216. package/lib/module/RTCDataChannelEvent.js +19 -0
  217. package/lib/module/RTCDataChannelEvent.js.map +1 -0
  218. package/lib/module/RTCDataPacketCryptor.js +66 -0
  219. package/lib/module/RTCDataPacketCryptor.js.map +1 -0
  220. package/lib/module/RTCDataPacketCryptorFactory.js +19 -0
  221. package/lib/module/RTCDataPacketCryptorFactory.js.map +1 -0
  222. package/lib/module/RTCErrorEvent.js +16 -0
  223. package/lib/module/RTCErrorEvent.js.map +1 -0
  224. package/lib/module/RTCFrameCryptor.js +128 -0
  225. package/lib/module/RTCFrameCryptor.js.map +1 -0
  226. package/lib/module/RTCFrameCryptorFactory.js +70 -0
  227. package/lib/module/RTCFrameCryptorFactory.js.map +1 -0
  228. package/lib/module/RTCIceCandidate.js +27 -0
  229. package/lib/module/RTCIceCandidate.js.map +1 -0
  230. package/lib/module/RTCIceCandidateEvent.js +21 -0
  231. package/lib/module/RTCIceCandidateEvent.js.map +1 -0
  232. package/lib/module/RTCKeyProvider.js +101 -0
  233. package/lib/module/RTCKeyProvider.js.map +1 -0
  234. package/lib/module/RTCPIPView.js +26 -0
  235. package/lib/module/RTCPIPView.js.map +1 -0
  236. package/lib/module/RTCPeerConnection.js +684 -0
  237. package/lib/module/RTCPeerConnection.js.map +1 -0
  238. package/lib/module/RTCRtcpParameters.js +17 -0
  239. package/lib/module/RTCRtcpParameters.js.map +1 -0
  240. package/lib/module/RTCRtpCapabilities.js +15 -0
  241. package/lib/module/RTCRtpCapabilities.js.map +1 -0
  242. package/lib/module/RTCRtpCodecCapability.js +12 -0
  243. package/lib/module/RTCRtpCodecCapability.js.map +1 -0
  244. package/lib/module/RTCRtpCodecParameters.js +31 -0
  245. package/lib/module/RTCRtpCodecParameters.js.map +1 -0
  246. package/lib/module/RTCRtpEncodingParameters.js +71 -0
  247. package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
  248. package/lib/module/RTCRtpHeaderExtension.js +20 -0
  249. package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
  250. package/lib/module/RTCRtpParameters.js +27 -0
  251. package/lib/module/RTCRtpParameters.js.map +1 -0
  252. package/lib/module/RTCRtpReceiveParameters.js +7 -0
  253. package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
  254. package/lib/module/RTCRtpReceiver.js +45 -0
  255. package/lib/module/RTCRtpReceiver.js.map +1 -0
  256. package/lib/module/RTCRtpSendParameters.js +41 -0
  257. package/lib/module/RTCRtpSendParameters.js.map +1 -0
  258. package/lib/module/RTCRtpSender.js +59 -0
  259. package/lib/module/RTCRtpSender.js.map +1 -0
  260. package/lib/module/RTCRtpTransceiver.js +74 -0
  261. package/lib/module/RTCRtpTransceiver.js.map +1 -0
  262. package/lib/module/RTCSessionDescription.js +26 -0
  263. package/lib/module/RTCSessionDescription.js.map +1 -0
  264. package/lib/module/RTCTrackEvent.js +31 -0
  265. package/lib/module/RTCTrackEvent.js.map +1 -0
  266. package/lib/module/RTCUtil.js +176 -0
  267. package/lib/module/RTCUtil.js.map +1 -0
  268. package/lib/module/RTCView.js +11 -0
  269. package/lib/module/RTCView.js.map +1 -0
  270. package/lib/module/ScreenCapturePickerView.js +3 -0
  271. package/lib/module/ScreenCapturePickerView.js.map +1 -0
  272. package/lib/module/getDisplayMedia.js +26 -0
  273. package/lib/module/getDisplayMedia.js.map +1 -0
  274. package/lib/module/getUserMedia.js +92 -0
  275. package/lib/module/getUserMedia.js.map +1 -0
  276. package/lib/module/index.js +60 -0
  277. package/lib/module/index.js.map +1 -0
  278. package/lib/typescript/Constraints.d.ts +19 -0
  279. package/lib/typescript/EventEmitter.d.ts +7 -0
  280. package/lib/typescript/Logger.d.ts +13 -0
  281. package/lib/typescript/MediaDevices.d.ts +30 -0
  282. package/lib/typescript/MediaStream.d.ts +48 -0
  283. package/lib/typescript/MediaStreamError.d.ts +6 -0
  284. package/lib/typescript/MediaStreamErrorEvent.d.ts +6 -0
  285. package/lib/typescript/MediaStreamTrack.d.ts +103 -0
  286. package/lib/typescript/MediaStreamTrackEvent.d.ts +19 -0
  287. package/lib/typescript/MessageEvent.d.ts +21 -0
  288. package/lib/typescript/Permissions.d.ts +55 -0
  289. package/lib/typescript/RTCAudioSession.d.ts +10 -0
  290. package/lib/typescript/RTCDataChannel.d.ts +43 -0
  291. package/lib/typescript/RTCDataChannelEvent.d.ts +19 -0
  292. package/lib/typescript/RTCDataPacketCryptor.d.ts +12 -0
  293. package/lib/typescript/RTCDataPacketCryptorFactory.d.ts +6 -0
  294. package/lib/typescript/RTCErrorEvent.d.ts +12 -0
  295. package/lib/typescript/RTCFrameCryptor.d.ts +47 -0
  296. package/lib/typescript/RTCFrameCryptorFactory.d.ts +21 -0
  297. package/lib/typescript/RTCIceCandidate.d.ts +17 -0
  298. package/lib/typescript/RTCIceCandidateEvent.d.ts +20 -0
  299. package/lib/typescript/RTCKeyProvider.d.ts +21 -0
  300. package/lib/typescript/RTCPIPView.d.ts +15 -0
  301. package/lib/typescript/RTCPeerConnection.d.ts +117 -0
  302. package/lib/typescript/RTCRtcpParameters.d.ts +10 -0
  303. package/lib/typescript/RTCRtpCapabilities.d.ts +9 -0
  304. package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
  305. package/lib/typescript/RTCRtpCodecParameters.d.ts +16 -0
  306. package/lib/typescript/RTCRtpEncodingParameters.d.ts +23 -0
  307. package/lib/typescript/RTCRtpHeaderExtension.d.ts +12 -0
  308. package/lib/typescript/RTCRtpParameters.d.ts +19 -0
  309. package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
  310. package/lib/typescript/RTCRtpReceiver.d.ts +21 -0
  311. package/lib/typescript/RTCRtpSendParameters.d.ts +20 -0
  312. package/lib/typescript/RTCRtpSender.d.ts +22 -0
  313. package/lib/typescript/RTCRtpTransceiver.d.ts +31 -0
  314. package/lib/typescript/RTCSessionDescription.d.ts +12 -0
  315. package/lib/typescript/RTCTrackEvent.d.ts +29 -0
  316. package/lib/typescript/RTCUtil.d.ts +37 -0
  317. package/lib/typescript/RTCView.d.ts +117 -0
  318. package/lib/typescript/ScreenCapturePickerView.d.ts +2 -0
  319. package/lib/typescript/getDisplayMedia.d.ts +2 -0
  320. package/lib/typescript/getUserMedia.d.ts +7 -0
  321. package/lib/typescript/index.d.ts +22 -0
  322. package/livekit-react-native-webrtc.podspec +29 -0
  323. package/macos/RCTWebRTC.xcodeproj/project.pbxproj +324 -0
  324. package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  325. package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  326. package/metro.config.js +7 -0
  327. package/metro.config.macos.js +14 -0
  328. package/package.json +65 -0
  329. package/react-native.config.js +11 -0
  330. package/src/.eslintrc.cjs +67 -0
  331. package/src/Constraints.ts +21 -0
  332. package/src/EventEmitter.ts +83 -0
  333. package/src/Logger.ts +49 -0
  334. package/src/MediaDevices.ts +53 -0
  335. package/src/MediaStream.ts +161 -0
  336. package/src/MediaStreamError.ts +12 -0
  337. package/src/MediaStreamErrorEvent.ts +11 -0
  338. package/src/MediaStreamTrack.ts +331 -0
  339. package/src/MediaStreamTrackEvent.ts +25 -0
  340. package/src/MessageEvent.ts +26 -0
  341. package/src/Permissions.ts +133 -0
  342. package/src/RTCAudioSession.ts +25 -0
  343. package/src/RTCDataChannel.ts +190 -0
  344. package/src/RTCDataChannelEvent.ts +28 -0
  345. package/src/RTCDataPacketCryptor.ts +90 -0
  346. package/src/RTCDataPacketCryptorFactory.ts +25 -0
  347. package/src/RTCErrorEvent.ts +21 -0
  348. package/src/RTCFrameCryptor.ts +163 -0
  349. package/src/RTCFrameCryptorFactory.ts +102 -0
  350. package/src/RTCIceCandidate.ts +29 -0
  351. package/src/RTCIceCandidateEvent.ts +26 -0
  352. package/src/RTCKeyProvider.ts +117 -0
  353. package/src/RTCPIPView.tsx +47 -0
  354. package/src/RTCPeerConnection.ts +832 -0
  355. package/src/RTCRtcpParameters.ts +23 -0
  356. package/src/RTCRtpCapabilities.ts +16 -0
  357. package/src/RTCRtpCodecCapability.ts +13 -0
  358. package/src/RTCRtpCodecParameters.ts +44 -0
  359. package/src/RTCRtpEncodingParameters.ts +90 -0
  360. package/src/RTCRtpHeaderExtension.ts +27 -0
  361. package/src/RTCRtpParameters.ts +37 -0
  362. package/src/RTCRtpReceiveParameters.ts +7 -0
  363. package/src/RTCRtpReceiver.ts +60 -0
  364. package/src/RTCRtpSendParameters.ts +63 -0
  365. package/src/RTCRtpSender.ts +78 -0
  366. package/src/RTCRtpTransceiver.ts +107 -0
  367. package/src/RTCSessionDescription.ts +30 -0
  368. package/src/RTCTrackEvent.ts +42 -0
  369. package/src/RTCUtil.ts +211 -0
  370. package/src/RTCView.ts +122 -0
  371. package/src/ScreenCapturePickerView.ts +4 -0
  372. package/src/getDisplayMedia.ts +30 -0
  373. package/src/getUserMedia.ts +111 -0
  374. package/src/index.ts +101 -0
  375. package/tools/format.sh +6 -0
  376. package/tools/release.sh +45 -0
  377. package/tsconfig.json +16 -0
@@ -0,0 +1,1593 @@
1
+ package com.oney.WebRTCModule;
2
+
3
+ import android.util.Log;
4
+ import android.util.Pair;
5
+ import android.util.SparseArray;
6
+
7
+ import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
9
+
10
+ import com.facebook.react.bridge.Arguments;
11
+ import com.facebook.react.bridge.Callback;
12
+ import com.facebook.react.bridge.Promise;
13
+ import com.facebook.react.bridge.ReactApplicationContext;
14
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
15
+ import com.facebook.react.bridge.ReactMethod;
16
+ import com.facebook.react.bridge.ReadableArray;
17
+ import com.facebook.react.bridge.ReadableMap;
18
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
19
+ import com.facebook.react.bridge.ReadableType;
20
+ import com.facebook.react.bridge.WritableArray;
21
+ import com.facebook.react.bridge.WritableMap;
22
+ import com.facebook.react.module.annotations.ReactModule;
23
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
24
+ import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoDecoderFactory;
25
+ import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoEncoderFactory;
26
+
27
+ import org.webrtc.AddIceObserver;
28
+ import org.webrtc.AudioProcessingFactory;
29
+ import org.webrtc.AudioTrack;
30
+ import org.webrtc.CryptoOptions;
31
+ import org.webrtc.EglBase;
32
+ import org.webrtc.IceCandidate;
33
+ import org.webrtc.Loggable;
34
+ import org.webrtc.Logging;
35
+ import org.webrtc.MediaConstraints;
36
+ import org.webrtc.MediaStream;
37
+ import org.webrtc.MediaStreamTrack;
38
+ import org.webrtc.PeerConnection;
39
+ import org.webrtc.PeerConnectionFactory;
40
+ import org.webrtc.RTCStatsReport;
41
+ import org.webrtc.RtpCapabilities;
42
+ import org.webrtc.RtpParameters;
43
+ import org.webrtc.RtpSender;
44
+ import org.webrtc.RtpTransceiver;
45
+ import org.webrtc.SdpObserver;
46
+ import org.webrtc.SessionDescription;
47
+ import org.webrtc.SoftwareVideoDecoderFactory;
48
+ import org.webrtc.SoftwareVideoEncoderFactory;
49
+ import org.webrtc.VideoDecoderFactory;
50
+ import org.webrtc.VideoEncoderFactory;
51
+ import org.webrtc.VideoTrack;
52
+ import org.webrtc.audio.AudioDeviceModule;
53
+ import org.webrtc.audio.JavaAudioDeviceModule;
54
+
55
+ import java.util.ArrayList;
56
+ import java.util.HashMap;
57
+ import java.util.List;
58
+ import java.util.Map;
59
+ import java.util.Objects;
60
+ import java.util.concurrent.Callable;
61
+ import java.util.concurrent.ExecutionException;
62
+
63
+ @ReactModule(name = "WebRTCModule")
64
+ public class WebRTCModule extends ReactContextBaseJavaModule {
65
+ static final String TAG = WebRTCModule.class.getCanonicalName();
66
+
67
+ PeerConnectionFactory mFactory;
68
+ VideoEncoderFactory mVideoEncoderFactory;
69
+ VideoDecoderFactory mVideoDecoderFactory;
70
+ AudioDeviceModule mAudioDeviceModule;
71
+
72
+ // Need to expose the peer connection codec factories here to get capabilities
73
+ private final SparseArray<PeerConnectionObserver> mPeerConnectionObservers;
74
+ final Map<String, MediaStream> localStreams;
75
+
76
+ private final GetUserMediaImpl getUserMediaImpl;
77
+
78
+ public WebRTCModule(ReactApplicationContext reactContext) {
79
+ super(reactContext);
80
+
81
+ mPeerConnectionObservers = new SparseArray<>();
82
+ localStreams = new HashMap<>();
83
+
84
+ WebRTCModuleOptions options = WebRTCModuleOptions.getInstance();
85
+
86
+ AudioDeviceModule adm = options.audioDeviceModule;
87
+ VideoEncoderFactory encoderFactory = options.videoEncoderFactory;
88
+ VideoDecoderFactory decoderFactory = options.videoDecoderFactory;
89
+ Loggable injectableLogger = options.injectableLogger;
90
+ Logging.Severity loggingSeverity = options.loggingSeverity;
91
+ String fieldTrials = options.fieldTrials;
92
+
93
+ PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(reactContext)
94
+ .setFieldTrials(fieldTrials)
95
+ .setNativeLibraryLoader(new LibraryLoader())
96
+ .setInjectableLogger(injectableLogger, loggingSeverity)
97
+ .createInitializationOptions());
98
+
99
+ if (injectableLogger == null && loggingSeverity != null) {
100
+ Logging.enableLogToDebugOutput(loggingSeverity);
101
+ }
102
+
103
+ if (encoderFactory == null || decoderFactory == null) {
104
+ // Initialize EGL context required for HW acceleration.
105
+ EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
106
+
107
+ if (eglContext != null) {
108
+ encoderFactory = new H264AndSoftwareVideoEncoderFactory(eglContext);
109
+ decoderFactory = new H264AndSoftwareVideoDecoderFactory(eglContext);
110
+ } else {
111
+ encoderFactory = new SoftwareVideoEncoderFactory();
112
+ decoderFactory = new SoftwareVideoDecoderFactory();
113
+ }
114
+ }
115
+
116
+ if (adm == null) {
117
+ adm = JavaAudioDeviceModule.builder(reactContext).createAudioDeviceModule();
118
+ }
119
+
120
+ AudioProcessingFactory audioProcessingFactory = null;
121
+ try {
122
+ if (options.audioProcessingFactoryFactory != null) {
123
+ audioProcessingFactory = options.audioProcessingFactoryFactory.call();
124
+ }
125
+ } catch (Exception e) {
126
+ // do nothing.
127
+ }
128
+
129
+ Log.d(TAG, "Using video encoder factory: " + encoderFactory.getClass().getCanonicalName());
130
+ Log.d(TAG, "Using video decoder factory: " + decoderFactory.getClass().getCanonicalName());
131
+
132
+ PeerConnectionFactory.Builder pcFactoryBuilder = PeerConnectionFactory.builder()
133
+ .setAudioDeviceModule(adm)
134
+ .setVideoEncoderFactory(encoderFactory)
135
+ .setVideoDecoderFactory(decoderFactory);
136
+
137
+ if (audioProcessingFactory != null) {
138
+ pcFactoryBuilder.setAudioProcessingFactory(audioProcessingFactory);
139
+ }
140
+
141
+ mFactory = pcFactoryBuilder.createPeerConnectionFactory();
142
+
143
+ // PeerConnectionFactory now owns the adm native pointer, and we don't need it anymore.
144
+ adm.release();
145
+
146
+ // Saving the encoder and decoder factories to get codec info later when needed.
147
+ mVideoEncoderFactory = encoderFactory;
148
+ mVideoDecoderFactory = decoderFactory;
149
+ mAudioDeviceModule = adm;
150
+
151
+ getUserMediaImpl = new GetUserMediaImpl(this, reactContext);
152
+ }
153
+
154
+ @NonNull
155
+ @Override
156
+ public String getName() {
157
+ return "WebRTCModule";
158
+ }
159
+
160
+ public PeerConnectionObserver getPeerConnectionObserver(int id) {
161
+ return mPeerConnectionObservers.get(id);
162
+ }
163
+ private PeerConnection getPeerConnection(int id) {
164
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
165
+ return (pco == null) ? null : pco.getPeerConnection();
166
+ }
167
+
168
+ void sendEvent(String eventName, @Nullable ReadableMap params) {
169
+ getReactApplicationContext()
170
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
171
+ .emit(eventName, params);
172
+ }
173
+
174
+ private PeerConnection.IceServer createIceServer(String url) {
175
+ return PeerConnection.IceServer.builder(url).createIceServer();
176
+ }
177
+
178
+ private PeerConnection.IceServer createIceServer(String url, String username, String credential) {
179
+ return PeerConnection.IceServer.builder(url).setUsername(username).setPassword(credential).createIceServer();
180
+ }
181
+
182
+ private List<PeerConnection.IceServer> createIceServers(ReadableArray iceServersArray) {
183
+ final int size = (iceServersArray == null) ? 0 : iceServersArray.size();
184
+ List<PeerConnection.IceServer> iceServers = new ArrayList<>(size);
185
+ for (int i = 0; i < size; i++) {
186
+ ReadableMap iceServerMap = iceServersArray.getMap(i);
187
+ boolean hasUsernameAndCredential = iceServerMap.hasKey("username") && iceServerMap.hasKey("credential");
188
+ if (iceServerMap.hasKey("urls")) {
189
+ switch (iceServerMap.getType("urls")) {
190
+ case String:
191
+ if (hasUsernameAndCredential) {
192
+ iceServers.add(createIceServer(iceServerMap.getString("urls"),
193
+ iceServerMap.getString("username"),
194
+ iceServerMap.getString("credential")));
195
+ } else {
196
+ iceServers.add(createIceServer(iceServerMap.getString("urls")));
197
+ }
198
+ break;
199
+ case Array:
200
+ ReadableArray urls = iceServerMap.getArray("urls");
201
+ for (int j = 0; j < urls.size(); j++) {
202
+ String url = urls.getString(j);
203
+ if (hasUsernameAndCredential) {
204
+ iceServers.add(createIceServer(
205
+ url, iceServerMap.getString("username"), iceServerMap.getString("credential")));
206
+ } else {
207
+ iceServers.add(createIceServer(url));
208
+ }
209
+ }
210
+ break;
211
+ }
212
+ }
213
+ }
214
+ return iceServers;
215
+ }
216
+
217
+ private PeerConnection.RTCConfiguration parseRTCConfiguration(ReadableMap map) {
218
+ ReadableArray iceServersArray = null;
219
+ if (map != null && map.hasKey("iceServers")) {
220
+ iceServersArray = map.getArray("iceServers");
221
+ }
222
+ List<PeerConnection.IceServer> iceServers = createIceServers(iceServersArray);
223
+
224
+ PeerConnection.RTCConfiguration conf = new PeerConnection.RTCConfiguration(iceServers);
225
+ conf.sdpSemantics = PeerConnection.SdpSemantics.UNIFIED_PLAN;
226
+
227
+ // Required for perfect negotiation.
228
+ conf.enableImplicitRollback = true;
229
+
230
+ // Enable GCM ciphers.
231
+ CryptoOptions cryptoOptions = CryptoOptions.builder()
232
+ .setEnableGcmCryptoSuites(true)
233
+ .setEnableAes128Sha1_32CryptoCipher(false)
234
+ .setEnableEncryptedRtpHeaderExtensions(false)
235
+ .setRequireFrameEncryption(false)
236
+ .createCryptoOptions();
237
+ conf.cryptoOptions = cryptoOptions;
238
+
239
+ if (map == null) {
240
+ return conf;
241
+ }
242
+
243
+ // iceTransportPolicy (public api)
244
+ if (map.hasKey("iceTransportPolicy") && map.getType("iceTransportPolicy") == ReadableType.String) {
245
+ final String v = map.getString("iceTransportPolicy");
246
+ if (v != null) {
247
+ switch (v) {
248
+ case "all": // public
249
+ conf.iceTransportsType = PeerConnection.IceTransportsType.ALL;
250
+ break;
251
+ case "relay": // public
252
+ conf.iceTransportsType = PeerConnection.IceTransportsType.RELAY;
253
+ break;
254
+ case "nohost":
255
+ conf.iceTransportsType = PeerConnection.IceTransportsType.NOHOST;
256
+ break;
257
+ case "none":
258
+ conf.iceTransportsType = PeerConnection.IceTransportsType.NONE;
259
+ break;
260
+ }
261
+ }
262
+ }
263
+
264
+ // bundlePolicy (public api)
265
+ if (map.hasKey("bundlePolicy") && map.getType("bundlePolicy") == ReadableType.String) {
266
+ final String v = map.getString("bundlePolicy");
267
+ if (v != null) {
268
+ switch (v) {
269
+ case "balanced": // public
270
+ conf.bundlePolicy = PeerConnection.BundlePolicy.BALANCED;
271
+ break;
272
+ case "max-compat": // public
273
+ conf.bundlePolicy = PeerConnection.BundlePolicy.MAXCOMPAT;
274
+ break;
275
+ case "max-bundle": // public
276
+ conf.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
277
+ break;
278
+ }
279
+ }
280
+ }
281
+
282
+ // rtcpMuxPolicy (public api)
283
+ if (map.hasKey("rtcpMuxPolicy") && map.getType("rtcpMuxPolicy") == ReadableType.String) {
284
+ final String v = map.getString("rtcpMuxPolicy");
285
+ if (v != null) {
286
+ switch (v) {
287
+ case "negotiate": // public
288
+ conf.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.NEGOTIATE;
289
+ break;
290
+ case "require": // public
291
+ conf.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;
292
+ break;
293
+ }
294
+ }
295
+ }
296
+
297
+ // FIXME: peerIdentity of type DOMString (public api)
298
+ // FIXME: certificates of type sequence<RTCCertificate> (public api)
299
+
300
+ // iceCandidatePoolSize of type unsigned short, defaulting to 0
301
+ if (map.hasKey("iceCandidatePoolSize") && map.getType("iceCandidatePoolSize") == ReadableType.Number) {
302
+ final int v = map.getInt("iceCandidatePoolSize");
303
+ if (v > 0) {
304
+ conf.iceCandidatePoolSize = v;
305
+ }
306
+ }
307
+
308
+ // === below is private api in webrtc ===
309
+
310
+ // tcpCandidatePolicy (private api)
311
+ if (map.hasKey("tcpCandidatePolicy") && map.getType("tcpCandidatePolicy") == ReadableType.String) {
312
+ final String v = map.getString("tcpCandidatePolicy");
313
+ if (v != null) {
314
+ switch (v) {
315
+ case "enabled":
316
+ conf.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.ENABLED;
317
+ break;
318
+ case "disabled":
319
+ conf.tcpCandidatePolicy = PeerConnection.TcpCandidatePolicy.DISABLED;
320
+ break;
321
+ }
322
+ }
323
+ }
324
+
325
+ // candidateNetworkPolicy (private api)
326
+ if (map.hasKey("candidateNetworkPolicy") && map.getType("candidateNetworkPolicy") == ReadableType.String) {
327
+ final String v = map.getString("candidateNetworkPolicy");
328
+ if (v != null) {
329
+ switch (v) {
330
+ case "all":
331
+ conf.candidateNetworkPolicy = PeerConnection.CandidateNetworkPolicy.ALL;
332
+ break;
333
+ case "low_cost":
334
+ conf.candidateNetworkPolicy = PeerConnection.CandidateNetworkPolicy.LOW_COST;
335
+ break;
336
+ }
337
+ }
338
+ }
339
+
340
+ // KeyType (private api)
341
+ if (map.hasKey("keyType") && map.getType("keyType") == ReadableType.String) {
342
+ final String v = map.getString("keyType");
343
+ if (v != null) {
344
+ switch (v) {
345
+ case "RSA":
346
+ conf.keyType = PeerConnection.KeyType.RSA;
347
+ break;
348
+ case "ECDSA":
349
+ conf.keyType = PeerConnection.KeyType.ECDSA;
350
+ break;
351
+ }
352
+ }
353
+ }
354
+
355
+ // continualGatheringPolicy (private api)
356
+ if (map.hasKey("continualGatheringPolicy") && map.getType("continualGatheringPolicy") == ReadableType.String) {
357
+ final String v = map.getString("continualGatheringPolicy");
358
+ if (v != null) {
359
+ switch (v) {
360
+ case "gather_once":
361
+ conf.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_ONCE;
362
+ break;
363
+ case "gather_continually":
364
+ conf.continualGatheringPolicy = PeerConnection.ContinualGatheringPolicy.GATHER_CONTINUALLY;
365
+ break;
366
+ }
367
+ }
368
+ }
369
+
370
+ // audioJitterBufferMaxPackets (private api)
371
+ if (map.hasKey("audioJitterBufferMaxPackets")
372
+ && map.getType("audioJitterBufferMaxPackets") == ReadableType.Number) {
373
+ final int v = map.getInt("audioJitterBufferMaxPackets");
374
+ if (v > 0) {
375
+ conf.audioJitterBufferMaxPackets = v;
376
+ }
377
+ }
378
+
379
+ // iceConnectionReceivingTimeout (private api)
380
+ if (map.hasKey("iceConnectionReceivingTimeout")
381
+ && map.getType("iceConnectionReceivingTimeout") == ReadableType.Number) {
382
+ final int v = map.getInt("iceConnectionReceivingTimeout");
383
+ conf.iceConnectionReceivingTimeout = v;
384
+ }
385
+
386
+ // iceBackupCandidatePairPingInterval (private api)
387
+ if (map.hasKey("iceBackupCandidatePairPingInterval")
388
+ && map.getType("iceBackupCandidatePairPingInterval") == ReadableType.Number) {
389
+ final int v = map.getInt("iceBackupCandidatePairPingInterval");
390
+ conf.iceBackupCandidatePairPingInterval = v;
391
+ }
392
+
393
+ // audioJitterBufferFastAccelerate (private api)
394
+ if (map.hasKey("audioJitterBufferFastAccelerate")
395
+ && map.getType("audioJitterBufferFastAccelerate") == ReadableType.Boolean) {
396
+ final boolean v = map.getBoolean("audioJitterBufferFastAccelerate");
397
+ conf.audioJitterBufferFastAccelerate = v;
398
+ }
399
+
400
+ // pruneTurnPorts (private api)
401
+ if (map.hasKey("pruneTurnPorts") && map.getType("pruneTurnPorts") == ReadableType.Boolean) {
402
+ final boolean v = map.getBoolean("pruneTurnPorts");
403
+ conf.pruneTurnPorts = v;
404
+ }
405
+
406
+ // presumeWritableWhenFullyRelayed (private api)
407
+ if (map.hasKey("presumeWritableWhenFullyRelayed")
408
+ && map.getType("presumeWritableWhenFullyRelayed") == ReadableType.Boolean) {
409
+ final boolean v = map.getBoolean("presumeWritableWhenFullyRelayed");
410
+ conf.presumeWritableWhenFullyRelayed = v;
411
+ }
412
+
413
+ return conf;
414
+ }
415
+
416
+ @ReactMethod(isBlockingSynchronousMethod = true)
417
+ public boolean peerConnectionInit(ReadableMap configuration, int id) {
418
+ PeerConnection.RTCConfiguration rtcConfiguration = parseRTCConfiguration(configuration);
419
+
420
+ try {
421
+ return (boolean) ThreadUtils
422
+ .submitToExecutor(() -> {
423
+ PeerConnectionObserver observer = new PeerConnectionObserver(this, id);
424
+ PeerConnection peerConnection = mFactory.createPeerConnection(rtcConfiguration, observer);
425
+ if (peerConnection == null) {
426
+ return false;
427
+ }
428
+ observer.setPeerConnection(peerConnection);
429
+ mPeerConnectionObservers.put(id, observer);
430
+ return true;
431
+ })
432
+ .get();
433
+ } catch (ExecutionException | InterruptedException e) {
434
+ e.printStackTrace();
435
+ throw new RuntimeException(e);
436
+ }
437
+ }
438
+
439
+ MediaStream getStreamForReactTag(String streamReactTag) {
440
+ // This function _only_ gets called from WebRTCView, in the UI thread.
441
+ // Hence make sure we run this code in the executor or we run at the risk
442
+ // of being out of sync.
443
+ try {
444
+ return (MediaStream) ThreadUtils
445
+ .submitToExecutor((Callable<Object>) () -> {
446
+ MediaStream stream = localStreams.get(streamReactTag);
447
+
448
+ if (stream != null) {
449
+ return stream;
450
+ }
451
+
452
+ for (int i = 0, size = mPeerConnectionObservers.size(); i < size; i++) {
453
+ PeerConnectionObserver pco = mPeerConnectionObservers.valueAt(i);
454
+ stream = pco.remoteStreams.get(streamReactTag);
455
+ if (stream != null) {
456
+ return stream;
457
+ }
458
+ }
459
+
460
+ return null;
461
+ })
462
+ .get();
463
+ } catch (ExecutionException | InterruptedException e) {
464
+ return null;
465
+ }
466
+ }
467
+
468
+ public MediaStreamTrack getTrack(int pcId, String trackId) {
469
+ if (pcId == -1) {
470
+ return getLocalTrack(trackId);
471
+ }
472
+
473
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
474
+ if (pco == null) {
475
+ Log.d(TAG, "getTrack(): could not find PeerConnection");
476
+ return null;
477
+ }
478
+
479
+ return pco.remoteTracks.get(trackId);
480
+ }
481
+
482
+ MediaStreamTrack getLocalTrack(String trackId) {
483
+ return getUserMediaImpl.getTrack(trackId);
484
+ }
485
+
486
+ public VideoTrack createVideoTrack(AbstractVideoCaptureController videoCaptureController) {
487
+ return getUserMediaImpl.createVideoTrack(videoCaptureController);
488
+ }
489
+
490
+ public void createStream(
491
+ MediaStreamTrack[] tracks, GetUserMediaImpl.BiConsumer<String, ArrayList<WritableMap>> successCallback) {
492
+ getUserMediaImpl.createStream(tracks, successCallback);
493
+ }
494
+
495
+ /**
496
+ * Turns an "options" <tt>ReadableMap</tt> into a <tt>MediaConstraints</tt> object.
497
+ *
498
+ * @param options A <tt>ReadableMap</tt> which represents a JavaScript
499
+ * object specifying the options to be parsed into a
500
+ * <tt>MediaConstraints</tt> instance.
501
+ * @return A new <tt>MediaConstraints</tt> instance initialized with the
502
+ * mandatory keys and values specified by <tt>options</tt>.
503
+ */
504
+ MediaConstraints constraintsForOptions(ReadableMap options) {
505
+ MediaConstraints mediaConstraints = new MediaConstraints();
506
+ ReadableMapKeySetIterator keyIterator = options.keySetIterator();
507
+
508
+ while (keyIterator.hasNextKey()) {
509
+ String key = keyIterator.nextKey();
510
+ String value = ReactBridgeUtil.getMapStrValue(options, key);
511
+
512
+ mediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair(key, value));
513
+ }
514
+
515
+ return mediaConstraints;
516
+ }
517
+
518
+ @ReactMethod(isBlockingSynchronousMethod = true)
519
+ public WritableMap peerConnectionAddTransceiver(int id, ReadableMap options) {
520
+ try {
521
+ return (WritableMap) ThreadUtils
522
+ .submitToExecutor((Callable<Object>) () -> {
523
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
524
+ if (pco == null) {
525
+ Log.d(TAG, "peerConnectionAddTransceiver() peerConnection is null");
526
+ return null;
527
+ }
528
+
529
+ RtpTransceiver transceiver = null;
530
+ if (options.hasKey("type")) {
531
+ String kind = options.getString("type");
532
+ transceiver = pco.addTransceiver(SerializeUtils.parseMediaType(kind),
533
+ SerializeUtils.parseTransceiverOptions(options.getMap("init")));
534
+ } else if (options.hasKey("trackId")) {
535
+ String trackId = options.getString("trackId");
536
+ MediaStreamTrack track = getLocalTrack(trackId);
537
+ transceiver = pco.addTransceiver(
538
+ track, SerializeUtils.parseTransceiverOptions(options.getMap("init")));
539
+
540
+ } else {
541
+ // This should technically never happen as the JS side checks for that.
542
+ Log.d(TAG, "peerConnectionAddTransceiver() no type nor trackId provided in options");
543
+ return null;
544
+ }
545
+
546
+ if (transceiver == null) {
547
+ Log.d(TAG, "peerConnectionAddTransceiver() Error adding transceiver");
548
+ return null;
549
+ }
550
+ WritableMap params = Arguments.createMap();
551
+ // We need to get a unique order at which the transceiver was created
552
+ // to reorder the cached array of transceivers on the JS layer.
553
+ params.putInt("transceiverOrder", pco.getNextTransceiverId());
554
+ params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
555
+ return params;
556
+ })
557
+ .get();
558
+ } catch (InterruptedException | ExecutionException e) {
559
+ Log.d(TAG, "peerConnectionAddTransceiver() " + e.getMessage());
560
+ return null;
561
+ }
562
+ }
563
+
564
+ @ReactMethod(isBlockingSynchronousMethod = true)
565
+ public WritableMap peerConnectionAddTrack(int id, String trackId, ReadableMap options) {
566
+ try {
567
+ return (WritableMap) ThreadUtils
568
+ .submitToExecutor((Callable<Object>) () -> {
569
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
570
+ if (pco == null) {
571
+ Log.d(TAG, "peerConnectionAddTrack() peerConnection is null");
572
+ return null;
573
+ }
574
+
575
+ MediaStreamTrack track = getLocalTrack(trackId);
576
+ if (track == null) {
577
+ Log.w(TAG, "peerConnectionAddTrack() couldn't find track " + trackId);
578
+ return null;
579
+ }
580
+
581
+ List<String> streamIds = new ArrayList<>();
582
+ if (options.hasKey("streamIds")) {
583
+ ReadableArray rawStreamIds = options.getArray("streamIds");
584
+ if (rawStreamIds != null) {
585
+ for (int i = 0; i < rawStreamIds.size(); i++) {
586
+ streamIds.add(rawStreamIds.getString(i));
587
+ }
588
+ }
589
+ }
590
+ RtpSender sender = pco.getPeerConnection().addTrack(track, streamIds);
591
+
592
+ // Need to get the corresponding transceiver as well
593
+ RtpTransceiver transceiver = pco.getTransceiver(sender.id());
594
+
595
+ // We need the transceiver creation order to reorder the transceivers array
596
+ // in the JS layer.
597
+ WritableMap params = Arguments.createMap();
598
+ params.putInt("transceiverOrder", pco.getNextTransceiverId());
599
+ params.putMap("transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
600
+ params.putMap("sender", SerializeUtils.serializeSender(id, sender));
601
+ return params;
602
+ })
603
+ .get();
604
+ } catch (InterruptedException | ExecutionException e) {
605
+ Log.d(TAG, "peerConnectionAddTrack() " + e.getMessage());
606
+ return null;
607
+ }
608
+ }
609
+
610
+ @ReactMethod(isBlockingSynchronousMethod = true)
611
+ public boolean peerConnectionRemoveTrack(int id, String senderId) {
612
+ try {
613
+ return (boolean) ThreadUtils
614
+ .submitToExecutor((Callable<Object>) () -> {
615
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
616
+ if (pco == null) {
617
+ Log.d(TAG, "peerConnectionRemoveTrack() peerConnection is null");
618
+ return false;
619
+ }
620
+ RtpSender sender = pco.getSender(senderId);
621
+ if (sender == null) {
622
+ Log.w(TAG, "peerConnectionRemoveTrack() sender is null");
623
+ return false;
624
+ }
625
+
626
+ return pco.getPeerConnection().removeTrack(sender);
627
+ })
628
+ .get();
629
+ } catch (InterruptedException | ExecutionException e) {
630
+ Log.d(TAG, "peerConnectionRemoveTrack() " + e.getMessage());
631
+ return false;
632
+ }
633
+ }
634
+
635
+ @ReactMethod
636
+ public void senderSetParameters(int id, String senderId, ReadableMap options, Promise promise) {
637
+ ThreadUtils.runOnExecutor(() -> {
638
+ try {
639
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
640
+ if (pco == null) {
641
+ Log.d(TAG, "senderSetParameters() peerConnectionObserver is null");
642
+ promise.reject(new Exception("Peer Connection is not initialized"));
643
+ return;
644
+ }
645
+
646
+ RtpSender sender = pco.getSender(senderId);
647
+ if (sender == null) {
648
+ Log.w(TAG, "senderSetParameters() sender is null");
649
+ promise.reject(new Exception("Could not get sender"));
650
+ return;
651
+ }
652
+
653
+ RtpParameters params = sender.getParameters();
654
+ params = SerializeUtils.updateRtpParameters(options, params);
655
+ sender.setParameters(params);
656
+ promise.resolve(SerializeUtils.serializeRtpParameters(sender.getParameters()));
657
+ } catch (Exception e) {
658
+ Log.d(TAG, "senderSetParameters: " + e.getMessage());
659
+ promise.reject(e);
660
+ }
661
+ });
662
+ }
663
+
664
+ @ReactMethod
665
+ public void transceiverStop(int id, String senderId, Promise promise) {
666
+ ThreadUtils.runOnExecutor(() -> {
667
+ try {
668
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
669
+ if (pco == null) {
670
+ Log.d(TAG, "transceiverStop() peerConnectionObserver is null");
671
+ promise.reject(new Exception("Peer Connection is not initialized"));
672
+ return;
673
+ }
674
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
675
+ if (transceiver == null) {
676
+ Log.w(TAG, "transceiverStop() transceiver is null");
677
+ promise.reject(new Exception("Could not get transceiver"));
678
+ return;
679
+ }
680
+
681
+ transceiver.stopStandard();
682
+ promise.resolve(true);
683
+ } catch (Exception e) {
684
+ Log.d(TAG, "transceiverStop(): " + e.getMessage());
685
+ promise.reject(e);
686
+ }
687
+ });
688
+ }
689
+
690
+ @ReactMethod
691
+ public void senderReplaceTrack(int id, String senderId, String trackId, Promise promise) {
692
+ ThreadUtils.runOnExecutor(() -> {
693
+ try {
694
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
695
+ if (pco == null) {
696
+ Log.d(TAG, "senderReplaceTrack() peerConnectionObserver is null");
697
+ promise.reject(new Exception("Peer Connection is not initialized"));
698
+ return;
699
+ }
700
+
701
+ RtpSender sender = pco.getSender(senderId);
702
+ if (sender == null) {
703
+ Log.w(TAG, "senderReplaceTrack() sender is null");
704
+ promise.reject(new Exception("Could not get sender"));
705
+ return;
706
+ }
707
+
708
+ MediaStreamTrack track = getLocalTrack(trackId);
709
+ sender.setTrack(track, false);
710
+ promise.resolve(true);
711
+ } catch (Exception e) {
712
+ Log.d(TAG, "senderReplaceTrack(): " + e.getMessage());
713
+ promise.reject(e);
714
+ }
715
+ });
716
+ }
717
+
718
+ @ReactMethod
719
+ public void transceiverSetDirection(int id, String senderId, String direction, Promise promise) {
720
+ ThreadUtils.runOnExecutor(() -> {
721
+ WritableMap identifier = Arguments.createMap();
722
+ WritableMap params = Arguments.createMap();
723
+ identifier.putInt("peerConnectionId", id);
724
+ identifier.putString("transceiverId", senderId);
725
+ try {
726
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
727
+ if (pco == null) {
728
+ Log.d(TAG, "transceiverSetDirection() peerConnectionObserver is null");
729
+ promise.reject(new Exception("Peer Connection is not initialized"));
730
+ return;
731
+ }
732
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
733
+ if (transceiver == null) {
734
+ Log.d(TAG, "transceiverSetDirection() transceiver is null");
735
+ promise.reject(new Exception("Could not get sender"));
736
+ return;
737
+ }
738
+
739
+ transceiver.setDirection(SerializeUtils.parseDirection(direction));
740
+
741
+ promise.resolve(true);
742
+ } catch (Exception e) {
743
+ Log.d(TAG, "transceiverSetDirection(): " + e.getMessage());
744
+ promise.reject(e);
745
+ }
746
+ });
747
+ }
748
+
749
+ @ReactMethod(isBlockingSynchronousMethod = true)
750
+ public boolean transceiverSetCodecPreferences(int id, String senderId, ReadableArray codecPreferences) {
751
+ ThreadUtils.runOnExecutor(() -> {
752
+ WritableMap identifier = Arguments.createMap();
753
+ WritableMap params = Arguments.createMap();
754
+ identifier.putInt("peerConnectionId", id);
755
+ identifier.putString("transceiverId", senderId);
756
+ try {
757
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
758
+ if (pco == null) {
759
+ Log.d(TAG, "transceiverSetDirection() peerConnectionObserver is null");
760
+ return;
761
+ }
762
+ RtpTransceiver transceiver = pco.getTransceiver(senderId);
763
+ if (transceiver == null) {
764
+ Log.d(TAG, "transceiverSetDirection() transceiver is null");
765
+ return;
766
+ }
767
+
768
+ // Convert JSON codec capabilities to the actual objects.
769
+ RtpTransceiver.RtpTransceiverDirection direction = transceiver.getDirection();
770
+ List<Pair<Map<String, Object>, RtpCapabilities.CodecCapability>> availableCodecs = new ArrayList<>();
771
+
772
+ if (direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_RECV)
773
+ || direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY)) {
774
+ RtpCapabilities capabilities = mFactory.getRtpSenderCapabilities(transceiver.getMediaType());
775
+ for (RtpCapabilities.CodecCapability codec : capabilities.codecs) {
776
+ Map<String, Object> codecDict = SerializeUtils.serializeRtpCapabilitiesCodec(codec).toHashMap();
777
+ availableCodecs.add(new Pair<>(codecDict, codec));
778
+ }
779
+ }
780
+
781
+ if (direction.equals(RtpTransceiver.RtpTransceiverDirection.SEND_RECV)
782
+ || direction.equals(RtpTransceiver.RtpTransceiverDirection.RECV_ONLY)) {
783
+ RtpCapabilities capabilities = mFactory.getRtpReceiverCapabilities(transceiver.getMediaType());
784
+ for (RtpCapabilities.CodecCapability codec : capabilities.codecs) {
785
+ Map<String, Object> codecDict = SerializeUtils.serializeRtpCapabilitiesCodec(codec).toHashMap();
786
+ availableCodecs.add(new Pair<>(codecDict, codec));
787
+ }
788
+ }
789
+
790
+ // Codec preferences is order sensitive.
791
+ List<RtpCapabilities.CodecCapability> codecsToSet = new ArrayList<>();
792
+
793
+ for (int i = 0; i < codecPreferences.size(); i++) {
794
+ Map<String, Object> codecPref = codecPreferences.getMap(i).toHashMap();
795
+ for (Pair<Map<String, Object>, RtpCapabilities.CodecCapability> pair : availableCodecs) {
796
+ Map<String, Object> availableCodecDict = pair.first;
797
+ if (codecPref.equals(availableCodecDict)) {
798
+ codecsToSet.add(pair.second);
799
+ break;
800
+ }
801
+ }
802
+ }
803
+
804
+ transceiver.setCodecPreferences(codecsToSet);
805
+ } catch (Exception e) {
806
+ Log.d(TAG, "transceiverSetCodecPreferences(): " + e.getMessage());
807
+ }
808
+ });
809
+ return true;
810
+ }
811
+
812
+ @ReactMethod
813
+ public void getDisplayMedia(Promise promise) {
814
+ ThreadUtils.runOnExecutor(() -> getUserMediaImpl.getDisplayMedia(promise));
815
+ }
816
+
817
+ @ReactMethod
818
+ public void getUserMedia(ReadableMap constraints, Callback successCallback, Callback errorCallback) {
819
+ ThreadUtils.runOnExecutor(() -> getUserMediaImpl.getUserMedia(constraints, successCallback, errorCallback));
820
+ }
821
+
822
+ @ReactMethod
823
+ public void enumerateDevices(Callback callback) {
824
+ ThreadUtils.runOnExecutor(() -> callback.invoke(getUserMediaImpl.enumerateDevices()));
825
+ }
826
+
827
+ @ReactMethod
828
+ public void mediaStreamCreate(String id) {
829
+ ThreadUtils.runOnExecutor(() -> {
830
+ MediaStream mediaStream = mFactory.createLocalMediaStream(id);
831
+ localStreams.put(id, mediaStream);
832
+ });
833
+ }
834
+
835
+ @ReactMethod
836
+ public void mediaStreamAddTrack(String streamId, int pcId, String trackId) {
837
+ ThreadUtils.runOnExecutor(() -> {
838
+ MediaStream stream = localStreams.get(streamId);
839
+ if (stream == null) {
840
+ Log.d(TAG, "mediaStreamAddTrack() could not find stream " + streamId);
841
+ return;
842
+ }
843
+
844
+ MediaStreamTrack track = getTrack(pcId, trackId);
845
+ if (track == null) {
846
+ Log.d(TAG, "mediaStreamAddTrack() could not find track " + trackId);
847
+ return;
848
+ }
849
+
850
+ String kind = track.kind();
851
+ if ("audio".equals(kind)) {
852
+ stream.addTrack((AudioTrack) track);
853
+ } else if ("video".equals(kind)) {
854
+ stream.addTrack((VideoTrack) track);
855
+ }
856
+ });
857
+ }
858
+
859
+ @ReactMethod
860
+ public void mediaStreamRemoveTrack(String streamId, int pcId, String trackId) {
861
+ ThreadUtils.runOnExecutor(() -> {
862
+ MediaStream stream = localStreams.get(streamId);
863
+ if (stream == null) {
864
+ Log.d(TAG, "mediaStreamRemoveTrack() could not find stream " + streamId);
865
+ return;
866
+ }
867
+
868
+ MediaStreamTrack track = getTrack(pcId, trackId);
869
+ if (track == null) {
870
+ Log.d(TAG, "mediaStreamRemoveTrack() could not find track " + trackId);
871
+ return;
872
+ }
873
+
874
+ String kind = track.kind();
875
+ if ("audio".equals(kind)) {
876
+ stream.removeTrack((AudioTrack) track);
877
+ } else if ("video".equals(kind)) {
878
+ stream.removeTrack((VideoTrack) track);
879
+ }
880
+ });
881
+ }
882
+
883
+ @ReactMethod
884
+ public void mediaStreamRelease(String id) {
885
+ ThreadUtils.runOnExecutor(() -> {
886
+ MediaStream stream = localStreams.get(id);
887
+ if (stream == null) {
888
+ Log.d(TAG, "mediaStreamRelease() stream is null");
889
+ return;
890
+ }
891
+ localStreams.remove(id);
892
+ stream.dispose();
893
+ });
894
+ }
895
+
896
+ @ReactMethod
897
+ public void mediaStreamTrackRelease(String id) {
898
+ ThreadUtils.runOnExecutor(() -> {
899
+ MediaStreamTrack track = getLocalTrack(id);
900
+ if (track == null) {
901
+ Log.d(TAG, "mediaStreamTrackRelease() track is null");
902
+ return;
903
+ }
904
+ track.setEnabled(false);
905
+ getUserMediaImpl.disposeTrack(id);
906
+ });
907
+ }
908
+
909
+ @ReactMethod
910
+ public void mediaStreamTrackSetEnabled(int pcId, String id, boolean enabled) {
911
+ ThreadUtils.runOnExecutor(() -> {
912
+ MediaStreamTrack track = getTrack(pcId, id);
913
+ if (track == null) {
914
+ Log.d(TAG, "mediaStreamTrackSetEnabled() could not find track " + id);
915
+ return;
916
+ }
917
+
918
+ if (track.enabled() == enabled) {
919
+ return;
920
+ }
921
+ track.setEnabled(enabled);
922
+ getUserMediaImpl.mediaStreamTrackSetEnabled(id, enabled);
923
+ });
924
+ }
925
+
926
+ @ReactMethod
927
+ public void mediaStreamTrackApplyConstraints(String id, ReadableMap constraints, Promise promise) {
928
+ ThreadUtils.runOnExecutor(() -> {
929
+ MediaStreamTrack track = getLocalTrack(id);
930
+ if (track != null) {
931
+ getUserMediaImpl.applyConstraints(id, constraints, promise);
932
+ } else {
933
+ promise.reject(new Exception("mediaStreamTrackApplyConstraints() could not find track " + id));
934
+ }
935
+ });
936
+ }
937
+
938
+ @ReactMethod
939
+ public void mediaStreamTrackSetVolume(int pcId, String id, double volume) {
940
+ ThreadUtils.runOnExecutor(() -> {
941
+ MediaStreamTrack track = getTrack(pcId, id);
942
+ if (track == null) {
943
+ Log.d(TAG, "mediaStreamTrackSetVolume() could not find track " + id);
944
+ return;
945
+ }
946
+
947
+ if (!(track instanceof AudioTrack)) {
948
+ Log.d(TAG, "mediaStreamTrackSetVolume() track is not an AudioTrack!");
949
+ return;
950
+ }
951
+
952
+ ((AudioTrack) track).setVolume(volume);
953
+ });
954
+ }
955
+
956
+ @ReactMethod
957
+ public void mediaStreamTrackSetPlaybackEnabled(int pcId, String id, boolean enabled) {
958
+ ThreadUtils.runOnExecutor(() -> {
959
+ MediaStreamTrack track = getTrack(pcId, id);
960
+ if (track == null) {
961
+ Log.d(TAG, "mediaStreamTrackSetPlaybackEnabled() could not find track " + id);
962
+ return;
963
+ }
964
+
965
+ if (!(track instanceof AudioTrack)) {
966
+ Log.d(TAG, "mediaStreamTrackSetPlaybackEnabled() track is not an AudioTrack!");
967
+ return;
968
+ }
969
+
970
+ ((AudioTrack) track).setVolume(enabled ? 1.0 : 0.0);
971
+ });
972
+ }
973
+
974
+ @ReactMethod
975
+ public void mediaStreamTrackEnableAudioSink(int pcId, String id, boolean enabled) {
976
+ Log.d(TAG, "mediaStreamTrackEnableAudioSink() pcId=" + pcId + " trackId=" + id + " enabled=" + enabled + " - Not fully implemented on Android");
977
+ }
978
+
979
+ /**
980
+ * This serializes the transceivers current direction and mid and returns them
981
+ * for update when an sdp negotiation/renegotiation happens
982
+ */
983
+ private ReadableArray getTransceiversInfo(PeerConnection peerConnection) {
984
+ WritableArray transceiverUpdates = Arguments.createArray();
985
+
986
+ for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
987
+ WritableMap transceiverUpdate = Arguments.createMap();
988
+
989
+ RtpTransceiver.RtpTransceiverDirection direction = transceiver.getCurrentDirection();
990
+ if (direction != null) {
991
+ String directionSerialized = SerializeUtils.serializeDirection(direction);
992
+ transceiverUpdate.putString("currentDirection", directionSerialized);
993
+ }
994
+
995
+ transceiverUpdate.putString("transceiverId", transceiver.getSender().id());
996
+ transceiverUpdate.putString("mid", transceiver.getMid());
997
+ transceiverUpdate.putBoolean("isStopped", transceiver.isStopped());
998
+ transceiverUpdate.putMap("senderRtpParameters",
999
+ SerializeUtils.serializeRtpParameters(transceiver.getSender().getParameters()));
1000
+ transceiverUpdate.putMap("receiverRtpParameters",
1001
+ SerializeUtils.serializeRtpParameters(transceiver.getReceiver().getParameters()));
1002
+ transceiverUpdates.pushMap(transceiverUpdate);
1003
+ }
1004
+ return transceiverUpdates;
1005
+ }
1006
+
1007
+ @ReactMethod
1008
+ public void mediaStreamTrackSetVideoEffects(String id, ReadableArray names) {
1009
+ ThreadUtils.runOnExecutor(() -> { getUserMediaImpl.setVideoEffects(id, names); });
1010
+ }
1011
+
1012
+ @ReactMethod
1013
+ public void peerConnectionSetConfiguration(ReadableMap configuration, int id) {
1014
+ ThreadUtils.runOnExecutor(() -> {
1015
+ PeerConnection peerConnection = getPeerConnection(id);
1016
+ if (peerConnection == null) {
1017
+ Log.d(TAG, "peerConnectionSetConfiguration() peerConnection is null");
1018
+ return;
1019
+ }
1020
+ peerConnection.setConfiguration(parseRTCConfiguration(configuration));
1021
+ });
1022
+ }
1023
+
1024
+ @ReactMethod
1025
+ public void peerConnectionCreateOffer(int id, ReadableMap options, Promise promise) {
1026
+ ThreadUtils.runOnExecutor(() -> {
1027
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1028
+ PeerConnection peerConnection = pco.getPeerConnection();
1029
+
1030
+ if (peerConnection == null) {
1031
+ Log.d(TAG, "peerConnectionCreateOffer() peerConnection is null");
1032
+ promise.reject(new Exception("PeerConnection not found"));
1033
+ return;
1034
+ }
1035
+
1036
+ List<String> receiversIds = new ArrayList<>();
1037
+ for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
1038
+ receiversIds.add(transceiver.getReceiver().id());
1039
+ }
1040
+
1041
+ final SdpObserver observer = new SdpObserver() {
1042
+ @Override
1043
+ public void onCreateFailure(String s) {
1044
+ ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
1045
+ }
1046
+
1047
+ @Override
1048
+ public void onCreateSuccess(SessionDescription sdp) {
1049
+ ThreadUtils.runOnExecutor(() -> {
1050
+ WritableMap params = Arguments.createMap();
1051
+ WritableMap sdpInfo = Arguments.createMap();
1052
+
1053
+ sdpInfo.putString("sdp", sdp.description);
1054
+ sdpInfo.putString("type", sdp.type.canonicalForm());
1055
+
1056
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1057
+ params.putMap("sdpInfo", sdpInfo);
1058
+
1059
+ WritableArray newTransceivers = Arguments.createArray();
1060
+ for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
1061
+ if (!receiversIds.contains(transceiver.getReceiver().id())) {
1062
+ WritableMap newTransceiver = Arguments.createMap();
1063
+ newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
1064
+ newTransceiver.putMap(
1065
+ "transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
1066
+ newTransceivers.pushMap(newTransceiver);
1067
+ }
1068
+ }
1069
+
1070
+ params.putArray("newTransceivers", newTransceivers);
1071
+
1072
+ promise.resolve(params);
1073
+ });
1074
+ }
1075
+
1076
+ @Override
1077
+ public void onSetFailure(String s) {}
1078
+
1079
+ @Override
1080
+ public void onSetSuccess() {}
1081
+ };
1082
+
1083
+ peerConnection.createOffer(observer, constraintsForOptions(options));
1084
+ });
1085
+ }
1086
+
1087
+ @ReactMethod
1088
+ public void peerConnectionCreateAnswer(int id, ReadableMap options, Promise promise) {
1089
+ ThreadUtils.runOnExecutor(() -> {
1090
+ PeerConnection peerConnection = getPeerConnection(id);
1091
+
1092
+ if (peerConnection == null) {
1093
+ Log.d(TAG, "peerConnectionCreateAnswer() peerConnection is null");
1094
+ promise.reject(new Exception("PeerConnection not found"));
1095
+ return;
1096
+ }
1097
+
1098
+ final SdpObserver observer = new SdpObserver() {
1099
+ @Override
1100
+ public void onCreateFailure(String s) {
1101
+ ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
1102
+ }
1103
+
1104
+ @Override
1105
+ public void onCreateSuccess(SessionDescription sdp) {
1106
+ ThreadUtils.runOnExecutor(() -> {
1107
+ WritableMap params = Arguments.createMap();
1108
+ WritableMap sdpInfo = Arguments.createMap();
1109
+
1110
+ sdpInfo.putString("sdp", sdp.description);
1111
+ sdpInfo.putString("type", sdp.type.canonicalForm());
1112
+
1113
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1114
+ params.putMap("sdpInfo", sdpInfo);
1115
+
1116
+ promise.resolve(params);
1117
+ });
1118
+ }
1119
+
1120
+ @Override
1121
+ public void onSetFailure(String s) {}
1122
+
1123
+ @Override
1124
+ public void onSetSuccess() {}
1125
+ };
1126
+
1127
+ peerConnection.createAnswer(observer, constraintsForOptions(options));
1128
+ });
1129
+ }
1130
+
1131
+ @ReactMethod
1132
+ public void peerConnectionSetLocalDescription(int pcId, ReadableMap desc, Promise promise) {
1133
+ ThreadUtils.runOnExecutor(() -> {
1134
+ PeerConnection peerConnection = getPeerConnection(pcId);
1135
+ if (peerConnection == null) {
1136
+ Log.d(TAG, "peerConnectionSetLocalDescription() peerConnection is null");
1137
+ promise.reject(new Exception("PeerConnection not found"));
1138
+ return;
1139
+ }
1140
+
1141
+ final SdpObserver observer = new SdpObserver() {
1142
+ @Override
1143
+ public void onCreateSuccess(SessionDescription sdp) {}
1144
+
1145
+ @Override
1146
+ public void onSetSuccess() {
1147
+ ThreadUtils.runOnExecutor(() -> {
1148
+ WritableMap newSdpMap = Arguments.createMap();
1149
+ WritableMap params = Arguments.createMap();
1150
+
1151
+ SessionDescription newSdp = peerConnection.getLocalDescription();
1152
+ // Can happen when doing a rollback.
1153
+ if (newSdp != null) {
1154
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
1155
+ newSdpMap.putString("sdp", newSdp.description);
1156
+ }
1157
+
1158
+ params.putMap("sdpInfo", newSdpMap);
1159
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1160
+
1161
+ promise.resolve(params);
1162
+ });
1163
+ }
1164
+
1165
+ @Override
1166
+ public void onCreateFailure(String s) {}
1167
+
1168
+ @Override
1169
+ public void onSetFailure(String s) {
1170
+ ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
1171
+ }
1172
+ };
1173
+
1174
+ if (desc != null) {
1175
+ SessionDescription sdp = new SessionDescription(
1176
+ SessionDescription.Type.fromCanonicalForm(Objects.requireNonNull(desc.getString("type"))),
1177
+ desc.getString("sdp"));
1178
+
1179
+ peerConnection.setLocalDescription(observer, sdp);
1180
+ } else {
1181
+ peerConnection.setLocalDescription(observer);
1182
+ }
1183
+ });
1184
+ }
1185
+
1186
+ @ReactMethod
1187
+ public void peerConnectionSetRemoteDescription(int id, ReadableMap desc, Promise promise) {
1188
+ ThreadUtils.runOnExecutor(() -> {
1189
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1190
+ PeerConnection peerConnection = pco.getPeerConnection();
1191
+
1192
+ if (peerConnection == null) {
1193
+ Log.d(TAG, "peerConnectionSetRemoteDescription() peerConnection is null");
1194
+ promise.reject(new Exception("PeerConnection not found"));
1195
+ return;
1196
+ }
1197
+
1198
+ SessionDescription sdp = new SessionDescription(
1199
+ SessionDescription.Type.fromCanonicalForm(desc.getString("type")), desc.getString("sdp"));
1200
+
1201
+ List<String> receiversIds = new ArrayList<>();
1202
+ for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
1203
+ receiversIds.add(transceiver.getReceiver().id());
1204
+ }
1205
+
1206
+ final SdpObserver observer = new SdpObserver() {
1207
+ @Override
1208
+ public void onCreateSuccess(final SessionDescription sdp) {}
1209
+
1210
+ @Override
1211
+ public void onSetSuccess() {
1212
+ ThreadUtils.runOnExecutor(() -> {
1213
+ WritableMap newSdpMap = Arguments.createMap();
1214
+ WritableMap params = Arguments.createMap();
1215
+
1216
+ SessionDescription newSdp = peerConnection.getRemoteDescription();
1217
+ // Be defensive for the rollback cases.
1218
+ if (newSdp != null) {
1219
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
1220
+ newSdpMap.putString("sdp", newSdp.description);
1221
+ }
1222
+
1223
+ params.putArray("transceiversInfo", getTransceiversInfo(peerConnection));
1224
+ params.putMap("sdpInfo", newSdpMap);
1225
+
1226
+ WritableArray newTransceivers = Arguments.createArray();
1227
+ for (RtpTransceiver transceiver : peerConnection.getTransceivers()) {
1228
+ if (!receiversIds.contains(transceiver.getReceiver().id())) {
1229
+ WritableMap newTransceiver = Arguments.createMap();
1230
+ newTransceiver.putInt("transceiverOrder", pco.getNextTransceiverId());
1231
+ newTransceiver.putMap(
1232
+ "transceiver", SerializeUtils.serializeTransceiver(id, transceiver));
1233
+ newTransceivers.pushMap(newTransceiver);
1234
+ }
1235
+ }
1236
+
1237
+ params.putArray("newTransceivers", newTransceivers);
1238
+
1239
+ promise.resolve(params);
1240
+ });
1241
+ }
1242
+
1243
+ @Override
1244
+ public void onCreateFailure(String s) {}
1245
+
1246
+ @Override
1247
+ public void onSetFailure(String s) {
1248
+ ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
1249
+ }
1250
+ };
1251
+
1252
+ peerConnection.setRemoteDescription(observer, sdp);
1253
+ });
1254
+ }
1255
+
1256
+ @ReactMethod(isBlockingSynchronousMethod = true)
1257
+ public WritableMap receiverGetCapabilities(String kind) {
1258
+ try {
1259
+ return (WritableMap) ThreadUtils
1260
+ .submitToExecutor((Callable<Object>) () -> {
1261
+ MediaStreamTrack.MediaType mediaType;
1262
+ if (kind.equals("audio")) {
1263
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO;
1264
+ } else if (kind.equals("video")) {
1265
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO;
1266
+ } else {
1267
+ return Arguments.createMap();
1268
+ }
1269
+
1270
+ RtpCapabilities capabilities = mFactory.getRtpReceiverCapabilities(mediaType);
1271
+ return SerializeUtils.serializeRtpCapabilities(capabilities);
1272
+ })
1273
+ .get();
1274
+ } catch (ExecutionException | InterruptedException e) {
1275
+ Log.d(TAG, "receiverGetCapabilities() " + e.getMessage());
1276
+ return null;
1277
+ }
1278
+ }
1279
+
1280
+ @ReactMethod(isBlockingSynchronousMethod = true)
1281
+ public WritableMap senderGetCapabilities(String kind) {
1282
+ try {
1283
+ return (WritableMap) ThreadUtils
1284
+ .submitToExecutor((Callable<Object>) () -> {
1285
+ MediaStreamTrack.MediaType mediaType;
1286
+ if (kind.equals("audio")) {
1287
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO;
1288
+ } else if (kind.equals("video")) {
1289
+ mediaType = MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO;
1290
+ } else {
1291
+ return Arguments.createMap();
1292
+ }
1293
+
1294
+ RtpCapabilities capabilities = mFactory.getRtpSenderCapabilities(mediaType);
1295
+ return SerializeUtils.serializeRtpCapabilities(capabilities);
1296
+ })
1297
+ .get();
1298
+ } catch (ExecutionException | InterruptedException e) {
1299
+ Log.d(TAG, "senderGetCapabilities() " + e.getMessage());
1300
+ return null;
1301
+ }
1302
+ }
1303
+
1304
+ @ReactMethod
1305
+ public void receiverGetStats(int pcId, String receiverId, Promise promise) {
1306
+ ThreadUtils.runOnExecutor(() -> {
1307
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
1308
+ if (pco == null || pco.getPeerConnection() == null) {
1309
+ Log.d(TAG, "receiverGetStats() peerConnection is null");
1310
+ promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
1311
+ } else {
1312
+ pco.receiverGetStats(receiverId, promise);
1313
+ }
1314
+ });
1315
+ }
1316
+
1317
+ @ReactMethod
1318
+ public void senderGetStats(int pcId, String senderId, Promise promise) {
1319
+ ThreadUtils.runOnExecutor(() -> {
1320
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(pcId);
1321
+ if (pco == null || pco.getPeerConnection() == null) {
1322
+ Log.d(TAG, "senderGetStats() peerConnection is null");
1323
+ promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
1324
+ } else {
1325
+ pco.senderGetStats(senderId, promise);
1326
+ }
1327
+ });
1328
+ }
1329
+
1330
+ @ReactMethod
1331
+ public void peerConnectionAddICECandidate(int pcId, ReadableMap candidateMap, Promise promise) {
1332
+ ThreadUtils.runOnExecutor(() -> {
1333
+ PeerConnection peerConnection = getPeerConnection(pcId);
1334
+ if (peerConnection == null) {
1335
+ Log.d(TAG, "peerConnectionAddICECandidate() peerConnection is null");
1336
+ promise.reject(new Exception("PeerConnection not found"));
1337
+ return;
1338
+ }
1339
+
1340
+ if (!candidateMap.hasKey("sdpMid") && !candidateMap.hasKey("sdpMLineIndex")) {
1341
+ promise.reject("E_TYPE_ERROR", "Invalid argument");
1342
+ return;
1343
+ }
1344
+
1345
+ IceCandidate candidate = new IceCandidate(candidateMap.hasKey("sdpMid") && !candidateMap.isNull("sdpMid")
1346
+ ? candidateMap.getString("sdpMid")
1347
+ : "",
1348
+ candidateMap.hasKey("sdpMLineIndex") && !candidateMap.isNull("sdpMLineIndex")
1349
+ ? candidateMap.getInt("sdpMLineIndex")
1350
+ : 0,
1351
+ candidateMap.getString("candidate"));
1352
+
1353
+ peerConnection.addIceCandidate(candidate, new AddIceObserver() {
1354
+ @Override
1355
+ public void onAddSuccess() {
1356
+ ThreadUtils.runOnExecutor(() -> {
1357
+ WritableMap newSdpMap = Arguments.createMap();
1358
+ SessionDescription newSdp = peerConnection.getRemoteDescription();
1359
+ newSdpMap.putString("type", newSdp.type.canonicalForm());
1360
+ newSdpMap.putString("sdp", newSdp.description);
1361
+ promise.resolve(newSdpMap);
1362
+ });
1363
+ }
1364
+
1365
+ @Override
1366
+ public void onAddFailure(String s) {
1367
+ ThreadUtils.runOnExecutor(() -> { promise.reject("E_OPERATION_ERROR", s); });
1368
+ }
1369
+ });
1370
+ });
1371
+ }
1372
+
1373
+ @ReactMethod
1374
+ public void peerConnectionGetStats(int peerConnectionId, Promise promise) {
1375
+ ThreadUtils.runOnExecutor(() -> {
1376
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1377
+ if (pco == null || pco.getPeerConnection() == null) {
1378
+ Log.d(TAG, "peerConnectionGetStats() peerConnection is null");
1379
+ promise.resolve(StringUtils.statsToJSON(new RTCStatsReport(0, new HashMap<>())));
1380
+ } else {
1381
+ pco.getStats(promise);
1382
+ }
1383
+ });
1384
+ }
1385
+
1386
+ @ReactMethod
1387
+ public void peerConnectionClose(int id) {
1388
+ ThreadUtils.runOnExecutor(() -> {
1389
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1390
+ if (pco == null || pco.getPeerConnection() == null) {
1391
+ Log.d(TAG, "peerConnectionClose() peerConnection is null");
1392
+ return;
1393
+ }
1394
+ pco.close();
1395
+ });
1396
+ }
1397
+
1398
+ @ReactMethod
1399
+ public void peerConnectionDispose(int id) {
1400
+ ThreadUtils.runOnExecutor(() -> {
1401
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(id);
1402
+ if (pco == null || pco.getPeerConnection() == null) {
1403
+ Log.d(TAG, "peerConnectionDispose() peerConnection is null");
1404
+ }
1405
+ pco.dispose();
1406
+ mPeerConnectionObservers.remove(id);
1407
+ });
1408
+ }
1409
+
1410
+ @ReactMethod
1411
+ public void peerConnectionRestartIce(int pcId) {
1412
+ ThreadUtils.runOnExecutor(() -> {
1413
+ PeerConnection peerConnection = getPeerConnection(pcId);
1414
+ if (peerConnection == null) {
1415
+ Log.w(TAG, "peerConnectionRestartIce() peerConnection is null");
1416
+ return;
1417
+ }
1418
+
1419
+ peerConnection.restartIce();
1420
+ });
1421
+ }
1422
+
1423
+ @ReactMethod(isBlockingSynchronousMethod = true)
1424
+ public WritableMap createDataChannel(int peerConnectionId, String label, ReadableMap config) {
1425
+ try {
1426
+ return (WritableMap) ThreadUtils
1427
+ .submitToExecutor((Callable<Object>) () -> {
1428
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1429
+ if (pco == null || pco.getPeerConnection() == null) {
1430
+ Log.d(TAG, "createDataChannel() peerConnection is null");
1431
+ return null;
1432
+ } else {
1433
+ return pco.createDataChannel(label, config);
1434
+ }
1435
+ })
1436
+ .get();
1437
+ } catch (ExecutionException | InterruptedException e) {
1438
+ return null;
1439
+ }
1440
+ }
1441
+
1442
+ @ReactMethod
1443
+ public void dataChannelClose(int peerConnectionId, String reactTag) {
1444
+ ThreadUtils.runOnExecutor(() -> {
1445
+ // Forward to PeerConnectionObserver which deals with DataChannels
1446
+ // because DataChannel is owned by PeerConnection.
1447
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1448
+ if (pco == null || pco.getPeerConnection() == null) {
1449
+ Log.d(TAG, "dataChannelClose() peerConnection is null");
1450
+ return;
1451
+ }
1452
+
1453
+ pco.dataChannelClose(reactTag);
1454
+ });
1455
+ }
1456
+
1457
+ @ReactMethod
1458
+ public void dataChannelDispose(int peerConnectionId, String reactTag) {
1459
+ ThreadUtils.runOnExecutor(() -> {
1460
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1461
+ if (pco == null || pco.getPeerConnection() == null) {
1462
+ Log.d(TAG, "dataChannelDispose() peerConnection is null");
1463
+ return;
1464
+ }
1465
+
1466
+ pco.dataChannelDispose(reactTag);
1467
+ });
1468
+ }
1469
+
1470
+ @ReactMethod
1471
+ public void dataChannelSend(int peerConnectionId, String reactTag, String data, String type) {
1472
+ ThreadUtils.runOnExecutor(() -> {
1473
+ // Forward to PeerConnectionObserver which deals with DataChannels
1474
+ // because DataChannel is owned by PeerConnection.
1475
+ PeerConnectionObserver pco = mPeerConnectionObservers.get(peerConnectionId);
1476
+ if (pco == null || pco.getPeerConnection() == null) {
1477
+ Log.d(TAG, "dataChannelSend() peerConnection is null");
1478
+ return;
1479
+ }
1480
+
1481
+ pco.dataChannelSend(reactTag, data, type);
1482
+ });
1483
+ }
1484
+
1485
+ // Frame Cryptor methods
1486
+ ////////////////////////////////
1487
+ RTCCryptoManager frameCryptor = new RTCCryptoManager(this);
1488
+
1489
+ @ReactMethod(isBlockingSynchronousMethod = true)
1490
+ public String frameCryptorFactoryCreateFrameCryptor(ReadableMap config) {
1491
+ return frameCryptor.frameCryptorFactoryCreateFrameCryptor(config);
1492
+ }
1493
+
1494
+ @ReactMethod
1495
+ public void frameCryptorSetKeyIndex(ReadableMap config, Promise promise) {
1496
+ frameCryptor.frameCryptorSetKeyIndex(config, promise);
1497
+ }
1498
+
1499
+ @ReactMethod
1500
+ public void frameCryptorGetKeyIndex(ReadableMap config, Promise promise) {
1501
+ frameCryptor.frameCryptorGetKeyIndex(config, promise);
1502
+ }
1503
+
1504
+ @ReactMethod
1505
+ public void frameCryptorSetEnabled(ReadableMap config, Promise promise) {
1506
+ frameCryptor.frameCryptorSetEnabled(config, promise);
1507
+ }
1508
+
1509
+ @ReactMethod
1510
+ public void frameCryptorGetEnabled(ReadableMap config, Promise promise) {
1511
+ frameCryptor.frameCryptorGetEnabled(config, promise);
1512
+ }
1513
+
1514
+ @ReactMethod
1515
+ public void frameCryptorDispose(ReadableMap config, Promise promise) {
1516
+ frameCryptor.frameCryptorDispose(config, promise);
1517
+ }
1518
+
1519
+ @ReactMethod(isBlockingSynchronousMethod = true)
1520
+ public String frameCryptorFactoryCreateKeyProvider(ReadableMap config) {
1521
+ return frameCryptor.frameCryptorFactoryCreateKeyProvider(config);
1522
+ }
1523
+
1524
+ @ReactMethod
1525
+ public void keyProviderSetSharedKey(ReadableMap config, Promise promise) {
1526
+ frameCryptor.keyProviderSetSharedKey(config, promise);
1527
+ }
1528
+
1529
+ @ReactMethod
1530
+ public void keyProviderRatchetSharedKey(ReadableMap config, Promise promise) {
1531
+ frameCryptor.keyProviderRatchetSharedKey(config, promise);
1532
+ }
1533
+
1534
+ @ReactMethod
1535
+ public void keyProviderExportSharedKey(ReadableMap config, Promise promise) {
1536
+ frameCryptor.keyProviderExportSharedKey(config, promise);
1537
+ }
1538
+
1539
+ @ReactMethod
1540
+ public void keyProviderSetKey(ReadableMap config, Promise promise) {
1541
+ frameCryptor.keyProviderSetKey(config, promise);
1542
+ }
1543
+
1544
+ @ReactMethod
1545
+ public void keyProviderRatchetKey(ReadableMap config, Promise promise) {
1546
+ frameCryptor.keyProviderRatchetKey(config, promise);
1547
+ }
1548
+
1549
+ @ReactMethod
1550
+ public void keyProviderExportKey(ReadableMap config, Promise promise) {
1551
+ frameCryptor.keyProviderExportKey(config, promise);
1552
+ }
1553
+
1554
+ @ReactMethod
1555
+ public void keyProviderSetSifTrailer(ReadableMap config, Promise promise) {
1556
+ frameCryptor.keyProviderSetSifTrailer(config, promise);
1557
+ }
1558
+
1559
+ @ReactMethod
1560
+ public void keyProviderDispose(ReadableMap config, Promise promise) {
1561
+ frameCryptor.keyProviderDispose(config, promise);
1562
+ }
1563
+
1564
+ @ReactMethod
1565
+ public void dataPacketCryptorFactoryCreateDataPacketCryptor(ReadableMap params, @NonNull Promise result) {
1566
+ frameCryptor.dataPacketCryptorFactoryCreateDataPacketCryptor(params, result);
1567
+ }
1568
+
1569
+ @ReactMethod
1570
+ public void dataPacketCryptorEncrypt(ReadableMap params, @NonNull Promise result) {
1571
+ frameCryptor.dataPacketCryptorEncrypt(params, result);
1572
+ }
1573
+
1574
+ @ReactMethod
1575
+ public void dataPacketCryptorDecrypt(ReadableMap params, @NonNull Promise result) {
1576
+ frameCryptor.dataPacketCryptorDecrypt(params, result);
1577
+ }
1578
+
1579
+ @ReactMethod
1580
+ public void dataPacketCryptorDispose(ReadableMap params, @NonNull Promise result) {
1581
+ frameCryptor.dataPacketCryptorDispose(params, result);
1582
+ }
1583
+
1584
+ @ReactMethod
1585
+ public void addListener(String eventName) {
1586
+ // Keep: Required for RN built in Event Emitter Calls.
1587
+ }
1588
+
1589
+ @ReactMethod
1590
+ public void removeListeners(Integer count) {
1591
+ // Keep: Required for RN built in Event Emitter Calls.
1592
+ }
1593
+ }