philnash/mediadevices-camera-selection

Switching camera in mobile Safari sometimes causes remote side to lose video

Closed this issue · 3 comments

Sometimes, not always, when switching cameras the remote side loses video. The issue is intermittently reproducible after a few tries usually. On remote side I get a 'trackUnsubscribed' but then never get the 'trackSubscribed' event that should come right after that for the new camera video. Remote side can be another iOS device or an Android device, only seems to matter that the side switching cameras is iOS Safari. This is reproducible in the quickstart code from the repository running as is with no modifications. I first ran into this with app we're developing based on the quickstart code. Seems like it is either a bug in twilio-video.js or maybe Safari.

Happens in these iOS version so far:
iOS 13.3.1
iOS 13.4.1

I think someone else has reported this before and I couldn't reproduce it. They later came back to say that creating a delay between stopping the previous video and starting the new one solved it for them.

I know a timeout is not the best result here, but I don't know anything more about the issue myself I'm afraid. It may be an issue with iOS Safari and the fact that it doesn't allow for access to more than one camera at a time.

Let me know if putting a delay in helps.

Adding a timeout as suggested does seem to mitigate the problem so that it doesn't occur in my testing so far.

I'm surprised you can't reproduce it. It happens with every iOS device we've tested with so far, iPhone 11 Pro, iPhone XS and an iPad, all are running versions of iOS 13. It usually requires switching the camera 3 or 4 times or so before it happens, but sometimes it happens the first time.

Some more details, I listen for remote participant 'trackPublished' event and that fires every time. I also listen for publication 'subscribed' event and it doesn't fire when the issue occurs, it always fires when things work. So the remote track is getting published, but not subscribed to. However, if the local user also switches cameras a while after the issue happens, then usually that subscribe event that didn't happen will fire and the remote video will come back. Not sure what switching your local camera would do that would cause that remote subscribe to go ahead and fire.

Also, there are never any errors thrown in the debug console on either side.

Hey, the video team had actually been looking into this and there was an issue in track negotiaton. They have worked on and merged a fix here and it looks like it will be in the next release, 2.5.0. Hopefully the timeout will help for now, but make sure to upgrade as soon as you can to get the latest.