@jellyfish-dev/react-client-sdk
Version:
React client library for Jellyfish.
22 lines (21 loc) • 905 B
JavaScript
export const PERMISSION_DENIED = { name: "NotAllowedError" };
export const OVERCONSTRAINED_ERROR = { name: "OverconstrainedError" };
export const NOT_FOUND_ERROR = { name: "NotFoundError" };
export const UNHANDLED_ERROR = { name: "UNHANDLED_ERROR" };
// https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#exceptions
// OverconstrainedError has higher priority than NotAllowedError
export const parseError = (error) => {
if (error && typeof error === "object" && "name" in error) {
if (error.name === "NotAllowedError") {
return PERMISSION_DENIED;
}
else if (error.name === "OverconstrainedError") {
return OVERCONSTRAINED_ERROR;
}
else if (error.name === "NotFoundError") {
return NOT_FOUND_ERROR;
}
}
console.warn({ name: "Unhandled getUserMedia error", error });
return null;
};