A.Blanc
A.Blanc

Reputation: 433

How can I detect that a device change as unplugged headphones from laptop - chrome

I am using navigator.mediaDevices.enumerateDevices() to list the available devices for a call (implemented using webRTC).

I need to be able to detect when headphones are unpluged/pluged.

Any ideas how can I fix this?

Upvotes: 0

Views: 872

Answers (2)

Philipp Hancke
Philipp Hancke

Reputation: 17360

If the currently used devices gets unplugged, the MediaStreamTrack's onended callback should fire. If that happens call enumerateDevices again.

Upvotes: 1

A.Blanc
A.Blanc

Reputation: 433

Using MediaDevices.ondevicechange and enable "Experimental Web Platform features" as seen on similar answered questions.

Upvotes: 1

Related Questions