我正在尝试使用webrtc构建一个简单的视频聊天服务。我指的是介绍webrtc基础的html5rocks文章中给出的教程.. [http://www.html5rocks.com/en/tutorials/webrtc/basics/] [1]
server.js 在localhost 上使用node-static 工作正常,并提供完美的视频流和聊天服务。问题是当我尝试时在heroku上托管它 ..视频流不起作用或者我应该说没有server.js的功能工作..浏览器窗口只显示一个文本框,这是我的index.html文件的基本布局..所以在我的代码中确实存在一些问题。在server.js文件中缺少某些东西,这是在heroku上托管所必需的。这是Server.js的代码。请帮我解决问题。告诉我正确的托管它的方式因为我知道我在这里遗漏了一些东西..
var static = require('node-static');
/*var http = require('http');
var file = new(static.Server)();
var app = http.createServer(function (req, res) {
file.serve(req, res);
}).listen(2013);
*/
var express = require('express');
var app = express();
console.log(express.static(__dirname + '/js'));
app.use(express.static(__dirname + '/js'));
app.all('*', function(req, res){
res.sendfile("index.html");
});
app.listen(9000);
var io = require('socket.io').listen(app);
io.sockets.on('connection', function (socket){
function log(){
var array = [">>> "];
for (var i = 0; i < arguments.length; i++) {
array.push(arguments[i]);
}
socket.emit('log', array);
}
socket.on('message', function (message) {
log('Got message: ', message);
socket.broadcast.emit('message', message); // should be room only
});
socket.on('create or join', function (room) {
var numClients = io.sockets.clients(room).length;
log('Room ' + room + ' has ' + numClients + ' client(s)');
log('Request to create or join room', room);
if (numClients == 0){
socket.join(room);
socket.emit('created', room);
} else if (numClients == 1) {
io.sockets.in(room).emit('join', room);
socket.join(room);
socket.emit('joined', room);
} else { // max two clients
socket.emit('full', room);
}
socket.emit('emit(): client ' + socket.id + ' joined room ' + room);
socket.broadcast.emit('broadcast(): client ' + socket.id + ' joined room ' + room);
});
});