@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.
- package/.clang-format +11 -0
- package/.eslintignore +6 -0
- package/.nvmrc +1 -0
- package/ISSUE_TEMPLATE.md +40 -0
- package/LICENSE +22 -0
- package/README.md +82 -0
- package/android/build.gradle +36 -0
- package/android/consumer-rules.pro +3 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +113 -0
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +338 -0
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +49 -0
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +99 -0
- package/android/src/main/java/com/oney/WebRTCModule/DataPacketCryptorManager.java +63 -0
- package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +16 -0
- package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +66 -0
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +539 -0
- package/android/src/main/java/com/oney/WebRTCModule/LibraryLoader.java +21 -0
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +70 -0
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +82 -0
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +588 -0
- package/android/src/main/java/com/oney/WebRTCModule/RTCCryptoManager.java +493 -0
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +98 -0
- package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +36 -0
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +94 -0
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +342 -0
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +101 -0
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +41 -0
- package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -0
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +137 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +1593 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java +33 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +21 -0
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +583 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +38 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +59 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -0
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +12 -0
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoDecoderFactory.java +73 -0
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoEncoderFactory.java +73 -0
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoDecoderFactoryProxy.java +36 -0
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoEncoderFactoryProxy.java +36 -0
- package/android/src/main/java/org/webrtc/Camera1Helper.java +54 -0
- package/android/src/main/java/org/webrtc/Camera2Helper.java +52 -0
- package/android/src/main/res/values/strings.xml +5 -0
- package/android/src/main/res/values/styles.xml +8 -0
- package/apple/.placeholder +0 -0
- package/ios/RCTWebRTC/CaptureController.h +18 -0
- package/ios/RCTWebRTC/CaptureController.m +29 -0
- package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -0
- package/ios/RCTWebRTC/DataChannelWrapper.h +27 -0
- package/ios/RCTWebRTC/DataChannelWrapper.m +42 -0
- package/ios/RCTWebRTC/I420Converter.h +22 -0
- package/ios/RCTWebRTC/I420Converter.m +164 -0
- package/ios/RCTWebRTC/PIPController.h +24 -0
- package/ios/RCTWebRTC/PIPController.m +234 -0
- package/ios/RCTWebRTC/RCTConvert+WebRTC.h +16 -0
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +206 -0
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +10 -0
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +16 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.h +29 -0
- package/ios/RCTWebRTC/RTCVideoViewManager.m +411 -0
- package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -0
- package/ios/RCTWebRTC/SampleBufferVideoCallView.m +178 -0
- package/ios/RCTWebRTC/ScreenCaptureController.h +20 -0
- package/ios/RCTWebRTC/ScreenCaptureController.m +83 -0
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +7 -0
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +60 -0
- package/ios/RCTWebRTC/ScreenCapturer.h +19 -0
- package/ios/RCTWebRTC/ScreenCapturer.m +264 -0
- package/ios/RCTWebRTC/SerializeUtils.h +28 -0
- package/ios/RCTWebRTC/SerializeUtils.m +314 -0
- package/ios/RCTWebRTC/SocketConnection.h +13 -0
- package/ios/RCTWebRTC/SocketConnection.m +137 -0
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -0
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +37 -0
- package/ios/RCTWebRTC/VideoCaptureController.h +21 -0
- package/ios/RCTWebRTC/VideoCaptureController.m +328 -0
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +75 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +14 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +165 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCFrameCryptor.m +611 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +14 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +545 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +24 -0
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +1004 -0
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +267 -0
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +12 -0
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +166 -0
- package/ios/RCTWebRTC/WebRTCModule.h +45 -0
- package/ios/RCTWebRTC/WebRTCModule.m +149 -0
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +24 -0
- package/ios/RCTWebRTC/WebRTCModuleOptions.m +31 -0
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -0
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -0
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -0
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -0
- package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -0
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +404 -0
- package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -0
- package/lib/commonjs/Constraints.js +2 -0
- package/lib/commonjs/Constraints.js.map +1 -0
- package/lib/commonjs/EventEmitter.js +69 -0
- package/lib/commonjs/EventEmitter.js.map +1 -0
- package/lib/commonjs/Logger.js +47 -0
- package/lib/commonjs/Logger.js.map +1 -0
- package/lib/commonjs/MediaDevices.js +54 -0
- package/lib/commonjs/MediaDevices.js.map +1 -0
- package/lib/commonjs/MediaStream.js +137 -0
- package/lib/commonjs/MediaStream.js.map +1 -0
- package/lib/commonjs/MediaStreamError.js +19 -0
- package/lib/commonjs/MediaStreamError.js.map +1 -0
- package/lib/commonjs/MediaStreamErrorEvent.js +17 -0
- package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -0
- package/lib/commonjs/MediaStreamTrack.js +239 -0
- package/lib/commonjs/MediaStreamTrack.js.map +1 -0
- package/lib/commonjs/MediaStreamTrackEvent.js +26 -0
- package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -0
- package/lib/commonjs/MessageEvent.js +27 -0
- package/lib/commonjs/MessageEvent.js.map +1 -0
- package/lib/commonjs/Permissions.js +116 -0
- package/lib/commonjs/Permissions.js.map +1 -0
- package/lib/commonjs/RTCAudioSession.js +33 -0
- package/lib/commonjs/RTCAudioSession.js.map +1 -0
- package/lib/commonjs/RTCDataChannel.js +165 -0
- package/lib/commonjs/RTCDataChannel.js.map +1 -0
- package/lib/commonjs/RTCDataChannelEvent.js +26 -0
- package/lib/commonjs/RTCDataChannelEvent.js.map +1 -0
- package/lib/commonjs/RTCDataPacketCryptor.js +76 -0
- package/lib/commonjs/RTCDataPacketCryptor.js.map +1 -0
- package/lib/commonjs/RTCDataPacketCryptorFactory.js +27 -0
- package/lib/commonjs/RTCDataPacketCryptorFactory.js.map +1 -0
- package/lib/commonjs/RTCErrorEvent.js +23 -0
- package/lib/commonjs/RTCErrorEvent.js.map +1 -0
- package/lib/commonjs/RTCFrameCryptor.js +138 -0
- package/lib/commonjs/RTCFrameCryptor.js.map +1 -0
- package/lib/commonjs/RTCFrameCryptorFactory.js +81 -0
- package/lib/commonjs/RTCFrameCryptorFactory.js.map +1 -0
- package/lib/commonjs/RTCIceCandidate.js +34 -0
- package/lib/commonjs/RTCIceCandidate.js.map +1 -0
- package/lib/commonjs/RTCIceCandidateEvent.js +28 -0
- package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -0
- package/lib/commonjs/RTCKeyProvider.js +111 -0
- package/lib/commonjs/RTCKeyProvider.js.map +1 -0
- package/lib/commonjs/RTCPIPView.js +38 -0
- package/lib/commonjs/RTCPIPView.js.map +1 -0
- package/lib/commonjs/RTCPeerConnection.js +694 -0
- package/lib/commonjs/RTCPeerConnection.js.map +1 -0
- package/lib/commonjs/RTCRtcpParameters.js +24 -0
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpCapabilities.js +22 -0
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecCapability.js +19 -0
- package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -0
- package/lib/commonjs/RTCRtpCodecParameters.js +38 -0
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js +78 -0
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js +27 -0
- package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/commonjs/RTCRtpParameters.js +35 -0
- package/lib/commonjs/RTCRtpParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js +15 -0
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpReceiver.js +53 -0
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -0
- package/lib/commonjs/RTCRtpSendParameters.js +49 -0
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -0
- package/lib/commonjs/RTCRtpSender.js +67 -0
- package/lib/commonjs/RTCRtpSender.js.map +1 -0
- package/lib/commonjs/RTCRtpTransceiver.js +81 -0
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -0
- package/lib/commonjs/RTCSessionDescription.js +33 -0
- package/lib/commonjs/RTCSessionDescription.js.map +1 -0
- package/lib/commonjs/RTCTrackEvent.js +38 -0
- package/lib/commonjs/RTCTrackEvent.js.map +1 -0
- package/lib/commonjs/RTCUtil.js +186 -0
- package/lib/commonjs/RTCUtil.js.map +1 -0
- package/lib/commonjs/RTCView.js +16 -0
- package/lib/commonjs/RTCView.js.map +1 -0
- package/lib/commonjs/ScreenCapturePickerView.js +10 -0
- package/lib/commonjs/ScreenCapturePickerView.js.map +1 -0
- package/lib/commonjs/getDisplayMedia.js +33 -0
- package/lib/commonjs/getDisplayMedia.js.map +1 -0
- package/lib/commonjs/getUserMedia.js +101 -0
- package/lib/commonjs/getUserMedia.js.map +1 -0
- package/lib/commonjs/index.js +224 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/Constraints.js +2 -0
- package/lib/module/Constraints.js.map +1 -0
- package/lib/module/EventEmitter.js +58 -0
- package/lib/module/EventEmitter.js.map +1 -0
- package/lib/module/Logger.js +39 -0
- package/lib/module/Logger.js.map +1 -0
- package/lib/module/MediaDevices.js +46 -0
- package/lib/module/MediaDevices.js.map +1 -0
- package/lib/module/MediaStream.js +129 -0
- package/lib/module/MediaStream.js.map +1 -0
- package/lib/module/MediaStreamError.js +12 -0
- package/lib/module/MediaStreamError.js.map +1 -0
- package/lib/module/MediaStreamErrorEvent.js +10 -0
- package/lib/module/MediaStreamErrorEvent.js.map +1 -0
- package/lib/module/MediaStreamTrack.js +231 -0
- package/lib/module/MediaStreamTrack.js.map +1 -0
- package/lib/module/MediaStreamTrackEvent.js +19 -0
- package/lib/module/MediaStreamTrackEvent.js.map +1 -0
- package/lib/module/MessageEvent.js +20 -0
- package/lib/module/MessageEvent.js.map +1 -0
- package/lib/module/Permissions.js +109 -0
- package/lib/module/Permissions.js.map +1 -0
- package/lib/module/RTCAudioSession.js +26 -0
- package/lib/module/RTCAudioSession.js.map +1 -0
- package/lib/module/RTCDataChannel.js +155 -0
- package/lib/module/RTCDataChannel.js.map +1 -0
- package/lib/module/RTCDataChannelEvent.js +19 -0
- package/lib/module/RTCDataChannelEvent.js.map +1 -0
- package/lib/module/RTCDataPacketCryptor.js +66 -0
- package/lib/module/RTCDataPacketCryptor.js.map +1 -0
- package/lib/module/RTCDataPacketCryptorFactory.js +19 -0
- package/lib/module/RTCDataPacketCryptorFactory.js.map +1 -0
- package/lib/module/RTCErrorEvent.js +16 -0
- package/lib/module/RTCErrorEvent.js.map +1 -0
- package/lib/module/RTCFrameCryptor.js +128 -0
- package/lib/module/RTCFrameCryptor.js.map +1 -0
- package/lib/module/RTCFrameCryptorFactory.js +70 -0
- package/lib/module/RTCFrameCryptorFactory.js.map +1 -0
- package/lib/module/RTCIceCandidate.js +27 -0
- package/lib/module/RTCIceCandidate.js.map +1 -0
- package/lib/module/RTCIceCandidateEvent.js +21 -0
- package/lib/module/RTCIceCandidateEvent.js.map +1 -0
- package/lib/module/RTCKeyProvider.js +101 -0
- package/lib/module/RTCKeyProvider.js.map +1 -0
- package/lib/module/RTCPIPView.js +26 -0
- package/lib/module/RTCPIPView.js.map +1 -0
- package/lib/module/RTCPeerConnection.js +684 -0
- package/lib/module/RTCPeerConnection.js.map +1 -0
- package/lib/module/RTCRtcpParameters.js +17 -0
- package/lib/module/RTCRtcpParameters.js.map +1 -0
- package/lib/module/RTCRtpCapabilities.js +15 -0
- package/lib/module/RTCRtpCapabilities.js.map +1 -0
- package/lib/module/RTCRtpCodecCapability.js +12 -0
- package/lib/module/RTCRtpCodecCapability.js.map +1 -0
- package/lib/module/RTCRtpCodecParameters.js +31 -0
- package/lib/module/RTCRtpCodecParameters.js.map +1 -0
- package/lib/module/RTCRtpEncodingParameters.js +71 -0
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -0
- package/lib/module/RTCRtpHeaderExtension.js +20 -0
- package/lib/module/RTCRtpHeaderExtension.js.map +1 -0
- package/lib/module/RTCRtpParameters.js +27 -0
- package/lib/module/RTCRtpParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiveParameters.js +7 -0
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -0
- package/lib/module/RTCRtpReceiver.js +45 -0
- package/lib/module/RTCRtpReceiver.js.map +1 -0
- package/lib/module/RTCRtpSendParameters.js +41 -0
- package/lib/module/RTCRtpSendParameters.js.map +1 -0
- package/lib/module/RTCRtpSender.js +59 -0
- package/lib/module/RTCRtpSender.js.map +1 -0
- package/lib/module/RTCRtpTransceiver.js +74 -0
- package/lib/module/RTCRtpTransceiver.js.map +1 -0
- package/lib/module/RTCSessionDescription.js +26 -0
- package/lib/module/RTCSessionDescription.js.map +1 -0
- package/lib/module/RTCTrackEvent.js +31 -0
- package/lib/module/RTCTrackEvent.js.map +1 -0
- package/lib/module/RTCUtil.js +176 -0
- package/lib/module/RTCUtil.js.map +1 -0
- package/lib/module/RTCView.js +11 -0
- package/lib/module/RTCView.js.map +1 -0
- package/lib/module/ScreenCapturePickerView.js +3 -0
- package/lib/module/ScreenCapturePickerView.js.map +1 -0
- package/lib/module/getDisplayMedia.js +26 -0
- package/lib/module/getDisplayMedia.js.map +1 -0
- package/lib/module/getUserMedia.js +92 -0
- package/lib/module/getUserMedia.js.map +1 -0
- package/lib/module/index.js +60 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/Constraints.d.ts +19 -0
- package/lib/typescript/EventEmitter.d.ts +7 -0
- package/lib/typescript/Logger.d.ts +13 -0
- package/lib/typescript/MediaDevices.d.ts +30 -0
- package/lib/typescript/MediaStream.d.ts +48 -0
- package/lib/typescript/MediaStreamError.d.ts +6 -0
- package/lib/typescript/MediaStreamErrorEvent.d.ts +6 -0
- package/lib/typescript/MediaStreamTrack.d.ts +103 -0
- package/lib/typescript/MediaStreamTrackEvent.d.ts +19 -0
- package/lib/typescript/MessageEvent.d.ts +21 -0
- package/lib/typescript/Permissions.d.ts +55 -0
- package/lib/typescript/RTCAudioSession.d.ts +10 -0
- package/lib/typescript/RTCDataChannel.d.ts +43 -0
- package/lib/typescript/RTCDataChannelEvent.d.ts +19 -0
- package/lib/typescript/RTCDataPacketCryptor.d.ts +12 -0
- package/lib/typescript/RTCDataPacketCryptorFactory.d.ts +6 -0
- package/lib/typescript/RTCErrorEvent.d.ts +12 -0
- package/lib/typescript/RTCFrameCryptor.d.ts +47 -0
- package/lib/typescript/RTCFrameCryptorFactory.d.ts +21 -0
- package/lib/typescript/RTCIceCandidate.d.ts +17 -0
- package/lib/typescript/RTCIceCandidateEvent.d.ts +20 -0
- package/lib/typescript/RTCKeyProvider.d.ts +21 -0
- package/lib/typescript/RTCPIPView.d.ts +15 -0
- package/lib/typescript/RTCPeerConnection.d.ts +117 -0
- package/lib/typescript/RTCRtcpParameters.d.ts +10 -0
- package/lib/typescript/RTCRtpCapabilities.d.ts +9 -0
- package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -0
- package/lib/typescript/RTCRtpCodecParameters.d.ts +16 -0
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +23 -0
- package/lib/typescript/RTCRtpHeaderExtension.d.ts +12 -0
- package/lib/typescript/RTCRtpParameters.d.ts +19 -0
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -0
- package/lib/typescript/RTCRtpReceiver.d.ts +21 -0
- package/lib/typescript/RTCRtpSendParameters.d.ts +20 -0
- package/lib/typescript/RTCRtpSender.d.ts +22 -0
- package/lib/typescript/RTCRtpTransceiver.d.ts +31 -0
- package/lib/typescript/RTCSessionDescription.d.ts +12 -0
- package/lib/typescript/RTCTrackEvent.d.ts +29 -0
- package/lib/typescript/RTCUtil.d.ts +37 -0
- package/lib/typescript/RTCView.d.ts +117 -0
- package/lib/typescript/ScreenCapturePickerView.d.ts +2 -0
- package/lib/typescript/getDisplayMedia.d.ts +2 -0
- package/lib/typescript/getUserMedia.d.ts +7 -0
- package/lib/typescript/index.d.ts +22 -0
- package/livekit-react-native-webrtc.podspec +29 -0
- package/macos/RCTWebRTC.xcodeproj/project.pbxproj +324 -0
- package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/metro.config.js +7 -0
- package/metro.config.macos.js +14 -0
- package/package.json +65 -0
- package/react-native.config.js +11 -0
- package/src/.eslintrc.cjs +67 -0
- package/src/Constraints.ts +21 -0
- package/src/EventEmitter.ts +83 -0
- package/src/Logger.ts +49 -0
- package/src/MediaDevices.ts +53 -0
- package/src/MediaStream.ts +161 -0
- package/src/MediaStreamError.ts +12 -0
- package/src/MediaStreamErrorEvent.ts +11 -0
- package/src/MediaStreamTrack.ts +331 -0
- package/src/MediaStreamTrackEvent.ts +25 -0
- package/src/MessageEvent.ts +26 -0
- package/src/Permissions.ts +133 -0
- package/src/RTCAudioSession.ts +25 -0
- package/src/RTCDataChannel.ts +190 -0
- package/src/RTCDataChannelEvent.ts +28 -0
- package/src/RTCDataPacketCryptor.ts +90 -0
- package/src/RTCDataPacketCryptorFactory.ts +25 -0
- package/src/RTCErrorEvent.ts +21 -0
- package/src/RTCFrameCryptor.ts +163 -0
- package/src/RTCFrameCryptorFactory.ts +102 -0
- package/src/RTCIceCandidate.ts +29 -0
- package/src/RTCIceCandidateEvent.ts +26 -0
- package/src/RTCKeyProvider.ts +117 -0
- package/src/RTCPIPView.tsx +47 -0
- package/src/RTCPeerConnection.ts +832 -0
- package/src/RTCRtcpParameters.ts +23 -0
- package/src/RTCRtpCapabilities.ts +16 -0
- package/src/RTCRtpCodecCapability.ts +13 -0
- package/src/RTCRtpCodecParameters.ts +44 -0
- package/src/RTCRtpEncodingParameters.ts +90 -0
- package/src/RTCRtpHeaderExtension.ts +27 -0
- package/src/RTCRtpParameters.ts +37 -0
- package/src/RTCRtpReceiveParameters.ts +7 -0
- package/src/RTCRtpReceiver.ts +60 -0
- package/src/RTCRtpSendParameters.ts +63 -0
- package/src/RTCRtpSender.ts +78 -0
- package/src/RTCRtpTransceiver.ts +107 -0
- package/src/RTCSessionDescription.ts +30 -0
- package/src/RTCTrackEvent.ts +42 -0
- package/src/RTCUtil.ts +211 -0
- package/src/RTCView.ts +122 -0
- package/src/ScreenCapturePickerView.ts +4 -0
- package/src/getDisplayMedia.ts +30 -0
- package/src/getUserMedia.ts +111 -0
- package/src/index.ts +101 -0
- package/tools/format.sh +6 -0
- package/tools/release.sh +45 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
#if !TARGET_OS_TV
|
|
2
|
+
|
|
3
|
+
#import "VideoCaptureController.h"
|
|
4
|
+
|
|
5
|
+
#import <React/RCTLog.h>
|
|
6
|
+
|
|
7
|
+
@interface VideoCaptureController ()
|
|
8
|
+
|
|
9
|
+
@property(nonatomic, strong) RTCCameraVideoCapturer *capturer;
|
|
10
|
+
@property(nonatomic, strong) AVCaptureDeviceFormat *selectedFormat;
|
|
11
|
+
@property(nonatomic, strong) AVCaptureDevice *device;
|
|
12
|
+
@property(nonatomic, assign) BOOL running;
|
|
13
|
+
@property(nonatomic, assign) BOOL usingFrontCamera;
|
|
14
|
+
@property(nonatomic, assign) int width;
|
|
15
|
+
@property(nonatomic, assign) int height;
|
|
16
|
+
@property(nonatomic, assign) int frameRate;
|
|
17
|
+
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@implementation VideoCaptureController
|
|
21
|
+
|
|
22
|
+
- (instancetype)initWithCapturer:(RTCCameraVideoCapturer *)capturer andConstraints:(NSDictionary *)constraints {
|
|
23
|
+
self = [super init];
|
|
24
|
+
if (self) {
|
|
25
|
+
self.capturer = capturer;
|
|
26
|
+
self.running = NO;
|
|
27
|
+
[self determineDevice:constraints];
|
|
28
|
+
[self applyConstraints:constraints error:nil];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return self;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (void)dealloc {
|
|
35
|
+
self.device = NULL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)startCapture {
|
|
39
|
+
if (self.deviceId) {
|
|
40
|
+
self.device = [AVCaptureDevice deviceWithUniqueID:self.deviceId];
|
|
41
|
+
}
|
|
42
|
+
if (!self.device) {
|
|
43
|
+
AVCaptureDevicePosition position =
|
|
44
|
+
self.usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
|
|
45
|
+
self.device = [self findDeviceForPosition:position];
|
|
46
|
+
self.deviceId = self.device.uniqueID;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!self.device) {
|
|
50
|
+
RCTLogWarn(@"[VideoCaptureController] No capture devices found!");
|
|
51
|
+
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
AVCaptureDeviceFormat *format = [self selectFormatForDevice:self.device
|
|
56
|
+
withTargetWidth:self.width
|
|
57
|
+
withTargetHeight:self.height];
|
|
58
|
+
if (!format) {
|
|
59
|
+
RCTLogWarn(@"[VideoCaptureController] No valid formats for device %@", self.device);
|
|
60
|
+
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
self.selectedFormat = format;
|
|
65
|
+
|
|
66
|
+
AVCaptureSession *session = self.capturer.captureSession;
|
|
67
|
+
if (@available(iOS 16.0, *)) {
|
|
68
|
+
BOOL enable = self.enableMultitaskingCameraAccess;
|
|
69
|
+
BOOL shouldChange = session.multitaskingCameraAccessEnabled != enable;
|
|
70
|
+
BOOL canChange = !enable || (enable && session.isMultitaskingCameraAccessSupported);
|
|
71
|
+
|
|
72
|
+
if (shouldChange && canChange) {
|
|
73
|
+
[session beginConfiguration];
|
|
74
|
+
[session setMultitaskingCameraAccessEnabled:enable];
|
|
75
|
+
[session commitConfiguration];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
RCTLog(@"[VideoCaptureController] Capture will start");
|
|
80
|
+
|
|
81
|
+
// Starting the capture happens on another thread. Wait for it.
|
|
82
|
+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
|
83
|
+
|
|
84
|
+
__weak VideoCaptureController *weakSelf = self;
|
|
85
|
+
[self.capturer startCaptureWithDevice:self.device
|
|
86
|
+
format:format
|
|
87
|
+
fps:self.frameRate
|
|
88
|
+
completionHandler:^(NSError *err) {
|
|
89
|
+
if (err) {
|
|
90
|
+
RCTLogError(@"[VideoCaptureController] Error starting capture: %@", err);
|
|
91
|
+
} else {
|
|
92
|
+
RCTLog(@"[VideoCaptureController] Capture started");
|
|
93
|
+
weakSelf.running = YES;
|
|
94
|
+
}
|
|
95
|
+
dispatch_semaphore_signal(semaphore);
|
|
96
|
+
}];
|
|
97
|
+
|
|
98
|
+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
- (void)stopCapture {
|
|
102
|
+
if (!self.running)
|
|
103
|
+
return;
|
|
104
|
+
|
|
105
|
+
RCTLog(@"[VideoCaptureController] Capture will stop");
|
|
106
|
+
// Stopping the capture happens on another thread. Wait for it.
|
|
107
|
+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
|
108
|
+
|
|
109
|
+
__weak VideoCaptureController *weakSelf = self;
|
|
110
|
+
[self.capturer stopCaptureWithCompletionHandler:^{
|
|
111
|
+
RCTLog(@"[VideoCaptureController] Capture stopped");
|
|
112
|
+
weakSelf.running = NO;
|
|
113
|
+
weakSelf.device = nil;
|
|
114
|
+
|
|
115
|
+
dispatch_semaphore_signal(semaphore);
|
|
116
|
+
}];
|
|
117
|
+
|
|
118
|
+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
- (void)determineDevice:(NSDictionary *)constraints {
|
|
122
|
+
// Clear device to prepare for starting camera with new constraints.
|
|
123
|
+
self.device = nil;
|
|
124
|
+
NSString *deviceId = constraints[@"deviceId"];
|
|
125
|
+
id facingMode = constraints[@"facingMode"];
|
|
126
|
+
|
|
127
|
+
if (!facingMode && !deviceId) {
|
|
128
|
+
// Default to front camera.
|
|
129
|
+
facingMode = @"user";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (facingMode && [facingMode isKindOfClass:[NSString class]]) {
|
|
133
|
+
AVCaptureDevicePosition position;
|
|
134
|
+
if ([facingMode isEqualToString:@"environment"]) {
|
|
135
|
+
position = AVCaptureDevicePositionBack;
|
|
136
|
+
} else if ([facingMode isEqualToString:@"user"]) {
|
|
137
|
+
position = AVCaptureDevicePositionFront;
|
|
138
|
+
} else {
|
|
139
|
+
// If the specified facingMode value is not supported, fall back
|
|
140
|
+
// to the front camera.
|
|
141
|
+
position = AVCaptureDevicePositionFront;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
BOOL usingFrontCamera = position == AVCaptureDevicePositionFront;
|
|
145
|
+
if (self.usingFrontCamera != usingFrontCamera) {
|
|
146
|
+
self.usingFrontCamera = usingFrontCamera;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (!deviceId) {
|
|
151
|
+
AVCaptureDevicePosition position =
|
|
152
|
+
self.usingFrontCamera ? AVCaptureDevicePositionFront : AVCaptureDevicePositionBack;
|
|
153
|
+
deviceId = [self findDeviceForPosition:position].uniqueID;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (self.deviceId != deviceId && ![self.deviceId isEqualToString:deviceId]) {
|
|
157
|
+
self.deviceId = deviceId;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
- (void)applyConstraints:(NSDictionary *)constraints error:(NSError **)outError {
|
|
162
|
+
BOOL hasChanged = NO;
|
|
163
|
+
|
|
164
|
+
int width = [constraints[@"width"] intValue];
|
|
165
|
+
int height = [constraints[@"height"] intValue];
|
|
166
|
+
int frameRate = [constraints[@"frameRate"] intValue];
|
|
167
|
+
|
|
168
|
+
if (self.width != width) {
|
|
169
|
+
hasChanged = YES;
|
|
170
|
+
self.width = width;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (self.height != height) {
|
|
174
|
+
hasChanged = YES;
|
|
175
|
+
self.height = height;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (self.frameRate != frameRate) {
|
|
179
|
+
hasChanged = YES;
|
|
180
|
+
self.frameRate = frameRate;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (self.running && hasChanged) {
|
|
184
|
+
[self stopCapture];
|
|
185
|
+
[self startCapture];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
- (NSDictionary *)getSettings {
|
|
190
|
+
AVCaptureDeviceFormat *format = self.selectedFormat;
|
|
191
|
+
CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
|
|
192
|
+
NSMutableDictionary *settings = [[NSMutableDictionary alloc] initWithDictionary:@{
|
|
193
|
+
@"groupId" : @"",
|
|
194
|
+
@"height" : @(dimensions.height),
|
|
195
|
+
@"width" : @(dimensions.width),
|
|
196
|
+
@"frameRate" : @(30),
|
|
197
|
+
@"facingMode" : self.usingFrontCamera ? @"user" : @"environment"
|
|
198
|
+
}];
|
|
199
|
+
|
|
200
|
+
if (self.deviceId) {
|
|
201
|
+
settings[@"deviceId"] = self.deviceId;
|
|
202
|
+
}
|
|
203
|
+
return settings;
|
|
204
|
+
}
|
|
205
|
+
#pragma mark NSKeyValueObserving
|
|
206
|
+
|
|
207
|
+
- (void)observeValueForKeyPath:(NSString *)keyPath
|
|
208
|
+
ofObject:(id)object
|
|
209
|
+
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
|
210
|
+
context:(void *)context {
|
|
211
|
+
if (@available(iOS 11.1, *)) {
|
|
212
|
+
if ([object isKindOfClass:[AVCaptureDevice class]] && [keyPath isEqualToString:@"systemPressureState"]) {
|
|
213
|
+
AVCaptureDevice *device = (AVCaptureDevice *)object;
|
|
214
|
+
AVCaptureSystemPressureLevel pressureLevel =
|
|
215
|
+
((AVCaptureSystemPressureState *)change[NSKeyValueChangeNewKey]).level;
|
|
216
|
+
if (pressureLevel == AVCaptureSystemPressureLevelSerious ||
|
|
217
|
+
pressureLevel == AVCaptureSystemPressureLevelCritical) {
|
|
218
|
+
RCTLogWarn(
|
|
219
|
+
@"[VideoCaptureController] Reached elevated system pressure level: %@. Throttling frame rate.",
|
|
220
|
+
pressureLevel);
|
|
221
|
+
[self throttleFrameRateForDevice:device];
|
|
222
|
+
} else if (pressureLevel == AVCaptureSystemPressureLevelNominal) {
|
|
223
|
+
RCTLogWarn(@"[VideoCaptureController] Restored normal system pressure level. Resetting frame rate to "
|
|
224
|
+
@"default.");
|
|
225
|
+
[self resetFrameRateForDevice:device];
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
- (void)registerSystemPressureStateObserverForDevice:(AVCaptureDevice *)device {
|
|
232
|
+
if (@available(iOS 11.1, *)) {
|
|
233
|
+
[device addObserver:self forKeyPath:@"systemPressureState" options:NSKeyValueObservingOptionNew context:nil];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
- (void)removeObserverForDevice:(AVCaptureDevice *)device {
|
|
238
|
+
if (@available(iOS 11.1, *)) {
|
|
239
|
+
[device removeObserver:self forKeyPath:@"systemPressureState"];
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
#pragma mark Private
|
|
244
|
+
|
|
245
|
+
- (void)setDevice:(AVCaptureDevice *)device {
|
|
246
|
+
if (_device) {
|
|
247
|
+
[self removeObserverForDevice:_device];
|
|
248
|
+
}
|
|
249
|
+
if (device) {
|
|
250
|
+
[self registerSystemPressureStateObserverForDevice:device];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
_device = device;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
- (AVCaptureDevice *)findDeviceForPosition:(AVCaptureDevicePosition)position {
|
|
257
|
+
NSArray<AVCaptureDevice *> *captureDevices = [RTCCameraVideoCapturer captureDevices];
|
|
258
|
+
for (AVCaptureDevice *device in captureDevices) {
|
|
259
|
+
if (device.position == position) {
|
|
260
|
+
return device;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return [captureDevices firstObject];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
- (AVCaptureDeviceFormat *)selectFormatForDevice:(AVCaptureDevice *)device
|
|
268
|
+
withTargetWidth:(int)targetWidth
|
|
269
|
+
withTargetHeight:(int)targetHeight {
|
|
270
|
+
NSArray<AVCaptureDeviceFormat *> *formats = [RTCCameraVideoCapturer supportedFormatsForDevice:device];
|
|
271
|
+
AVCaptureDeviceFormat *selectedFormat = nil;
|
|
272
|
+
int currentDiff = INT_MAX;
|
|
273
|
+
|
|
274
|
+
for (AVCaptureDeviceFormat *format in formats) {
|
|
275
|
+
// Only use multi cam formats when on multi cam supported devices.
|
|
276
|
+
if (@available(iOS 13.0, macOS 14.0, tvOS 17.0, *)) {
|
|
277
|
+
if (AVCaptureMultiCamSession.multiCamSupported && !format.multiCamSupported) {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
CMVideoDimensions dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription);
|
|
283
|
+
FourCharCode pixelFormat = CMFormatDescriptionGetMediaSubType(format.formatDescription);
|
|
284
|
+
int diff = abs(targetWidth - dimension.width) + abs(targetHeight - dimension.height);
|
|
285
|
+
if (diff < currentDiff) {
|
|
286
|
+
selectedFormat = format;
|
|
287
|
+
currentDiff = diff;
|
|
288
|
+
} else if (diff == currentDiff && pixelFormat == [_capturer preferredOutputPixelFormat]) {
|
|
289
|
+
selectedFormat = format;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return selectedFormat;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
- (void)throttleFrameRateForDevice:(AVCaptureDevice *)device {
|
|
297
|
+
NSError *error = nil;
|
|
298
|
+
|
|
299
|
+
[device lockForConfiguration:&error];
|
|
300
|
+
if (error) {
|
|
301
|
+
RCTLog(@"[VideoCaptureController] Could not lock device for configuration: %@", error);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
device.activeVideoMinFrameDuration = CMTimeMake(1, 20);
|
|
306
|
+
device.activeVideoMaxFrameDuration = CMTimeMake(1, 15);
|
|
307
|
+
|
|
308
|
+
[device unlockForConfiguration];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
- (void)resetFrameRateForDevice:(AVCaptureDevice *)device {
|
|
312
|
+
NSError *error = nil;
|
|
313
|
+
|
|
314
|
+
[device lockForConfiguration:&error];
|
|
315
|
+
if (error) {
|
|
316
|
+
RCTLog(@"[VideoCaptureController] Could not lock device for configuration: %@", error);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
device.activeVideoMinFrameDuration = kCMTimeInvalid;
|
|
321
|
+
device.activeVideoMaxFrameDuration = kCMTimeInvalid;
|
|
322
|
+
|
|
323
|
+
[device unlockForConfiguration];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
@end
|
|
327
|
+
|
|
328
|
+
#endif
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
#import <AVFoundation/AVFoundation.h>
|
|
3
|
+
|
|
4
|
+
#import "WebRTCModule.h"
|
|
5
|
+
|
|
6
|
+
static NSString *const PERMISSION_DENIED = @"denied";
|
|
7
|
+
static NSString *const PERMISSION_GRANTED = @"granted";
|
|
8
|
+
static NSString *const PERMISSION_PROMPT = @"prompt";
|
|
9
|
+
|
|
10
|
+
@implementation WebRTCModule (Permissions)
|
|
11
|
+
|
|
12
|
+
- (AVMediaType)avMediaType:(NSString *)mediaType {
|
|
13
|
+
if ([mediaType isEqualToString:@"microphone"]) {
|
|
14
|
+
return AVMediaTypeAudio;
|
|
15
|
+
} else if ([mediaType isEqualToString:@"camera"]) {
|
|
16
|
+
return AVMediaTypeVideo;
|
|
17
|
+
} else {
|
|
18
|
+
return nil;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
RCT_EXPORT_METHOD(checkPermission
|
|
23
|
+
: (NSString *)mediaType resolver
|
|
24
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
25
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
26
|
+
#if TARGET_OS_TV
|
|
27
|
+
resolve(@"tvOS is not supported");
|
|
28
|
+
return;
|
|
29
|
+
#else
|
|
30
|
+
AVMediaType mediaType_ = [self avMediaType:mediaType];
|
|
31
|
+
|
|
32
|
+
if (mediaType_ == nil) {
|
|
33
|
+
reject(@"invalid_type", @"Invalid media type", nil);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:mediaType_];
|
|
37
|
+
switch (status) {
|
|
38
|
+
case AVAuthorizationStatusAuthorized:
|
|
39
|
+
resolve(PERMISSION_GRANTED);
|
|
40
|
+
break;
|
|
41
|
+
|
|
42
|
+
case AVAuthorizationStatusNotDetermined:
|
|
43
|
+
resolve(PERMISSION_PROMPT);
|
|
44
|
+
break;
|
|
45
|
+
|
|
46
|
+
default:
|
|
47
|
+
resolve(PERMISSION_DENIED);
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
#endif
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
RCT_EXPORT_METHOD(requestPermission
|
|
54
|
+
: (NSString *)mediaType resolver
|
|
55
|
+
: (RCTPromiseResolveBlock)resolve rejecter
|
|
56
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
57
|
+
#if TARGET_OS_TV
|
|
58
|
+
resolve(@"tvOS is not supported");
|
|
59
|
+
return;
|
|
60
|
+
#else
|
|
61
|
+
AVMediaType mediaType_ = [self avMediaType:mediaType];
|
|
62
|
+
|
|
63
|
+
if (mediaType_ == nil) {
|
|
64
|
+
reject(@"invalid_type", @"Invalid media type", nil);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
[AVCaptureDevice requestAccessForMediaType:mediaType_
|
|
69
|
+
completionHandler:^(BOOL granted) {
|
|
70
|
+
resolve(@(granted));
|
|
71
|
+
}];
|
|
72
|
+
#endif
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#import <objc/runtime.h>
|
|
2
|
+
|
|
3
|
+
#import <React/RCTBridge.h>
|
|
4
|
+
#import <React/RCTBridgeModule.h>
|
|
5
|
+
|
|
6
|
+
#import "WebRTCModule.h"
|
|
7
|
+
|
|
8
|
+
@implementation WebRTCModule (RTCAudioSession)
|
|
9
|
+
|
|
10
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidActivate) {
|
|
11
|
+
[[RTCAudioSession sharedInstance] audioSessionDidActivate:[AVAudioSession sharedInstance]];
|
|
12
|
+
return nil;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(audioSessionDidDeactivate) {
|
|
16
|
+
[[RTCAudioSession sharedInstance] audioSessionDidDeactivate:[AVAudioSession sharedInstance]];
|
|
17
|
+
return nil;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#import "DataChannelWrapper.h"
|
|
2
|
+
#import "WebRTCModule.h"
|
|
3
|
+
|
|
4
|
+
@interface RTCDataChannel (React)
|
|
5
|
+
|
|
6
|
+
@property(nonatomic, strong) NSNumber *peerConnectionId;
|
|
7
|
+
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@interface WebRTCModule (RTCDataChannel)<DataChannelWrapperDelegate>
|
|
11
|
+
|
|
12
|
+
- (NSString *)stringForDataChannelState:(RTCDataChannelState)state;
|
|
13
|
+
|
|
14
|
+
@end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#import <objc/runtime.h>
|
|
2
|
+
|
|
3
|
+
#import <React/RCTBridge.h>
|
|
4
|
+
#import <React/RCTBridgeModule.h>
|
|
5
|
+
#import <React/RCTEventDispatcher.h>
|
|
6
|
+
|
|
7
|
+
#import <WebRTC/RTCDataChannelConfiguration.h>
|
|
8
|
+
#import "WebRTCModule+RTCDataChannel.h"
|
|
9
|
+
#import "WebRTCModule+RTCPeerConnection.h"
|
|
10
|
+
|
|
11
|
+
@implementation WebRTCModule (RTCDataChannel)
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Thuis methos is implemented synchronously since we need to create the DataChannel on the spot
|
|
15
|
+
* and where is no good way to report an error at creation time.
|
|
16
|
+
*/
|
|
17
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createDataChannel
|
|
18
|
+
: (nonnull NSNumber *)peerConnectionId label
|
|
19
|
+
: (NSString *)label config
|
|
20
|
+
: (RTCDataChannelConfiguration *)config) {
|
|
21
|
+
__block id channelInfo;
|
|
22
|
+
|
|
23
|
+
dispatch_sync(self.workerQueue, ^{
|
|
24
|
+
RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
|
|
25
|
+
|
|
26
|
+
if (peerConnection == nil) {
|
|
27
|
+
RCTLogWarn(@"PeerConnection %@ not found", peerConnectionId);
|
|
28
|
+
channelInfo = nil;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
RTCDataChannel *dataChannel = [peerConnection dataChannelForLabel:label configuration:config];
|
|
33
|
+
|
|
34
|
+
if (dataChannel == nil) {
|
|
35
|
+
channelInfo = nil;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
NSString *reactTag = [[NSUUID UUID] UUIDString];
|
|
40
|
+
DataChannelWrapper *dcw = [[DataChannelWrapper alloc] initWithChannel:dataChannel reactTag:reactTag];
|
|
41
|
+
dcw.pcId = peerConnectionId;
|
|
42
|
+
peerConnection.dataChannels[reactTag] = dcw;
|
|
43
|
+
dcw.delegate = self;
|
|
44
|
+
|
|
45
|
+
channelInfo = @{
|
|
46
|
+
@"peerConnectionId" : peerConnectionId,
|
|
47
|
+
@"reactTag" : reactTag,
|
|
48
|
+
@"label" : dataChannel.label,
|
|
49
|
+
@"id" : @(dataChannel.channelId),
|
|
50
|
+
@"ordered" : @(dataChannel.isOrdered),
|
|
51
|
+
@"maxPacketLifeTime" : @(dataChannel.maxPacketLifeTime),
|
|
52
|
+
@"maxRetransmits" : @(dataChannel.maxRetransmits),
|
|
53
|
+
@"protocol" : dataChannel.protocol,
|
|
54
|
+
@"negotiated" : @(dataChannel.isNegotiated),
|
|
55
|
+
@"readyState" : [self stringForDataChannelState:dataChannel.readyState]
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return channelInfo;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
RCT_EXPORT_METHOD(dataChannelClose
|
|
63
|
+
: (nonnull NSNumber *)peerConnectionId reactTag
|
|
64
|
+
: (nonnull NSString *)tag {
|
|
65
|
+
RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
|
|
66
|
+
DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
|
|
67
|
+
if (dcw) {
|
|
68
|
+
[dcw.channel close];
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
RCT_EXPORT_METHOD(dataChannelDispose
|
|
73
|
+
: (nonnull NSNumber *)peerConnectionId reactTag
|
|
74
|
+
: (nonnull NSString *)tag {
|
|
75
|
+
RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
|
|
76
|
+
DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
|
|
77
|
+
if (dcw) {
|
|
78
|
+
dcw.delegate = nil;
|
|
79
|
+
[peerConnection.dataChannels removeObjectForKey:tag];
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
RCT_EXPORT_METHOD(dataChannelSend
|
|
84
|
+
: (nonnull NSNumber *)peerConnectionId reactTag
|
|
85
|
+
: (nonnull NSString *)tag data
|
|
86
|
+
: (NSString *)data type
|
|
87
|
+
: (NSString *)type {
|
|
88
|
+
RTCPeerConnection *peerConnection = self.peerConnections[peerConnectionId];
|
|
89
|
+
DataChannelWrapper *dcw = peerConnection.dataChannels[tag];
|
|
90
|
+
if (dcw) {
|
|
91
|
+
BOOL isBinary = [type isEqualToString:@"binary"];
|
|
92
|
+
NSData *bytes = isBinary ? [[NSData alloc] initWithBase64EncodedString:data options:0]
|
|
93
|
+
: [data dataUsingEncoding:NSUTF8StringEncoding];
|
|
94
|
+
RTCDataBuffer *buffer = [[RTCDataBuffer alloc] initWithData:bytes isBinary:isBinary];
|
|
95
|
+
[dcw.channel sendData:buffer];
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
- (NSString *)stringForDataChannelState:(RTCDataChannelState)state {
|
|
100
|
+
switch (state) {
|
|
101
|
+
case RTCDataChannelStateConnecting:
|
|
102
|
+
return @"connecting";
|
|
103
|
+
case RTCDataChannelStateOpen:
|
|
104
|
+
return @"open";
|
|
105
|
+
case RTCDataChannelStateClosing:
|
|
106
|
+
return @"closing";
|
|
107
|
+
case RTCDataChannelStateClosed:
|
|
108
|
+
return @"closed";
|
|
109
|
+
}
|
|
110
|
+
return nil;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#pragma mark - DataChannelWrapperDelegate methods
|
|
114
|
+
|
|
115
|
+
// Called when the data channel state has changed.
|
|
116
|
+
- (void)dataChannelDidChangeState:(DataChannelWrapper *)dcw {
|
|
117
|
+
RTCDataChannel *channel = dcw.channel;
|
|
118
|
+
NSDictionary *event = @{
|
|
119
|
+
@"reactTag" : dcw.reactTag,
|
|
120
|
+
@"peerConnectionId" : dcw.pcId,
|
|
121
|
+
@"id" : @(channel.channelId),
|
|
122
|
+
@"state" : [self stringForDataChannelState:channel.readyState]
|
|
123
|
+
};
|
|
124
|
+
[self sendEventWithName:kEventDataChannelStateChanged body:event];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Called when a data buffer was successfully received.
|
|
128
|
+
- (void)dataChannel:(DataChannelWrapper *)dcw didReceiveMessageWithBuffer:(RTCDataBuffer *)buffer {
|
|
129
|
+
NSString *type;
|
|
130
|
+
NSString *data;
|
|
131
|
+
if (buffer.isBinary) {
|
|
132
|
+
type = @"binary";
|
|
133
|
+
data = [buffer.data base64EncodedStringWithOptions:0];
|
|
134
|
+
} else {
|
|
135
|
+
type = @"text";
|
|
136
|
+
// XXX NSData has a length property which means that, when it represents
|
|
137
|
+
// text, the value of its bytes property does not have to be terminated by
|
|
138
|
+
// null. In such a case, NSString's stringFromUTF8String may fail and return
|
|
139
|
+
// nil (which would crash the process when inserting data into NSDictionary
|
|
140
|
+
// without the nil protection implemented below).
|
|
141
|
+
data = [[NSString alloc] initWithData:buffer.data encoding:NSUTF8StringEncoding];
|
|
142
|
+
}
|
|
143
|
+
NSDictionary *event = @{
|
|
144
|
+
@"reactTag" : dcw.reactTag,
|
|
145
|
+
@"peerConnectionId" : dcw.pcId,
|
|
146
|
+
@"type" : type,
|
|
147
|
+
// XXX NSDictionary will crash the process upon
|
|
148
|
+
// attempting to insert nil. Such behavior is
|
|
149
|
+
// unacceptable given that protection in such a
|
|
150
|
+
// scenario is extremely simple.
|
|
151
|
+
@"data" : (data ? data : [NSNull null])
|
|
152
|
+
};
|
|
153
|
+
[self sendEventWithName:kEventDataChannelReceiveMessage body:event];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
- (void)dataChannel:(DataChannelWrapper *)dcw didChangeBufferedAmount:(uint64_t)amount {
|
|
157
|
+
NSDictionary *event = @{
|
|
158
|
+
@"reactTag" : dcw.reactTag,
|
|
159
|
+
@"peerConnectionId" : dcw.pcId,
|
|
160
|
+
@"bufferedAmount" : [NSNumber numberWithUnsignedLongLong:amount]
|
|
161
|
+
};
|
|
162
|
+
[self sendEventWithName:kEventDataChannelDidChangeBufferedAmount body:event];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@end
|