mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
add webcam and microphone detection
This commit is contained in:
parent
45fb3ebb92
commit
8eaabdd0e5
@ -43,6 +43,8 @@
|
|||||||
<p>Frame rate: ${browser_check_data.vsync_rate}</p>
|
<p>Frame rate: ${browser_check_data.vsync_rate}</p>
|
||||||
<p>WebAudio API support: ${browser_check_data.webaudio}</p>
|
<p>WebAudio API support: ${browser_check_data.webaudio}</p>
|
||||||
<p>Fullscreen API support: ${browser_check_data.fullscreen}</p>
|
<p>Fullscreen API support: ${browser_check_data.fullscreen}</p>
|
||||||
|
<p>Webcam support: ${browser_check_data.webcam}</p>
|
||||||
|
<p>Microphone support: ${browser_check_data.microphone}</p>
|
||||||
`
|
`
|
||||||
return html;
|
return html;
|
||||||
},
|
},
|
||||||
|
@ -20,6 +20,8 @@ const info = <const>{
|
|||||||
"os",
|
"os",
|
||||||
"fullscreen",
|
"fullscreen",
|
||||||
"vsync_rate",
|
"vsync_rate",
|
||||||
|
"webcam",
|
||||||
|
"microphone",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -209,6 +211,40 @@ class BrowserCheckPlugin implements JsPsychPlugin<Info> {
|
|||||||
requestAnimationFrame(start);
|
requestAnimationFrame(start);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
webcam: () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
||||||
|
const webcams = devices.filter((d) => {
|
||||||
|
return d.kind == "videoinput";
|
||||||
|
});
|
||||||
|
if (webcams.length > 0) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
microphone: () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
navigator.mediaDevices.enumerateDevices().then((devices) => {
|
||||||
|
const microphones = devices.filter((d) => {
|
||||||
|
return d.kind == "audioinput";
|
||||||
|
});
|
||||||
|
if (microphones.length > 0) {
|
||||||
|
resolve(true);
|
||||||
|
} else {
|
||||||
|
resolve(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user