@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
package/.clang-format
ADDED
package/.eslintignore
ADDED
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
22
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
If you have any questions then please use our Community Discourse: https://react-native-webrtc.discourse.group/
|
|
3
|
+
Otherwise you are in the right place for reporting bugs.
|
|
4
|
+
|
|
5
|
+
Please include as much information as possible and make the issue title as descriptive as you can.
|
|
6
|
+
But most of all please take your time and explain to the best of your abilities.
|
|
7
|
+
|
|
8
|
+
Code samples can be very helpful but even more so if displayed correctly.
|
|
9
|
+
Here is an example of how you can use syntax highlighting.
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
|
|
13
|
+
console.log( 'Hello World' );
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
More info can be found over here.
|
|
18
|
+
https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting
|
|
19
|
+
-->
|
|
20
|
+
|
|
21
|
+
#### Expected Behavior:
|
|
22
|
+
<!--
|
|
23
|
+
Explain what you expect to happen.
|
|
24
|
+
-->
|
|
25
|
+
|
|
26
|
+
#### Observed Behavior:
|
|
27
|
+
<!--
|
|
28
|
+
Explain what is actually happening.
|
|
29
|
+
-->
|
|
30
|
+
|
|
31
|
+
#### Steps to reproduce the issue:
|
|
32
|
+
<!--
|
|
33
|
+
Explain how the issue can be reproduced.
|
|
34
|
+
If we manage to reproduce the issue then it is more likely to be addressed in an update.
|
|
35
|
+
-->
|
|
36
|
+
|
|
37
|
+
#### Platform Information
|
|
38
|
+
* **React Native Version**:
|
|
39
|
+
* **WebRTC Module Version**:
|
|
40
|
+
* **Platform OS + Version**: <!-- Android / iOS / macOS / Web / Expo -->
|
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present React Native WebRTC Community
|
|
4
|
+
Copyright (c) 2015-2017 Howard Yang
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
[<img src="https://avatars.githubusercontent.com/u/42463376" alt="React Native WebRTC" style="height: 6em;" />](https://github.com/react-native-webrtc/react-native-webrtc)
|
|
2
|
+
|
|
3
|
+
# React-Native-WebRTC
|
|
4
|
+
[](https://www.npmjs.com/package/@sbhjt-gr/react-native-webrtc)
|
|
5
|
+
[](https://react-native-webrtc.discourse.group/)
|
|
6
|
+
|
|
7
|
+
A WebRTC module for React Native.
|
|
8
|
+
|
|
9
|
+
> [!NOTE]
|
|
10
|
+
> This is a fork of [livekit/react-native-webrtc](https://github.com/livekit/react-native-webrtc) with additional audio interception features for real-time translation.
|
|
11
|
+
|
|
12
|
+
## Feature Overview
|
|
13
|
+
|
|
14
|
+
| | Android | iOS | tvOS | macOS* | Windows* | Web* | Expo* |
|
|
15
|
+
| :- | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
|
|
16
|
+
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | - | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
17
|
+
| Data Channels | :heavy_check_mark: | :heavy_check_mark: | - | - | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
18
|
+
| Screen Capture | :heavy_check_mark: | :heavy_check_mark: | - | - | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
19
|
+
| Plan B | - | - | - | - | - | - | - |
|
|
20
|
+
| Unified Plan* | :heavy_check_mark: | :heavy_check_mark: | - | - | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
21
|
+
| Simulcast* | :heavy_check_mark: | :heavy_check_mark: | - | - | - | :heavy_check_mark: | :heavy_check_mark: |
|
|
22
|
+
|
|
23
|
+
> **macOS** - We don't currently actively support macOS at this time.
|
|
24
|
+
Support might return in the future.
|
|
25
|
+
|
|
26
|
+
> **Windows** - We don't currently support the [react-native-windows](https://github.com/microsoft/react-native-windows) platform at this time.
|
|
27
|
+
Anyone interested in getting the ball rolling? We're open to contributions.
|
|
28
|
+
|
|
29
|
+
> **Web** - The [react-native-webrtc-web-shim](https://github.com/react-native-webrtc/react-native-webrtc-web-shim) project provides a shim for [react-native-web](https://github.com/necolas/react-native-web) support.
|
|
30
|
+
Which will allow you to use [(almost)](https://github.com/react-native-webrtc/react-native-webrtc-web-shim/tree/main#setup) the exact same code in your [react-native-web](https://github.com/necolas/react-native-web) project as you would with [react-native](https://reactnative.dev/) directly.
|
|
31
|
+
|
|
32
|
+
> **Expo** - As this module includes native code it is not available in the [Expo Go](https://expo.dev/client) app by default.
|
|
33
|
+
However you can get things working via the [expo-dev-client](https://docs.expo.dev/development/getting-started/) library and out-of-tree [config-plugins/react-native-webrtc](https://github.com/expo/config-plugins/tree/master/packages/react-native-webrtc) package.
|
|
34
|
+
|
|
35
|
+
> **Unified Plan** - As of version 106.0.0 Unified Plan is the only supported mode.
|
|
36
|
+
Those still in need of Plan B will need to use an older release.
|
|
37
|
+
|
|
38
|
+
> **Simulcast** - As of version 111.0.0 Simulcast is now possible with ease.
|
|
39
|
+
Software encode/decode factories have been enabled by default.
|
|
40
|
+
|
|
41
|
+
## WebRTC Revision
|
|
42
|
+
|
|
43
|
+
* Currently used revision: [M125](https://github.com/webrtc-sdk/webrtc/tree/m125_release)
|
|
44
|
+
* Supported architectures
|
|
45
|
+
* Android: armeabi-v7a, arm64-v8a, x86, x86_64
|
|
46
|
+
* iOS: arm64, x86_64
|
|
47
|
+
* tvOS: arm64
|
|
48
|
+
* macOS: arm64, x86_64
|
|
49
|
+
|
|
50
|
+
## Getting Started
|
|
51
|
+
|
|
52
|
+
Use one of the following preferred package install methods to immediately get going.
|
|
53
|
+
Don't forget to follow platform guides below to cover any extra required steps.
|
|
54
|
+
|
|
55
|
+
**npm:** `npm install @sbhjt-gr/react-native-webrtc --save`
|
|
56
|
+
**yarn:** `yarn add @sbhjt-gr/react-native-webrtc`
|
|
57
|
+
**pnpm:** `pnpm install @sbhjt-gr/react-native-webrtc`
|
|
58
|
+
|
|
59
|
+
## Guides
|
|
60
|
+
|
|
61
|
+
- [Android Install](./Documentation/AndroidInstallation.md)
|
|
62
|
+
- [iOS Install](./Documentation/iOSInstallation.md)
|
|
63
|
+
- [tvOS Install](./Documentation/tvOSInstallation.md)
|
|
64
|
+
- [Basic Usage](./Documentation/BasicUsage.md)
|
|
65
|
+
- [Step by Step Call Guide](./Documentation/CallGuide.md)
|
|
66
|
+
- [Improving Call Reliability](./Documentation/ImprovingCallReliability.md)
|
|
67
|
+
- [Migrating to Unified Plan](https://docs.google.com/document/d/1-ZfikoUtoJa9k-GZG1daN0BU3IjIanQ_JSscHxQesvU/edit#heading=h.wuu7dx8tnifl)
|
|
68
|
+
|
|
69
|
+
## Example Projects
|
|
70
|
+
|
|
71
|
+
We have some very basic example projects included in the [examples](./examples) directory.
|
|
72
|
+
Don't worry, there are plans to include a much more broader example with backend included.
|
|
73
|
+
|
|
74
|
+
## Community
|
|
75
|
+
|
|
76
|
+
Come join our [Discourse Community](https://react-native-webrtc.discourse.group/) if you want to discuss any React Native and WebRTC related topics.
|
|
77
|
+
Everyone is welcome and every little helps.
|
|
78
|
+
|
|
79
|
+
## Related Projects
|
|
80
|
+
|
|
81
|
+
Looking for extra functionality coverage?
|
|
82
|
+
The [react-native-webrtc](https://github.com/react-native-webrtc) organization provides a number of packages which are more than useful when developing Real Time Communication applications.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
def safeExtGet(prop, fallback) {
|
|
4
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
android {
|
|
8
|
+
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
9
|
+
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
|
|
10
|
+
namespace "com.oney.WebRTCModule"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
compileSdkVersion safeExtGet('compileSdkVersion', 24)
|
|
14
|
+
buildToolsVersion safeExtGet('buildToolsVersion', "23.0.1")
|
|
15
|
+
|
|
16
|
+
defaultConfig {
|
|
17
|
+
minSdkVersion 24
|
|
18
|
+
targetSdkVersion safeExtGet('targetSdkVersion', 24)
|
|
19
|
+
versionCode 1
|
|
20
|
+
versionName "1.0"
|
|
21
|
+
consumerProguardFiles 'consumer-rules.pro'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// WebRTC requires Java 8 features
|
|
25
|
+
// https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/discuss-webrtc/V1h2uQMDCkA/RA-uzncVAAAJ
|
|
26
|
+
compileOptions {
|
|
27
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
28
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
dependencies {
|
|
33
|
+
implementation "com.facebook.react:react-android:+"
|
|
34
|
+
api 'io.github.webrtc-sdk:android:137.7151.04'
|
|
35
|
+
implementation "androidx.core:core:1.7.0"
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
+
package="com.oney.WebRTCModule"
|
|
3
|
+
xmlns:tools="http://schemas.android.com/tools"
|
|
4
|
+
>
|
|
5
|
+
<application>
|
|
6
|
+
<service
|
|
7
|
+
android:name=".MediaProjectionService"
|
|
8
|
+
android:foregroundServiceType="mediaProjection">
|
|
9
|
+
</service>
|
|
10
|
+
</application>
|
|
11
|
+
</manifest>
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
package com.oney.WebRTCModule;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
import androidx.core.util.Consumer;
|
|
5
|
+
|
|
6
|
+
import com.facebook.react.bridge.Arguments;
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
8
|
+
import com.facebook.react.bridge.WritableMap;
|
|
9
|
+
|
|
10
|
+
import org.webrtc.VideoCapturer;
|
|
11
|
+
|
|
12
|
+
public abstract class AbstractVideoCaptureController {
|
|
13
|
+
protected int targetWidth;
|
|
14
|
+
protected int targetHeight;
|
|
15
|
+
protected int targetFps;
|
|
16
|
+
|
|
17
|
+
protected int actualWidth;
|
|
18
|
+
protected int actualHeight;
|
|
19
|
+
protected int actualFps;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* {@link VideoCapturer} which this controller manages.
|
|
23
|
+
*/
|
|
24
|
+
protected VideoCapturer videoCapturer;
|
|
25
|
+
|
|
26
|
+
protected CapturerEventsListener capturerEventsListener;
|
|
27
|
+
|
|
28
|
+
public AbstractVideoCaptureController(int width, int height, int fps) {
|
|
29
|
+
this.targetWidth = width;
|
|
30
|
+
this.targetHeight = height;
|
|
31
|
+
this.targetFps = fps;
|
|
32
|
+
this.actualWidth = width;
|
|
33
|
+
this.actualHeight = height;
|
|
34
|
+
this.actualFps = fps;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public void initializeVideoCapturer() {
|
|
38
|
+
videoCapturer = createVideoCapturer();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@Nullable
|
|
42
|
+
public abstract String getDeviceId();
|
|
43
|
+
|
|
44
|
+
public void dispose() {
|
|
45
|
+
if (videoCapturer != null) {
|
|
46
|
+
videoCapturer.dispose();
|
|
47
|
+
videoCapturer = null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public int getHeight() {
|
|
52
|
+
return actualHeight;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public int getWidth() {
|
|
56
|
+
return actualWidth;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public int getFrameRate() {
|
|
60
|
+
return actualFps;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public WritableMap getSettings() {
|
|
64
|
+
WritableMap settings = Arguments.createMap();
|
|
65
|
+
settings.putString("deviceId", getDeviceId());
|
|
66
|
+
settings.putString("groupId", "");
|
|
67
|
+
settings.putInt("height", getHeight());
|
|
68
|
+
settings.putInt("width", getWidth());
|
|
69
|
+
settings.putInt("frameRate", getFrameRate());
|
|
70
|
+
return settings;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public VideoCapturer getVideoCapturer() {
|
|
74
|
+
return videoCapturer;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void startCapture() {
|
|
78
|
+
try {
|
|
79
|
+
videoCapturer.startCapture(targetWidth, targetHeight, targetFps);
|
|
80
|
+
} catch (RuntimeException e) {
|
|
81
|
+
// XXX This can only fail if we initialize the capturer incorrectly,
|
|
82
|
+
// which we don't. Thus, ignore any failures here since we trust
|
|
83
|
+
// ourselves.
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public boolean stopCapture() {
|
|
88
|
+
try {
|
|
89
|
+
videoCapturer.stopCapture();
|
|
90
|
+
return true;
|
|
91
|
+
} catch (InterruptedException e) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public void applyConstraints(ReadableMap constraints, @Nullable Consumer<Exception> onFinishedCallback) {
|
|
97
|
+
if (onFinishedCallback != null) {
|
|
98
|
+
onFinishedCallback.accept(
|
|
99
|
+
new UnsupportedOperationException("This video track does not support applyConstraints."));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void setCapturerEventsListener(CapturerEventsListener listener) {
|
|
104
|
+
this.capturerEventsListener = listener;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
protected abstract VideoCapturer createVideoCapturer();
|
|
108
|
+
|
|
109
|
+
public interface CapturerEventsListener {
|
|
110
|
+
/** Called when the capturer is ended and in an irrecoverable state. */
|
|
111
|
+
public void onCapturerEnded();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
package com.oney.WebRTCModule;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.hardware.camera2.CameraManager;
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
import android.util.Pair;
|
|
7
|
+
|
|
8
|
+
import androidx.annotation.Nullable;
|
|
9
|
+
import androidx.core.util.Consumer;
|
|
10
|
+
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.WritableMap;
|
|
13
|
+
|
|
14
|
+
import org.webrtc.Camera1Capturer;
|
|
15
|
+
import org.webrtc.Camera1Helper;
|
|
16
|
+
import org.webrtc.Camera2Capturer;
|
|
17
|
+
import org.webrtc.Camera2Helper;
|
|
18
|
+
import org.webrtc.CameraEnumerator;
|
|
19
|
+
import org.webrtc.CameraVideoCapturer;
|
|
20
|
+
import org.webrtc.Size;
|
|
21
|
+
import org.webrtc.VideoCapturer;
|
|
22
|
+
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.List;
|
|
25
|
+
import java.util.Objects;
|
|
26
|
+
|
|
27
|
+
public class CameraCaptureController extends AbstractVideoCaptureController {
|
|
28
|
+
/**
|
|
29
|
+
* The {@link Log} tag with which {@code CameraCaptureController} is to log.
|
|
30
|
+
*/
|
|
31
|
+
private static final String TAG = CameraCaptureController.class.getSimpleName();
|
|
32
|
+
|
|
33
|
+
private boolean isFrontFacing;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Equivalent to the camera index as a String
|
|
37
|
+
*/
|
|
38
|
+
@Nullable
|
|
39
|
+
private String currentDeviceId;
|
|
40
|
+
|
|
41
|
+
private final Context context;
|
|
42
|
+
private final CameraEnumerator cameraEnumerator;
|
|
43
|
+
|
|
44
|
+
private final String constraintDeviceId;
|
|
45
|
+
private final String constraintFacingMode;
|
|
46
|
+
private ReadableMap constraints;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The {@link CameraEventsHandler} used with
|
|
50
|
+
* {@link CameraEnumerator#createCapturer}.
|
|
51
|
+
*/
|
|
52
|
+
private final CameraEventsHandler cameraEventsHandler = new CameraEventsHandler() {
|
|
53
|
+
@Override
|
|
54
|
+
public void onCameraOpening(String cameraName) {
|
|
55
|
+
super.onCameraOpening(cameraName);
|
|
56
|
+
int cameraIndex = findCameraIndex(cameraName);
|
|
57
|
+
updateActualSize(cameraIndex, cameraName, videoCapturer);
|
|
58
|
+
CameraCaptureController.this.currentDeviceId = cameraIndex == -1 ? null : String.valueOf(cameraIndex);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
public CameraCaptureController(Context context, CameraEnumerator cameraEnumerator, ReadableMap constraints) {
|
|
63
|
+
super(constraints.getInt("width"), constraints.getInt("height"), constraints.getInt("frameRate"));
|
|
64
|
+
|
|
65
|
+
this.context = context;
|
|
66
|
+
this.cameraEnumerator = cameraEnumerator;
|
|
67
|
+
this.constraints = constraints;
|
|
68
|
+
|
|
69
|
+
this.constraintDeviceId = ReactBridgeUtil.getMapStrValue(this.constraints, "deviceId");
|
|
70
|
+
this.constraintFacingMode = ReactBridgeUtil.getMapStrValue(this.constraints, "facingMode");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Nullable
|
|
74
|
+
@Override
|
|
75
|
+
public String getDeviceId() {
|
|
76
|
+
return currentDeviceId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private int findCameraIndex(String cameraName) {
|
|
80
|
+
String[] deviceNames = cameraEnumerator.getDeviceNames();
|
|
81
|
+
for (int i = 0; i < deviceNames.length; i++) {
|
|
82
|
+
if (Objects.equals(deviceNames[i], cameraName)) {
|
|
83
|
+
return i;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Override
|
|
90
|
+
public WritableMap getSettings() {
|
|
91
|
+
WritableMap settings = super.getSettings();
|
|
92
|
+
settings.putString("facingMode", isFrontFacing ? "user" : "environment");
|
|
93
|
+
return settings;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
public void applyConstraints(ReadableMap constraints, @Nullable Consumer<Exception> onFinishedCallback) {
|
|
98
|
+
ReadableMap oldConstraints = this.constraints;
|
|
99
|
+
int oldTargetWidth = this.targetWidth;
|
|
100
|
+
int oldTargetHeight = this.targetHeight;
|
|
101
|
+
int oldTargetFps = this.targetFps;
|
|
102
|
+
|
|
103
|
+
// Don't save constraints yet, since we may fail to find a fit.
|
|
104
|
+
Runnable saveConstraints = () -> {
|
|
105
|
+
this.constraints = constraints;
|
|
106
|
+
this.targetWidth = constraints.getInt("width");
|
|
107
|
+
this.targetHeight = constraints.getInt("height");
|
|
108
|
+
this.targetFps = constraints.getInt("frameRate");
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (videoCapturer == null) {
|
|
112
|
+
// No existing capturer, just let it initialize normally.
|
|
113
|
+
saveConstraints.run();
|
|
114
|
+
if (onFinishedCallback != null) {
|
|
115
|
+
onFinishedCallback.accept(null);
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Find target camera to switch to.
|
|
121
|
+
String[] deviceNames = cameraEnumerator.getDeviceNames();
|
|
122
|
+
|
|
123
|
+
// Use the initial deviceId/facingMode. It is a constraint violation to change these through applyConstraints.
|
|
124
|
+
final String deviceId = constraintDeviceId;
|
|
125
|
+
final String facingMode = constraintFacingMode;
|
|
126
|
+
int cameraIndex = -1;
|
|
127
|
+
String cameraName = null;
|
|
128
|
+
|
|
129
|
+
// If deviceId is specified, then it takes precedence over facingMode.
|
|
130
|
+
if (deviceId != null) {
|
|
131
|
+
try {
|
|
132
|
+
cameraIndex = Integer.parseInt(deviceId);
|
|
133
|
+
cameraName = deviceNames[cameraIndex];
|
|
134
|
+
} catch (Exception e) {
|
|
135
|
+
Log.d(TAG, "failed to find device with id: " + deviceId);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Otherwise, use facingMode (defaulting to front/user facing).
|
|
140
|
+
if (cameraName == null) {
|
|
141
|
+
cameraIndex = -1;
|
|
142
|
+
final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
|
|
143
|
+
for (String name : deviceNames) {
|
|
144
|
+
cameraIndex++;
|
|
145
|
+
if (cameraEnumerator.isFrontFacing(name) == isFrontFacing) {
|
|
146
|
+
cameraName = name;
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (cameraName == null) {
|
|
153
|
+
if (onFinishedCallback != null) {
|
|
154
|
+
onFinishedCallback.accept(new Exception("OverconstrainedError: could not find camera with deviceId: "
|
|
155
|
+
+ deviceId + " or facingMode: " + facingMode));
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// For lambda reference
|
|
161
|
+
final int finalCameraIndex = cameraIndex;
|
|
162
|
+
final String finalCameraName = cameraName;
|
|
163
|
+
boolean shouldSwitchCamera = false;
|
|
164
|
+
try {
|
|
165
|
+
int currentCameraIndex = Integer.parseInt(currentDeviceId);
|
|
166
|
+
shouldSwitchCamera = cameraIndex != currentCameraIndex;
|
|
167
|
+
} catch (Exception e) {
|
|
168
|
+
shouldSwitchCamera = true;
|
|
169
|
+
Log.d(TAG, "Forcing camera switch, couldn't parse current device id: " + currentDeviceId);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
CameraVideoCapturer capturer = (CameraVideoCapturer) videoCapturer;
|
|
173
|
+
Runnable changeFormatIfNeededAndFinish = () -> {
|
|
174
|
+
saveConstraints.run();
|
|
175
|
+
if (targetWidth != oldTargetWidth || targetHeight != oldTargetHeight || targetFps != oldTargetFps) {
|
|
176
|
+
updateActualSize(finalCameraIndex, finalCameraName, videoCapturer);
|
|
177
|
+
capturer.changeCaptureFormat(targetWidth, targetHeight, targetFps);
|
|
178
|
+
}
|
|
179
|
+
if (onFinishedCallback != null) {
|
|
180
|
+
onFinishedCallback.accept(null);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
if (shouldSwitchCamera) {
|
|
185
|
+
capturer.switchCamera(new CameraVideoCapturer.CameraSwitchHandler() {
|
|
186
|
+
@Override
|
|
187
|
+
public void onCameraSwitchDone(boolean isFrontCamera) {
|
|
188
|
+
CameraCaptureController.this.isFrontFacing = isFrontCamera;
|
|
189
|
+
changeFormatIfNeededAndFinish.run();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Override
|
|
193
|
+
public void onCameraSwitchError(String s) {
|
|
194
|
+
Exception e = new Exception("Error switching camera: " + s);
|
|
195
|
+
Log.e(TAG, "OnCameraSwitchError", e);
|
|
196
|
+
if (onFinishedCallback != null) {
|
|
197
|
+
onFinishedCallback.accept(e);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}, cameraName);
|
|
201
|
+
} else {
|
|
202
|
+
// No camera switch needed, just change format if needed.
|
|
203
|
+
changeFormatIfNeededAndFinish.run();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
@Override
|
|
208
|
+
protected VideoCapturer createVideoCapturer() {
|
|
209
|
+
CreateCapturerResult result = createVideoCapturer(constraintDeviceId, constraintFacingMode);
|
|
210
|
+
if (result == null) {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
updateActualSize(result.cameraIndex, result.cameraName, result.videoCapturer);
|
|
215
|
+
|
|
216
|
+
return result.videoCapturer;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private void updateActualSize(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
|
|
220
|
+
// Find actual capture format.
|
|
221
|
+
Size actualSize = null;
|
|
222
|
+
if (videoCapturer instanceof Camera1Capturer) {
|
|
223
|
+
actualSize = Camera1Helper.findClosestCaptureFormat(cameraIndex, targetWidth, targetHeight);
|
|
224
|
+
} else if (videoCapturer instanceof Camera2Capturer) {
|
|
225
|
+
CameraManager cameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
|
|
226
|
+
actualSize = Camera2Helper.findClosestCaptureFormat(cameraManager, cameraName, targetWidth, targetHeight);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (actualSize != null) {
|
|
230
|
+
actualWidth = actualSize.width;
|
|
231
|
+
actualHeight = actualSize.height;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Constructs a new {@code VideoCapturer} instance attempting to satisfy
|
|
237
|
+
* specific constraints.
|
|
238
|
+
*
|
|
239
|
+
* @param deviceId the ID of the requested video device. If not
|
|
240
|
+
* {@code null} and a {@code VideoCapturer} can be created for it, then
|
|
241
|
+
* {@code facingMode} is ignored.
|
|
242
|
+
* @param facingMode the facing of the requested video source such as
|
|
243
|
+
* {@code user} and {@code environment}. If {@code null}, "user" is
|
|
244
|
+
* presumed.
|
|
245
|
+
* @return a pair containing the deviceId and {@code VideoCapturer} satisfying the {@code facingMode} or
|
|
246
|
+
* {@code deviceId} constraint, or null.
|
|
247
|
+
*/
|
|
248
|
+
@Nullable
|
|
249
|
+
private CreateCapturerResult createVideoCapturer(String deviceId, String facingMode) {
|
|
250
|
+
String[] deviceNames = cameraEnumerator.getDeviceNames();
|
|
251
|
+
List<String> failedDevices = new ArrayList<>();
|
|
252
|
+
|
|
253
|
+
String cameraName = null;
|
|
254
|
+
int cameraIndex = -1;
|
|
255
|
+
try {
|
|
256
|
+
cameraIndex = Integer.parseInt(deviceId);
|
|
257
|
+
cameraName = deviceNames[cameraIndex];
|
|
258
|
+
} catch (Exception e) {
|
|
259
|
+
Log.d(TAG, "failed to find device with id: " + deviceId);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// If deviceId is specified, then it takes precedence over facingMode.
|
|
263
|
+
if (cameraName != null) {
|
|
264
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(cameraName, cameraEventsHandler);
|
|
265
|
+
String message = "Create user-specified camera " + cameraName;
|
|
266
|
+
if (videoCapturer != null) {
|
|
267
|
+
Log.d(TAG, message + " succeeded");
|
|
268
|
+
this.isFrontFacing = cameraEnumerator.isFrontFacing(cameraName);
|
|
269
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
270
|
+
return new CreateCapturerResult(cameraIndex, cameraName, videoCapturer);
|
|
271
|
+
} else {
|
|
272
|
+
// fallback to facingMode
|
|
273
|
+
Log.d(TAG, message + " failed");
|
|
274
|
+
failedDevices.add(cameraName);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Otherwise, use facingMode (defaulting to front/user facing).
|
|
279
|
+
final boolean isFrontFacing = facingMode == null || facingMode.equals("user");
|
|
280
|
+
cameraIndex = -1;
|
|
281
|
+
for (String name : deviceNames) {
|
|
282
|
+
cameraIndex++;
|
|
283
|
+
if (failedDevices.contains(name)) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (cameraEnumerator.isFrontFacing(name) != isFrontFacing) {
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
290
|
+
String message = "Create camera " + name;
|
|
291
|
+
if (videoCapturer != null) {
|
|
292
|
+
Log.d(TAG, message + " succeeded");
|
|
293
|
+
this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
|
|
294
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
295
|
+
return new CreateCapturerResult(cameraIndex, name, videoCapturer);
|
|
296
|
+
} else {
|
|
297
|
+
Log.d(TAG, message + " failed");
|
|
298
|
+
failedDevices.add(name);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
cameraIndex = -1;
|
|
303
|
+
// Fallback to any available camera.
|
|
304
|
+
for (String name : deviceNames) {
|
|
305
|
+
cameraIndex++;
|
|
306
|
+
if (!failedDevices.contains(name)) {
|
|
307
|
+
VideoCapturer videoCapturer = cameraEnumerator.createCapturer(name, cameraEventsHandler);
|
|
308
|
+
String message = "Create fallback camera " + name;
|
|
309
|
+
if (videoCapturer != null) {
|
|
310
|
+
Log.d(TAG, message + " succeeded");
|
|
311
|
+
this.isFrontFacing = cameraEnumerator.isFrontFacing(name);
|
|
312
|
+
this.currentDeviceId = String.valueOf(cameraIndex);
|
|
313
|
+
return new CreateCapturerResult(cameraIndex, name, videoCapturer);
|
|
314
|
+
} else {
|
|
315
|
+
Log.d(TAG, message + " failed");
|
|
316
|
+
failedDevices.add(name);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
currentDeviceId = null;
|
|
322
|
+
Log.w(TAG, "Unable to identify a suitable camera.");
|
|
323
|
+
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private static class CreateCapturerResult {
|
|
328
|
+
public final int cameraIndex;
|
|
329
|
+
public final String cameraName;
|
|
330
|
+
public final VideoCapturer videoCapturer;
|
|
331
|
+
|
|
332
|
+
public CreateCapturerResult(int cameraIndex, String cameraName, VideoCapturer videoCapturer) {
|
|
333
|
+
this.cameraIndex = cameraIndex;
|
|
334
|
+
this.cameraName = cameraName;
|
|
335
|
+
this.videoCapturer = videoCapturer;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|