-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