Node.js Express中的WebRTC
我有一个HTML文件,它与上使用的示例相同 但当我尝试将其放入express服务器时,它无法工作。这是我的密码: index.jsNode.js Express中的WebRTC,node.js,express,webrtc,Node.js,Express,Webrtc,我有一个HTML文件,它与上使用的示例相同 但当我尝试将其放入express服务器时,它无法工作。这是我的密码: index.js var express = require('express') var app = express() app.get('/home', function(req,res){ res.sendfile(__dirname + '/public/home.html'); }); app.listen(4000) console.log("App listen
var express = require('express')
var app = express()
app.get('/home', function(req,res){
res.sendfile(__dirname + '/public/home.html');
});
app.listen(4000)
console.log("App listening on port 4000");
home.html
<!DOCTYPE html>
<html>
<head>
<script src="//simplewebrtc.com/latest.js"></script>
<script>
var webrtc = new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localVideo',
// the id/element dom element that will hold remote videos
remoteVideosEl: 'remotesVideos',
// immediately ask for camera access
autoRequestMedia: true
});
// we have to wait until it's ready
webrtc.on('readyToCall', function () {
// you can name it anything
webrtc.joinRoom('your awesome room name');
});
</script>
</head>
<body>
<video height="300" id="localVideo"></video>
<div id="remotesVideos"></div>
</body>
</html>
var webrtc=新的SimpleWebRTC({
//将保存“我们的”视频的id/element dom元素
localVideoEl:“localVideo”,
//将保存远程视频的id/element dom元素
remoteVideosEl:“remotesVideos”,
//立即要求进入摄像机
自动请求媒体:正确
});
//我们必须等到它准备好
webrtc.on('readyToCall',函数(){
//你可以给它起任何名字
webrtc.joinRoom(“你的好房间名”);
});
尝试更改沙盒信令服务器的url,如中所示
在不同的端口上运行服务器会导致问题,因为默认url不包括信令服务器的端口,因此它将尝试连接到信令。simplewebrtc.com:4000,那里没有任何应答。它需要与类似-
https://github.com/andyet/signalmaster
,我想这不是一个简单的express应用程序。真的吗?那么为什么在简单的apache服务器上运行HTML文件有效呢?我在您的express应用程序中没有找到任何特定于套接字的代码。当WebRTC工作时,它们也需要从服务器上实现。根据定义,ApacheWeb服务器
和node.js
Web服务器是不同的。@PiyasDe我认为这里的问题是CORS,在webrtc
中,服务器几乎是不相关的……服务器需要发送信号,有时在特殊情况下需要转弯/眩晕。