UNPKG

@rksan/mock-media-devices

Version:

WebAPI window.navigator.mediaDevices のモック

58 lines (57 loc) 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEntriesForAll = void 0; const utils_1 = require("../utils"); const createEntriesForAll = (kind, infos) => { return [ { keys: [{ name: "deviceId", default: "" }], type: "string", value(def, val) { if (!val) { let deviceId = ""; if (kind === "video") { const videos = infos.filter((info) => info.kind === "videoinput"); if (0 < videos.length) { deviceId = videos[0].deviceId; } } else { const audios = infos.filter((info) => info.kind === "audioinput" || info.kind === "audiooutput"); if (0 < audios.length) { deviceId = audios[0].deviceId; } } return deviceId; } else { return (0, utils_1.getConstrainDOMStringValue)(def, val); } }, }, { keys: [{ name: "groupId", default: "" }], type: "string", value: (def, val) => { if (!val) { let groupId = ""; if (kind === "video") { const videos = infos.filter((info) => info.kind === "videoinput"); if (0 < videos.length) groupId = videos[0].groupId; } else { const audios = infos.filter((info) => info.kind === "audioinput" || info.kind === "audiooutput"); if (0 < audios.length) groupId = audios[0].groupId; } return groupId; } else { return (0, utils_1.getConstrainDOMStringValue)(def, val); } }, }, ]; }; exports.createEntriesForAll = createEntriesForAll;