react-native-twilio-video-webrtc icon indicating copy to clipboard operation
react-native-twilio-video-webrtc copied to clipboard

Camera1Enumerator does not find front or back cameras in buildDeviceInfo

Open bhaskarmurthy opened this issue 3 years ago • 6 comments

The following twilio component is mounted in my component:

                <TwilioVideo
                    ref={handleTwilioVideoRef}
                    onRoomDidConnect={handleRoomDidConnect}
                    onRoomDidDisconnect={handleRoomDidDisconnect}
                    onRoomDidFailToConnect={event => {
                        console.error(event.error) // This error happens on JS side
                       handleRoomDidFailToConnect(event.error)
                    }}
                    onRoomParticipantDidConnect={handleRoomParticipantDidConnect}
                    onRoomParticipantDidDisconnect={handleRoomParticipantDidDisconnect}
                    onParticipantAddedVideoTrack={handleParticipantAddedVideoTrack}
                    onParticipantRemovedVideoTrack={handleParticipantRemovedVideoTrack}
                    onParticipantEnabledVideoTrack={handleParticipantEnabledVideoTrack}
                    onParticipantDisabledVideoTrack={handleParticipantDisabledVideoTrack}
                />

Steps to reproduce

  1. Start Twilio video
  2. Somehow TOGGLE_VIDEO command is called immediately on native side
  3. in buildDeviceInfo, Camera1Enumerator successfully gets devices

Expected behaviour

The following device names are found:

Camera 0, Facing back, Orientation 90
Camera 1, Facing front, Orientation 270

enumerator.isBackFacing should resolve to Camera 0 enumerator.isFrontFacing should resolve to Camera 1

Actual behaviour

enumerator.isBackFacing and enumerator.isFrontFacing never resolved to any of the provided device names

Environment

  • Node.js version: 14.17.0
  • React Native version: 0.61.4
  • React Native platform + platform version: Android 12 (Pixel 4a)

react-native-twilio-video-webrtc

Version: master

bhaskarmurthy avatar Aug 19 '21 05:08 bhaskarmurthy

Update

I tried updating CustomTwilioVideo.java by replacing all instances/uses of the Camera1 apis with Camera2 and was successfully able to get local and remote video working on my Pixel 4a (Android 30)

Line 39
import com.twilio.video.Camera2Capturer;

Line 193
    private static Camera2Capturer cameraCapturer;

Line 268
                        @Override
                        public void onError(@NonNull Camera2Capturer.Exception camera2CapturerException) {
                            Log.i("CustomTwilioVideoView", "Error getting camera");
                            Log.i("CustomTwilioVideoView", camera2CapturerException.getMessage(), camera2CapturerException);
                        }


Line 282
        Camera2Enumerator enumerator = new Camera2Enumerator(getContext());

bhaskarmurthy avatar Aug 19 '21 06:08 bhaskarmurthy

Should we adopt the CameraCompat class from twilio android example repo to do this in a more robust way?

bhaskarmurthy avatar Aug 19 '21 06:08 bhaskarmurthy

oof, of course android has multiple camera apis inconsistently implemented across versions / devices. Yeah, I think the cameracompat class will be needed. Sounds like this is something you already have a bead on, how would you feel about working on the PR?

slycoder avatar Aug 19 '21 07:08 slycoder

Also thanks for all of your investigation so far, it's been really helpful and insightful!

slycoder avatar Aug 19 '21 07:08 slycoder

@slycoder for sure - I have a working CameraCompat port over from the twilio android example repo in my branch. Will fork/create PR and send it your way

bhaskarmurthy avatar Aug 20 '21 15:08 bhaskarmurthy

That is awesome, thank you so much!

slycoder avatar Aug 21 '21 14:08 slycoder