opentok-react-native icon indicating copy to clipboard operation
opentok-react-native copied to clipboard

cameraPosition not working

Open simdanonline opened this issue 5 years ago • 5 comments

It still shows front camera, even though it is set to back ```

const [audio, setAudio] = useState(true)
const publisherProperties  = {
       publishAudio: audio,
        cameraPosition: 'back'

    };

const toggle = () => {
    if (audio) {
        setAudio(false);
    }
    else {
        setAudio(true)
    }

}




    <View style={styles.container}>
        <View style={{ flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'flex-start' }} >
            <OTSession apiKey={apiKey} sessionId={sessionId} token={token} eventHandlers={sessionEventHandlers}>
                <OTPublisher style={{ width: 500, height: height }} properties={publisherProperties} />
            </OTSession>
        </View>
**Please post usage questions or broader discussions on [StackOverflow](https://stackoverflow.com/questions/ask?tags=opentok+react-native)**.

---

For **feature requests**, please fill out the [feature request template](https://github.com/opentok/opentok-react-native/issues/new?template=feature_request.md)

---

For **bug reports**, please fill out the [bug report issue template](https://github.com/opentok/opentok-react-native/issues/new?template=bug.md)

simdanonline avatar Feb 22 '20 18:02 simdanonline

The correct options are facingMode: "environment" or "user". The former is the back one, the latter is the frontal one.

https://tokbox.com/developer/sdks/js/reference/OT.html#initPublisher

enricop89 avatar Mar 26 '20 15:03 enricop89

I have the same issue. Is clear where the issue comes from:

android/src/main/java/com/opentokreactnative/OTSessionManager.java


    @ReactMethod
    public void initPublisher(String publisherId, ReadableMap properties, Callback callback) {

        String name = properties.getString("name");
        Boolean videoTrack = properties.getBoolean("videoTrack");
        Boolean audioTrack = properties.getBoolean("audioTrack");
        String cameraPosition = properties.getString("cameraPosition");
        Boolean audioFallbackEnabled = properties.getBoolean("audioFallbackEnabled");
        int audioBitrate = properties.getInt("audioBitrate");
        String frameRate = "FPS_" + properties.getInt("frameRate");
        String resolution = properties.getString("resolution");
        Boolean publishAudio = properties.getBoolean("publishAudio");
        Boolean publishVideo = properties.getBoolean("publishVideo");
        String videoSource = properties.getString("videoSource");
        Publisher mPublisher = null;
        if (videoSource.equals("screen")) {
            View view = getCurrentActivity().getWindow().getDecorView().getRootView();
            OTScreenCapturer capturer = new OTScreenCapturer(view);
            mPublisher = new Publisher.Builder(this.getReactApplicationContext())
                    .audioTrack(audioTrack)
                    .videoTrack(videoTrack)
                    .name(name)
                    .audioBitrate(audioBitrate)
                    .resolution(Publisher.CameraCaptureResolution.valueOf(resolution))
                    .frameRate(Publisher.CameraCaptureFrameRate.valueOf(frameRate))
                    .capturer(capturer)
                    .build();
            mPublisher.setPublisherVideoType(PublisherKit.PublisherKitVideoType.PublisherKitVideoTypeScreen);
        } else {
            mPublisher = new Publisher.Builder(this.getReactApplicationContext())
                    .audioTrack(audioTrack)
                    .videoTrack(videoTrack)
                    .name(name)
                    .audioBitrate(audioBitrate)
                    .resolution(Publisher.CameraCaptureResolution.valueOf(resolution))
                    .frameRate(Publisher.CameraCaptureFrameRate.valueOf(frameRate))
                    .build();
            if (cameraPosition.equals("back")) {
                mPublisher.cycleCamera();
            }
        }
        mPublisher.setPublisherListener(this);
        mPublisher.setAudioLevelListener(this);
        mPublisher.setAudioFallbackEnabled(audioFallbackEnabled);
        mPublisher.setPublishVideo(publishVideo);
        mPublisher.setPublishAudio(publishAudio);
        ConcurrentHashMap<String, Publisher> mPublishers = sharedState.getPublishers();
        mPublishers.put(publisherId, mPublisher);
        callback.invoke();
    }

As you can see:

            if (cameraPosition.equals("back")) {
                mPublisher.cycleCamera();
            }

The initPublisher method doesn't accept the facingMode parameter.

Using cameraPosition only triggers a cycleCamera() and will fail picking the correct camera if the device has more than two cameras. I'm working in a PR

LuuchoRocha avatar Jun 18 '21 05:06 LuuchoRocha

the issues is still there, any update?

2021-10-14 at 11 38 AM

radjivF avatar Oct 14 '21 03:10 radjivF

Thanks for reporting this. This is currently not supported at the native level so there is nothing we can do. I've already mentioned it to our Engineering team. I will leave this issue open for tracking purposes

enricop89 avatar Oct 14 '21 10:10 enricop89

Thanks for reporting this. This is currently not supported at the native level so there is nothing we can do. I've already mentioned it to our Engineering team. I will leave this issue open for tracking purposes

@enricop89 Any update?

NAVEENCHVSPOP avatar Mar 17 '22 11:03 NAVEENCHVSPOP