Skip to content

Commit

Permalink
Merge pull request #145 from open-voip-alliance/fix/enumerate-device-…
Browse files Browse the repository at this point in the history
…polling

fix: listen to ondevicechange instead of polling for device changes
  • Loading branch information
timon-voys authored Dec 12, 2023
2 parents a2afe59 + 95f8a1a commit 25c33fb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class MediaSingleton extends EventEmitter implements IMediaDevices {

public init() {
this.update();

navigator.mediaDevices.ondevicechange = () => {
this.update();
};
}

get devices() {
Expand Down Expand Up @@ -161,13 +165,6 @@ class MediaSingleton extends EventEmitter implements IMediaDevices {
}

this.hadPermission = havePermission;

// When running on localhost in Firefox, the permission can't be stored
// (unless over https). The timer will clear the devices list on the next
// timeout. Prevent this behaviour because it's annoying to develop with.
if (!(Features.isFirefox && Features.isLocalhost)) {
this.timer = window.setTimeout(() => this.update(), UPDATE_INTERVAL);
}
}

private updateDevices(enumeratedDevices: MediaDeviceInfo[]) {
Expand Down

0 comments on commit 25c33fb

Please sign in to comment.