I'm trying to run Step 5 from the WebRTC codelab, but I am encountering errors. I'm using node.js and I ran the commands to install node-static and socket.io. When I try to run the demo, the popup opens to enter a room name, but when I click on "OK" I get the following errors.
From Chrome Dev Tools: http://i1200.photobucket.com/albums/bb338/LiquidFlame/devtools_error_zps45bfa2a7.jpg
From cmd: http://i1200.photobucket.com/albums/bb338/LiquidFlame/cmd_error_zps636925a1.png
I'm very new to node.js and socket.io and I'm not sure what's going on. Any help would be appreciated.
Thanks.
Here is the code from the server.js, let me know if you need more. All the code is from the codelab examples, I haven't edited it at all.
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 io = require('socket.io').listen(app);
io.sockets.on('connection', function (socket){
// convenience function to log server messages on the client
function log(){
var array = [">>> Message from server: "];
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);
// for a real app, would be room only (not broadcast)
socket.broadcast.emit('message', message);
});
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);
});
});