Detecting Device Changes

Great. You have built a few solid mechanisms to act on what devices are available when your app loads, and you’ll save your application from throwing TypeErrors by ensuring getUserMedia() is never called with a ham-fisted set of constraints when there’s no mic or camera available. You’re now also only adding tracks to $self.mediaStream when an available device has returned them.

But there are other cases of device ability to think about: external mics and cameras can have their cords unplugged by feral toddlers or vengeful cats, or be plugged back in if they were unplugged previously. Wireless media inputs can have their connections drop and reconnect, too.

Enter the devicechange event, which fires whenever a device ...

Get Programming WebRTC now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.