我如何在纯 js 中停止和退出,在 WEBRTC api js 中流式传输网络摄像头,我的代码中有以下脚本:
<script type="text/javascript">
$(document).ready(function() {
$("#abrirModal").click(function() {
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = {
audio: false,
video: true
};
var live = document.getElementById("live");
function successCallback(stream) {
window.stream = stream; // stream available to console
if (window.URL) {
live.src = window.URL.createObjectURL(stream);
} else {
live.src = stream;
}
$("#myModal").modal("show");
window.setTimeout(function() {
$("#myModal").modal("hide");
}, 9000);
}
function errorCallback(error) {
console.log("navigator.getUserMedia error: ", error);
}
navigator.getUserMedia(constraints, successCallback, errorCallback);
});
});
</script>
如何在其他 file.js 中关闭和退出网络摄像头,例如:
function exitWebCam () {
document.getElementById("live")."close the web cam";
}