@@ -39,7 +39,7 @@ import {
3939import { startCallService , stopCallService } from './callservice/CallService' ;
4040import Toast from 'react-native-toast-message' ;
4141
42- import { Track } from 'livekit-client' ;
42+ import { LocalVideoTrack , Track } from 'livekit-client' ;
4343
4444export const RoomPage = ( {
4545 navigation,
@@ -160,6 +160,7 @@ const RoomView = ({ navigation, e2ee }: RoomViewProps) => {
160160 isMicrophoneEnabled,
161161 isScreenShareEnabled,
162162 localParticipant,
163+ cameraTrack,
163164 } = useLocalParticipant ( ) ;
164165
165166 // Prepare for iOS screenshare.
@@ -192,6 +193,10 @@ const RoomView = ({ navigation, e2ee }: RoomViewProps) => {
192193 localParticipant . setCameraEnabled ( enabled ) ;
193194 } }
194195 switchCamera = { async ( ) => {
196+ if ( ! cameraTrack ) {
197+ return ;
198+ }
199+
195200 let facingModeStr = ! isCameraFrontFacing ? 'front' : 'environment' ;
196201 setCameraFrontFacing ( ! isCameraFrontFacing ) ;
197202
@@ -209,12 +214,17 @@ const RoomView = ({ navigation, e2ee }: RoomViewProps) => {
209214 }
210215 }
211216
212- if ( newDevice == null ) {
217+ if ( ! newDevice ) {
213218 return ;
214219 }
215220
216- //@ts -ignore
217- await room . switchActiveDevice ( 'videoinput' , newDevice . deviceId ) ;
221+ const localCameraTrack = cameraTrack . videoTrack ;
222+ if ( localCameraTrack instanceof LocalVideoTrack ) {
223+ localCameraTrack . restartTrack ( {
224+ deviceId : newDevice . deviceId ,
225+ facingMode : facingModeStr ,
226+ } ) ;
227+ }
218228 } }
219229 screenShareEnabled = { isScreenShareEnabled }
220230 setScreenShareEnabled = { ( enabled : boolean ) => {
0 commit comments