Description
I’m trying to implement a virtual camera by overriding MediaDevices.prototype.enumerateDevices and MediaDevices.prototype.getUserMedia. I’m able to successfully switch to the virtual camera within Zoom. However, when I attempt to switch back to the physical (built-in) camera, I receive the following error. I have confirmed that the device ID I’m trying to switch to is valid — it was obtained from a call to enumerateDevices() .
Browser Console Error
Error: {"type":"CAN_NOT_FIND_CAMERA","reason":"cannot find target camera"}
Which Web Video SDK version?
2.1.0
Video SDK Code Snippets
Here are the override implementations I’m using for enumerateDevices and getUserMedia to simulate a virtual camera:
const enumerateDevicesFn = navigator.mediaDevices.enumerateDevices.bind(navigator.mediaDevices);
const getUserMediaFn = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
MediaDevices.prototype.enumerateDevices = async function () {
const res = await enumerateDevicesFn.call(navigator.mediaDevices);
let dv = VIRTUAL_DEVICE;
dv = { ...dv, toJSON: () => dv }; // Ensure toJSON method is available
res.push(dv);
return res
}
MediaDevices.prototype.getUserMedia = async function (...args) {
if (args.length && args[0].video && args[0].video.deviceId) {
if (
args[0].video.deviceId === VIRTUAL_DEVICE.deviceId ||
args[0].video.deviceId.exact === VIRTUAL_DEVICE.deviceId
) {
const constraints = {
video: { ...(args?.video ?? {}) },
audio: false
}
const res = await getUserMediaFn.call(
navigator.mediaDevices,
constraints
)
const canvas = document.getElementById(AVATAR_CANVAS_ID)
if (res && canvas) {
return canvas.captureStream(30)
}
}
}
const res = await getUserMediaFn.call(navigator.mediaDevices, ...args);
return res;
}
To Reproduce
- Join a Zoom Video SDK session.
- Start the session using a real physical camera (works as expected).
- Switch to the virtual camera (also works).
- Attempt to switch back to the physical camera.
- Observe the error:
Error: {"type":"CAN_NOT_FIND_CAMERA","reason":"cannot find target camera"}
Screenshots
If applicable, add screenshots to help explain your problem.
Device :
- Device: MacBook Pro (Apple Silicon)
- OS: macOS (Sonoma)
- Browser: Chrome
- Browser Version: 137.0.6482.114 (Official Build) (arm64)
Session ID :
4OoNSCdnRRSq3GeJfQzaxA==