twilio-video.js icon indicating copy to clipboard operation
twilio-video.js copied to clipboard

Switching between front and rear cameras requires stopping current track in some scenarios

Open loganathanav opened this issue 2 years ago • 4 comments

I'm using 2.27.0, still the issue exist. Is there any work arounds to overcome this issue. I'm trying to catch and trying createLocalVideoTrak to have new track. That also not working.

if (isApplePhone) { room?.localParticipant?.videoTracks.forEach( (publication) => { publication.track.stop(); publication.track.restart({ facingMode: 'environment' }); } ); } else if (isAndroidPhone) { room?.localParticipant?.videoTracks.forEach( async (publication) => { publication.track.stop(); await publication.track.restart({ facingMode: 'environment', }); } ); }

Team, please confirm whether we need to use async/await or not inside forEach loop here? also, do we need to use stop() function in iPhone as well or not required?

Getting error in browser. Provide your suggestions, I'm struck here.

loganathanav avatar Sep 13 '23 17:09 loganathanav

@loganathanav ,

Thanks for writing in with your issue. You don't need to call stop() before calling restart(). Also, it is better to await on the Promise returned by restart(). Hope this helps.

manjeshbhargav avatar Sep 18 '23 14:09 manjeshbhargav

Hi @manjeshbhargav,

Thanks for your inputs. Tried without stop() in Samsung mobiles and when we switch camera it was not switching properly. As workaround I've added stop() before calling restart() for android mobiles.

I've to verify iPhone devices with await on the restart().

All works fine for the first time. Whenever we switch the cameras for the second time in Samsung mobiles getting "DOMException: Could not start video source" error in console and the screen becomes black.

loganathanav avatar Sep 20 '23 11:09 loganathanav

Hi @manjeshbhargav,

Any ideas?

loganathanav avatar Oct 10 '23 15:10 loganathanav

Hey @loganathanav I've run into this issue extensively before. We realized that we were asking for permissions twice. Once through getUserMedia() and another through createLocalTracks(). Didn't realize that createLocalTracks() also asks for permissions. Not sure if related to your issue but hope it helps,

mrmandarin2002 avatar Oct 25 '23 14:10 mrmandarin2002