@sbhjt-gr/react-native-webrtc 124.0.2 → 124.0.4
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 -11
- package/.eslintignore +6 -6
- package/.nvmrc +1 -1
- package/ISSUE_TEMPLATE.md +40 -40
- package/LICENSE +22 -22
- package/README.md +103 -103
- package/android/build.gradle +37 -37
- package/android/consumer-rules.pro +3 -3
- package/android/src/main/AndroidManifest.xml +11 -11
- package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +113 -113
- package/android/src/main/java/com/oney/WebRTCModule/CameraCaptureController.java +338 -338
- package/android/src/main/java/com/oney/WebRTCModule/CameraEventsHandler.java +49 -49
- package/android/src/main/java/com/oney/WebRTCModule/DataChannelWrapper.java +99 -99
- package/android/src/main/java/com/oney/WebRTCModule/DataPacketCryptorManager.java +62 -62
- package/android/src/main/java/com/oney/WebRTCModule/DisplayUtils.java +16 -16
- package/android/src/main/java/com/oney/WebRTCModule/EglUtils.java +66 -66
- package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +539 -539
- package/android/src/main/java/com/oney/WebRTCModule/LibraryLoader.java +21 -21
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionNotification.java +70 -70
- package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +82 -82
- package/android/src/main/java/com/oney/WebRTCModule/PeerConnectionObserver.java +588 -588
- package/android/src/main/java/com/oney/WebRTCModule/RTCCryptoManager.java +493 -493
- package/android/src/main/java/com/oney/WebRTCModule/RTCVideoViewManager.java +98 -98
- package/android/src/main/java/com/oney/WebRTCModule/ReactBridgeUtil.java +35 -35
- package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +94 -94
- package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +342 -342
- package/android/src/main/java/com/oney/WebRTCModule/StringUtils.java +100 -100
- package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +41 -41
- package/android/src/main/java/com/oney/WebRTCModule/TrackCapturerEventsEmitter.java +34 -34
- package/android/src/main/java/com/oney/WebRTCModule/VideoTrackAdapter.java +137 -137
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +1649 -1643
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModuleOptions.java +33 -33
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCModulePackage.java +21 -21
- package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +583 -583
- package/android/src/main/java/com/oney/WebRTCModule/palabra/PalabraClient.java +529 -464
- package/android/src/main/java/com/oney/WebRTCModule/palabra/PalabraConfig.java +17 -17
- package/android/src/main/java/com/oney/WebRTCModule/palabra/PalabraListener.java +7 -7
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/ProcessorProvider.java +38 -38
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoEffectProcessor.java +59 -59
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessor.java +19 -19
- package/android/src/main/java/com/oney/WebRTCModule/videoEffects/VideoFrameProcessorFactoryInterface.java +12 -12
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoDecoderFactory.java +73 -73
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/H264AndSoftwareVideoEncoderFactory.java +73 -73
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoDecoderFactoryProxy.java +36 -36
- package/android/src/main/java/com/oney/WebRTCModule/webrtcutils/SoftwareVideoEncoderFactoryProxy.java +36 -36
- package/android/src/main/java/org/webrtc/Camera1Helper.java +54 -54
- package/android/src/main/java/org/webrtc/Camera2Helper.java +52 -52
- package/android/src/main/res/values/strings.xml +5 -5
- package/android/src/main/res/values/styles.xml +8 -8
- package/ios/RCTWebRTC/CaptureController.h +18 -18
- package/ios/RCTWebRTC/CaptureController.m +28 -28
- package/ios/RCTWebRTC/CapturerEventsDelegate.h +12 -12
- package/ios/RCTWebRTC/DataChannelWrapper.h +27 -27
- package/ios/RCTWebRTC/DataChannelWrapper.m +42 -42
- package/ios/RCTWebRTC/I420Converter.h +22 -22
- package/ios/RCTWebRTC/I420Converter.m +164 -164
- package/ios/RCTWebRTC/PIPController.h +24 -24
- package/ios/RCTWebRTC/PIPController.m +234 -234
- package/ios/RCTWebRTC/PalabraAudioSink.h +13 -13
- package/ios/RCTWebRTC/PalabraAudioSink.m +18 -18
- package/ios/RCTWebRTC/PalabraClient.h +42 -36
- package/ios/RCTWebRTC/PalabraClient.m +680 -584
- package/ios/RCTWebRTC/RCTConvert+WebRTC.h +16 -16
- package/ios/RCTWebRTC/RCTConvert+WebRTC.m +206 -206
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.h +10 -10
- package/ios/RCTWebRTC/RTCMediaStreamTrack+React.m +16 -16
- package/ios/RCTWebRTC/RTCVideoViewManager.h +29 -29
- package/ios/RCTWebRTC/RTCVideoViewManager.m +411 -411
- package/ios/RCTWebRTC/SampleBufferVideoCallView.h +12 -12
- package/ios/RCTWebRTC/SampleBufferVideoCallView.m +178 -178
- package/ios/RCTWebRTC/ScreenCaptureController.h +20 -20
- package/ios/RCTWebRTC/ScreenCaptureController.m +82 -82
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.h +7 -7
- package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +59 -59
- package/ios/RCTWebRTC/ScreenCapturer.h +19 -19
- package/ios/RCTWebRTC/ScreenCapturer.m +263 -263
- package/ios/RCTWebRTC/SerializeUtils.h +28 -28
- package/ios/RCTWebRTC/SerializeUtils.m +314 -314
- package/ios/RCTWebRTC/SocketConnection.h +13 -13
- package/ios/RCTWebRTC/SocketConnection.m +137 -137
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.h +14 -14
- package/ios/RCTWebRTC/TrackCapturerEventsEmitter.m +36 -36
- package/ios/RCTWebRTC/VideoCaptureController.h +21 -21
- package/ios/RCTWebRTC/VideoCaptureController.m +328 -328
- package/ios/RCTWebRTC/WLVAudioDevice.h +12 -12
- package/ios/RCTWebRTC/WLVAudioDevice.m +137 -137
- package/ios/RCTWebRTC/WebRTCModule+Palabra.h +4 -4
- package/ios/RCTWebRTC/WebRTCModule+Palabra.m +92 -83
- package/ios/RCTWebRTC/WebRTCModule+Permissions.m +75 -75
- package/ios/RCTWebRTC/WebRTCModule+RTCAudioSession.m +20 -20
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.h +14 -14
- package/ios/RCTWebRTC/WebRTCModule+RTCDataChannel.m +165 -165
- package/ios/RCTWebRTC/WebRTCModule+RTCFrameCryptor.m +611 -611
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.h +13 -13
- package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +728 -728
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +24 -24
- package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +1004 -1004
- package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +267 -267
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.h +12 -12
- package/ios/RCTWebRTC/WebRTCModule+VideoTrackAdapter.m +166 -166
- package/ios/RCTWebRTC/WebRTCModule.h +58 -58
- package/ios/RCTWebRTC/WebRTCModule.m +169 -169
- package/ios/RCTWebRTC/WebRTCModuleOptions.h +24 -24
- package/ios/RCTWebRTC/WebRTCModuleOptions.m +31 -31
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.h +9 -9
- package/ios/RCTWebRTC/videoEffects/ProcessorProvider.m +23 -23
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.h +13 -13
- package/ios/RCTWebRTC/videoEffects/VideoEffectProcessor.m +23 -23
- package/ios/RCTWebRTC/videoEffects/VideoFrameProcessor.h +8 -8
- package/ios/RCTWebRTC.xcodeproj/project.pbxproj +404 -404
- package/ios/RCTWebRTC.xcworkspace/contents.xcworkspacedata +10 -10
- package/lib/commonjs/Constraints.js.map +1 -1
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/Logger.js.map +1 -1
- package/lib/commonjs/MediaDevices.js +17 -17
- package/lib/commonjs/MediaDevices.js.map +1 -1
- package/lib/commonjs/MediaStream.js +19 -19
- package/lib/commonjs/MediaStream.js.map +1 -1
- package/lib/commonjs/MediaStreamError.js.map +1 -1
- package/lib/commonjs/MediaStreamErrorEvent.js.map +1 -1
- package/lib/commonjs/MediaStreamTrack.js +28 -28
- package/lib/commonjs/MediaStreamTrack.js.map +1 -1
- package/lib/commonjs/MediaStreamTrackEvent.js +6 -6
- package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
- package/lib/commonjs/MessageEvent.js +7 -7
- package/lib/commonjs/MessageEvent.js.map +1 -1
- package/lib/commonjs/Permissions.js +28 -28
- package/lib/commonjs/Permissions.js.map +1 -1
- package/lib/commonjs/RTCAudioSession.js +4 -4
- package/lib/commonjs/RTCAudioSession.js.map +1 -1
- package/lib/commonjs/RTCDataChannel.js +2 -2
- package/lib/commonjs/RTCDataChannel.js.map +1 -1
- package/lib/commonjs/RTCDataChannelEvent.js +6 -6
- package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
- package/lib/commonjs/RTCDataPacketCryptor.js.map +1 -1
- package/lib/commonjs/RTCDataPacketCryptorFactory.js.map +1 -1
- package/lib/commonjs/RTCErrorEvent.js +3 -3
- package/lib/commonjs/RTCErrorEvent.js.map +1 -1
- package/lib/commonjs/RTCFrameCryptor.js +8 -8
- package/lib/commonjs/RTCFrameCryptor.js.map +1 -1
- package/lib/commonjs/RTCFrameCryptorFactory.js.map +1 -1
- package/lib/commonjs/RTCIceCandidate.js.map +1 -1
- package/lib/commonjs/RTCIceCandidateEvent.js +7 -7
- package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
- package/lib/commonjs/RTCKeyProvider.js.map +1 -1
- package/lib/commonjs/RTCPIPView.js +2 -2
- package/lib/commonjs/RTCPIPView.js.map +1 -1
- package/lib/commonjs/RTCPIPView.web.js.map +1 -1
- package/lib/commonjs/RTCPeerConnection.js +146 -41
- package/lib/commonjs/RTCPeerConnection.js.map +1 -1
- package/lib/commonjs/RTCRtcpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpCapabilities.js +2 -2
- package/lib/commonjs/RTCRtpCapabilities.js.map +1 -1
- package/lib/commonjs/RTCRtpCodecCapability.js.map +1 -1
- package/lib/commonjs/RTCRtpCodecParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpHeaderExtension.js.map +1 -1
- package/lib/commonjs/RTCRtpParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpReceiver.js +7 -7
- package/lib/commonjs/RTCRtpReceiver.js.map +1 -1
- package/lib/commonjs/RTCRtpSendParameters.js +3 -3
- package/lib/commonjs/RTCRtpSendParameters.js.map +1 -1
- package/lib/commonjs/RTCRtpSender.js +7 -7
- package/lib/commonjs/RTCRtpSender.js.map +1 -1
- package/lib/commonjs/RTCRtpTransceiver.js.map +1 -1
- package/lib/commonjs/RTCSessionDescription.js.map +1 -1
- package/lib/commonjs/RTCTrackEvent.js +6 -6
- package/lib/commonjs/RTCTrackEvent.js.map +1 -1
- package/lib/commonjs/RTCUtil.js +28 -28
- package/lib/commonjs/RTCUtil.js.map +1 -1
- package/lib/commonjs/RTCView.js +5 -5
- package/lib/commonjs/RTCView.js.map +1 -1
- package/lib/commonjs/RTCView.web.js.map +1 -1
- package/lib/commonjs/ScreenCapturePickerView.js.map +1 -1
- package/lib/commonjs/ScreenCapturePickerView.web.js.map +1 -1
- package/lib/commonjs/getDisplayMedia.js.map +1 -1
- package/lib/commonjs/getUserMedia.js +23 -0
- package/lib/commonjs/getUserMedia.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/webStream.js.map +1 -1
- package/lib/module/Constraints.js.map +1 -1
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/Logger.js.map +1 -1
- package/lib/module/MediaDevices.js +17 -17
- package/lib/module/MediaDevices.js.map +1 -1
- package/lib/module/MediaStream.js +19 -19
- package/lib/module/MediaStream.js.map +1 -1
- package/lib/module/MediaStreamError.js.map +1 -1
- package/lib/module/MediaStreamErrorEvent.js.map +1 -1
- package/lib/module/MediaStreamTrack.js +28 -28
- package/lib/module/MediaStreamTrack.js.map +1 -1
- package/lib/module/MediaStreamTrackEvent.js +6 -6
- package/lib/module/MediaStreamTrackEvent.js.map +1 -1
- package/lib/module/MessageEvent.js +7 -7
- package/lib/module/MessageEvent.js.map +1 -1
- package/lib/module/Permissions.js +28 -28
- package/lib/module/Permissions.js.map +1 -1
- package/lib/module/RTCAudioSession.js +4 -4
- package/lib/module/RTCAudioSession.js.map +1 -1
- package/lib/module/RTCDataChannel.js +2 -2
- package/lib/module/RTCDataChannel.js.map +1 -1
- package/lib/module/RTCDataChannelEvent.js +6 -6
- package/lib/module/RTCDataChannelEvent.js.map +1 -1
- package/lib/module/RTCDataPacketCryptor.js.map +1 -1
- package/lib/module/RTCDataPacketCryptorFactory.js.map +1 -1
- package/lib/module/RTCErrorEvent.js +3 -3
- package/lib/module/RTCErrorEvent.js.map +1 -1
- package/lib/module/RTCFrameCryptor.js +8 -8
- package/lib/module/RTCFrameCryptor.js.map +1 -1
- package/lib/module/RTCFrameCryptorFactory.js.map +1 -1
- package/lib/module/RTCIceCandidate.js.map +1 -1
- package/lib/module/RTCIceCandidateEvent.js +7 -7
- package/lib/module/RTCIceCandidateEvent.js.map +1 -1
- package/lib/module/RTCKeyProvider.js.map +1 -1
- package/lib/module/RTCPIPView.js +2 -2
- package/lib/module/RTCPIPView.js.map +1 -1
- package/lib/module/RTCPIPView.web.js.map +1 -1
- package/lib/module/RTCPeerConnection.js +146 -41
- package/lib/module/RTCPeerConnection.js.map +1 -1
- package/lib/module/RTCRtcpParameters.js.map +1 -1
- package/lib/module/RTCRtpCapabilities.js +2 -2
- package/lib/module/RTCRtpCapabilities.js.map +1 -1
- package/lib/module/RTCRtpCodecCapability.js.map +1 -1
- package/lib/module/RTCRtpCodecParameters.js.map +1 -1
- package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
- package/lib/module/RTCRtpHeaderExtension.js.map +1 -1
- package/lib/module/RTCRtpParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiveParameters.js.map +1 -1
- package/lib/module/RTCRtpReceiver.js +7 -7
- package/lib/module/RTCRtpReceiver.js.map +1 -1
- package/lib/module/RTCRtpSendParameters.js +3 -3
- package/lib/module/RTCRtpSendParameters.js.map +1 -1
- package/lib/module/RTCRtpSender.js +7 -7
- package/lib/module/RTCRtpSender.js.map +1 -1
- package/lib/module/RTCRtpTransceiver.js.map +1 -1
- package/lib/module/RTCSessionDescription.js.map +1 -1
- package/lib/module/RTCTrackEvent.js +6 -6
- package/lib/module/RTCTrackEvent.js.map +1 -1
- package/lib/module/RTCUtil.js +28 -28
- package/lib/module/RTCUtil.js.map +1 -1
- package/lib/module/RTCView.js +5 -5
- package/lib/module/RTCView.js.map +1 -1
- package/lib/module/RTCView.web.js.map +1 -1
- package/lib/module/ScreenCapturePickerView.js.map +1 -1
- package/lib/module/ScreenCapturePickerView.web.js.map +1 -1
- package/lib/module/getDisplayMedia.js.map +1 -1
- package/lib/module/getUserMedia.js +23 -0
- package/lib/module/getUserMedia.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/webStream.js.map +1 -1
- package/lib/typescript/Constraints.d.ts +19 -19
- package/lib/typescript/EventEmitter.d.ts +6 -6
- package/lib/typescript/Logger.d.ts +13 -13
- package/lib/typescript/MediaDevices.d.ts +30 -30
- package/lib/typescript/MediaStream.d.ts +48 -48
- package/lib/typescript/MediaStreamError.d.ts +6 -6
- package/lib/typescript/MediaStreamErrorEvent.d.ts +6 -6
- package/lib/typescript/MediaStreamTrack.d.ts +101 -101
- package/lib/typescript/MediaStreamTrackEvent.d.ts +19 -19
- package/lib/typescript/MessageEvent.d.ts +20 -20
- package/lib/typescript/Permissions.d.ts +55 -55
- package/lib/typescript/RTCAudioSession.d.ts +10 -10
- package/lib/typescript/RTCDataChannel.d.ts +43 -43
- package/lib/typescript/RTCDataChannelEvent.d.ts +19 -19
- package/lib/typescript/RTCDataPacketCryptor.d.ts +12 -12
- package/lib/typescript/RTCDataPacketCryptorFactory.d.ts +6 -6
- package/lib/typescript/RTCErrorEvent.d.ts +12 -12
- package/lib/typescript/RTCFrameCryptor.d.ts +47 -47
- package/lib/typescript/RTCFrameCryptorFactory.d.ts +21 -21
- package/lib/typescript/RTCIceCandidate.d.ts +17 -17
- package/lib/typescript/RTCIceCandidateEvent.d.ts +20 -20
- package/lib/typescript/RTCKeyProvider.d.ts +21 -21
- package/lib/typescript/RTCPIPView.d.ts +15 -15
- package/lib/typescript/RTCPIPView.web.d.ts +13 -13
- package/lib/typescript/RTCPeerConnection.d.ts +117 -117
- package/lib/typescript/RTCRtcpParameters.d.ts +10 -10
- package/lib/typescript/RTCRtpCapabilities.d.ts +9 -9
- package/lib/typescript/RTCRtpCodecCapability.d.ts +7 -7
- package/lib/typescript/RTCRtpCodecParameters.d.ts +16 -16
- package/lib/typescript/RTCRtpEncodingParameters.d.ts +23 -23
- package/lib/typescript/RTCRtpHeaderExtension.d.ts +12 -12
- package/lib/typescript/RTCRtpParameters.d.ts +19 -19
- package/lib/typescript/RTCRtpReceiveParameters.d.ts +4 -4
- package/lib/typescript/RTCRtpReceiver.d.ts +21 -21
- package/lib/typescript/RTCRtpSendParameters.d.ts +20 -20
- package/lib/typescript/RTCRtpSender.d.ts +22 -22
- package/lib/typescript/RTCRtpTransceiver.d.ts +31 -31
- package/lib/typescript/RTCSessionDescription.d.ts +12 -12
- package/lib/typescript/RTCTrackEvent.d.ts +29 -29
- package/lib/typescript/RTCUtil.d.ts +37 -37
- package/lib/typescript/RTCView.d.ts +117 -117
- package/lib/typescript/RTCView.web.d.ts +25 -25
- package/lib/typescript/ScreenCapturePickerView.d.ts +2 -2
- package/lib/typescript/ScreenCapturePickerView.web.d.ts +1 -1
- package/lib/typescript/getDisplayMedia.d.ts +2 -2
- package/lib/typescript/getUserMedia.d.ts +7 -7
- package/lib/typescript/index.d.ts +22 -22
- package/lib/typescript/index.web.d.ts +101 -101
- package/lib/typescript/webStream.d.ts +3 -3
- package/livekit-react-native-webrtc.podspec +29 -29
- package/macos/RCTWebRTC.xcodeproj/project.pbxproj +324 -324
- package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -7
- package/macos/RCTWebRTC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/metro.config.js +7 -7
- package/metro.config.macos.js +14 -14
- package/package.json +66 -66
- package/react-native.config.js +11 -11
- package/src/.eslintrc.cjs +67 -67
- package/src/Constraints.ts +20 -20
- package/src/EventEmitter.ts +65 -65
- package/src/Logger.ts +49 -49
- package/src/MediaDevices.ts +53 -53
- package/src/MediaStream.ts +161 -161
- package/src/MediaStreamError.ts +12 -12
- package/src/MediaStreamErrorEvent.ts +11 -11
- package/src/MediaStreamTrack.ts +282 -282
- package/src/MediaStreamTrackEvent.ts +25 -25
- package/src/MessageEvent.ts +26 -26
- package/src/Permissions.ts +133 -133
- package/src/RTCAudioSession.ts +25 -25
- package/src/RTCDataChannel.ts +190 -190
- package/src/RTCDataChannelEvent.ts +28 -28
- package/src/RTCDataPacketCryptor.ts +90 -90
- package/src/RTCDataPacketCryptorFactory.ts +24 -24
- package/src/RTCErrorEvent.ts +20 -20
- package/src/RTCFrameCryptor.ts +162 -162
- package/src/RTCFrameCryptorFactory.ts +101 -101
- package/src/RTCIceCandidate.ts +29 -29
- package/src/RTCIceCandidateEvent.ts +26 -26
- package/src/RTCKeyProvider.ts +117 -117
- package/src/RTCPIPView.tsx +46 -46
- package/src/RTCPIPView.web.tsx +18 -18
- package/src/RTCPeerConnection.ts +935 -832
- package/src/RTCRtcpParameters.ts +23 -23
- package/src/RTCRtpCapabilities.ts +16 -16
- package/src/RTCRtpCodecCapability.ts +12 -12
- package/src/RTCRtpCodecParameters.ts +44 -44
- package/src/RTCRtpEncodingParameters.ts +90 -90
- package/src/RTCRtpHeaderExtension.ts +27 -27
- package/src/RTCRtpParameters.ts +37 -37
- package/src/RTCRtpReceiveParameters.ts +7 -7
- package/src/RTCRtpReceiver.ts +60 -60
- package/src/RTCRtpSendParameters.ts +63 -63
- package/src/RTCRtpSender.ts +78 -78
- package/src/RTCRtpTransceiver.ts +107 -107
- package/src/RTCSessionDescription.ts +30 -30
- package/src/RTCTrackEvent.ts +42 -42
- package/src/RTCUtil.ts +211 -211
- package/src/RTCView.ts +122 -122
- package/src/RTCView.web.tsx +80 -80
- package/src/ScreenCapturePickerView.ts +4 -4
- package/src/ScreenCapturePickerView.web.tsx +3 -3
- package/src/getDisplayMedia.ts +30 -30
- package/src/getUserMedia.ts +136 -111
- package/src/index.ts +107 -107
- package/src/index.web.ts +191 -191
- package/src/webStream.ts +31 -31
- package/tools/format.sh +6 -6
- package/tools/release.sh +45 -45
- package/tsconfig.json +17 -17
|
@@ -1,338 +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
|
-
}
|
|
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
|
+
}
|