-1
我正在構建需要通過瀏覽器訪問用戶視頻的軟件,我正在使用WebRTC。使用WebRTC捕獲用戶的圖像
在我的工作目錄存在: 的package.json
{
"name": "intro-webrtc",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "4.x",
"ejs": "2.x"
}
}
server.js
var express = require('express');
var app = express() ;
console.log('server started');
app.get('/',function(req,res){
res.render('index.ejs') ;
})
app.listen(3000)
視圖/ index.ejs
<!doctype html>
<html lang="en">
<head>
<title> Introduction to WebRTC </title>
</head>
<body>
<video autoplay></video>
<script>
navigator.getUserMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
var constraints = {audio: true, video: true}
var videoArea = document.querySelector{"video"};
navigator.getUserMedia(constraints, onSuccess, onError);
function onSuccess(stream) {
console.log("Sucess! We have a stream!");
videoArea.src = window.URL.createObjectURL(stream);
videoArea.play() ;
}
function onError(error) {
console.log("Error with getUserMedia: ", error);
}
</script>
</body>
</html>
當試圖訪問http://localhost:3000/時,頁面似乎不是要求麥克風或視頻訪問,因此我不捕獲用戶的媒體。我使用Google Chrome。你能幫我,告訴我問題在哪裏,它可以修復嗎?
在此先感謝。
非常感謝你。我的錯。問題解決了,我現在可以捕捉用戶的視頻。 – YAS