# How to Switch Camera while a call is active based on a flag value?

**URL:** <https://react-native-webrtc.discourse.group/t/how-to-switch-camera-while-a-call-is-active-based-on-a-flag-value/1598>\
**Category:** General\
**Created:** [August 19, 2022, 7:23am UTC](https://react-native-webrtc.discourse.group/t/how-to-switch-camera-while-a-call-is-active-based-on-a-flag-value/1598 "2022-08-19T07:23:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhradeep2198](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@subhradeep2198](https://react-native-webrtc.discourse.group/u/subhradeep2198)\
**Post date:** [August 19, 2022, 7:23am UTC](https://react-native-webrtc.discourse.group/t/how-to-switch-camera-while-a-call-is-active-based-on-a-flag-value/1598/1 "2022-08-19T07:23:23Z")

</div>

I am making an App using React Native and react-native-webrtc. And I want to implement a feature where after connecting the call, I want to switch the camera from front to back and vice-versa based on a boolean flag value. If the value is true then the front camera will be used and if false then back camera will be used. Seems that only changing the facing mode updates the local stream and not the remote stream of the user connected with. Can anyone tell me how to solve this ?

---

<div class="post-metadata">

**Author:** ![subhradeep2198](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@subhradeep2198](https://react-native-webrtc.discourse.group/u/subhradeep2198)\
**Post date:** [August 19, 2022, 7:47am UTC](https://react-native-webrtc.discourse.group/t/how-to-switch-camera-while-a-call-is-active-based-on-a-flag-value/1598/2 "2022-08-19T07:47:08Z")

</div>

(Solved) : After going about it for quite some I finally found a solution. I hope that would help anyone else facing the problem. Instead of toggling the facing mode based on a boolean value, I created a function toggleCamera which switches the camera without the requirement for renegotiation. I replaced the existing Stream Track with the new Track as follows 🙂

```auto
const toggleCamera = () => {
        localStream.getVideoTracks().forEach((track) => {
            console.log('sc',track);
            track._switchCamera();
        })
 }

```

---

<div class="post-metadata">

**Author:** ![8BallBomBom](https://yyz2.discourse-cdn.com/free1/user_avatar/react-native-webrtc.discourse.group/8ballbombom/32/710_2.png) [@8BallBomBom](https://react-native-webrtc.discourse.group/u/8BallBomBom)\
**Post date:** [September 3, 2022, 11:37am UTC](https://react-native-webrtc.discourse.group/t/how-to-switch-camera-while-a-call-is-active-based-on-a-flag-value/1598/3 "2022-09-03T11:37:12Z")

</div>

We’ve now got a handbook over [here](https://react-native-webrtc.github.io/handbook/) which has some useful code samples.  
In time there will also be full blown example projects.
