Skip to content

Commit

Permalink
refresh video inputs if no device id
Browse files Browse the repository at this point in the history
  • Loading branch information
yamaha252 committed Nov 30, 2020
1 parent 94ef5a7 commit ca16297
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/modules/webcam/util/webcam.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ export class WebcamUtil {

private static availableVideoInputs: MediaDeviceInfo[] = [];

static hasVideoInputs() {
const inputs = WebcamUtil.availableVideoInputs;
return !!inputs.find(input => !!input.deviceId);
}

/**
* Lists available videoInput devices
* @returns a list of media device info.
Expand All @@ -11,7 +16,7 @@ export class WebcamUtil {
throw new Error('enumerateDevices() not supported.');
}

if (!WebcamUtil.availableVideoInputs.length) {
if (!this.hasVideoInputs()) {
const devices = await navigator.mediaDevices.enumerateDevices();
WebcamUtil.availableVideoInputs = devices.filter((device: MediaDeviceInfo) => device.kind === 'videoinput');
}
Expand Down

0 comments on commit ca16297

Please sign in to comment.