예전에 본 것 같긴한데 해본적은 없는 것 같아서 검색
[링크 : https://velog.io/@davelee/browser에서-webcam-이용하기]
const constraints = { audio: true, video: { width: 1280, height: 720 }, };
navigator.mediaDevices .getUserMedia(constraints) .then((mediaStream) => { const video = document.querySelector("video"); video.srcObject = mediaStream; video.onloadedmetadata = () => { video.play(); }; }) .catch((err) => { // always check for errors at the end. console.error(`${err.name}: ${err.message}`); }); |
[링크 : https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia]
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia) { navigator.getUserMedia( { audio: true, video: { width: 1280, height: 720 } }, (stream) => { const video = document.querySelector("video"); video.srcObject = stream; video.onloadedmetadata = (e) => { video.play(); }; }, (err) => { console.error(`The following error occurred: ${err.name}`); }, ); } else { console.log("getUserMedia not supported"); }
|
[링크 : https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia] deprecated