Detect webcams unplugged
This commit is contained in:
parent
9aeb18df37
commit
b04c438d6f
@ -209,10 +209,14 @@ function createVideoConstraintStore() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
setDeviceId: (deviceId: string) => update((constraints) => {
|
setDeviceId: (deviceId: string|undefined) => update((constraints) => {
|
||||||
|
if (deviceId !== undefined) {
|
||||||
constraints.deviceId = {
|
constraints.deviceId = {
|
||||||
exact: deviceId
|
exact: deviceId
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
delete constraints.deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
return constraints;
|
return constraints;
|
||||||
}),
|
}),
|
||||||
@ -241,15 +245,19 @@ function createAudioConstraintStore() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
setDeviceId: (deviceId: string) => update((constraints) => {
|
setDeviceId: (deviceId: string|undefined) => update((constraints) => {
|
||||||
selectedDeviceId = deviceId;
|
selectedDeviceId = deviceId;
|
||||||
|
|
||||||
if (typeof(constraints) === 'boolean') {
|
if (typeof(constraints) === 'boolean') {
|
||||||
constraints = {}
|
constraints = {}
|
||||||
}
|
}
|
||||||
|
if (deviceId !== undefined) {
|
||||||
constraints.deviceId = {
|
constraints.deviceId = {
|
||||||
exact: selectedDeviceId
|
exact: selectedDeviceId
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
delete constraints.deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
return constraints;
|
return constraints;
|
||||||
})
|
})
|
||||||
@ -552,3 +560,35 @@ export const cameraListStore = derived(deviceListStore, ($deviceListStore) => {
|
|||||||
export const microphoneListStore = derived(deviceListStore, ($deviceListStore) => {
|
export const microphoneListStore = derived(deviceListStore, ($deviceListStore) => {
|
||||||
return $deviceListStore.filter(device => device.kind === 'audioinput');
|
return $deviceListStore.filter(device => device.kind === 'audioinput');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: detect the new webcam and automatically switch on it.
|
||||||
|
cameraListStore.subscribe((devices) => {
|
||||||
|
// If the selected camera is unplugged, let's remove the constraint on deviceId
|
||||||
|
const constraints = get(videoConstraintStore);
|
||||||
|
if (!constraints.deviceId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we cannot find the device ID, let's remove it.
|
||||||
|
// @ts-ignore
|
||||||
|
if (!devices.find(device => device.deviceId === constraints.deviceId.exact)) {
|
||||||
|
videoConstraintStore.setDeviceId(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
microphoneListStore.subscribe((devices) => {
|
||||||
|
// If the selected camera is unplugged, let's remove the constraint on deviceId
|
||||||
|
const constraints = get(audioConstraintStore);
|
||||||
|
if (typeof constraints === 'boolean') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!constraints.deviceId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we cannot find the device ID, let's remove it.
|
||||||
|
// @ts-ignore
|
||||||
|
if (!devices.find(device => device.deviceId === constraints.deviceId.exact)) {
|
||||||
|
audioConstraintStore.setDeviceId(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user