Step 5 Not Working
Hello,
I'm trying to run Step 5, 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: (Right Click, Open Image In New Tab to view better)
From cmd:
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.
Comments (16)
-
-
Same here. This line is causing problems. var numClients = io.sockets.clients().length;
-
Hi,
I am also facing the same issue. Pl let us know if it is solved.
Thanks Anil
-
The function is depreciated from version 1.0. Use 0.9.
npm uninstall socket.io -g
go to the step 5 directory and run
npm install --save
-
Hi,
- I installed nvm.
- nvm install 0.9
- followed steps from Balaji Arun
works now :)
-
hi, Iam confused right now what i have to install first nvm or npm to figure it out.... dealing with the same error???? and my node version is 0.10
-
Hi, I was trying to following this code lab. But I found the 2014 io codelab for a more updated version of this repo. Basically it's the same concept.
Maybe you'd like to check it out. http://io2014codelabs.appspot.com/static/codelabs/webrtc-file-sharing
And google put them code in the github. https://github.com/googlesamples/io2014-codelabs/tree/master/webrtc-file-sharing
-
Balaji Arun:
Can you please explain why this works? How can one direct to a folder like step5 would install socket.io 0.9.7 ? it's so strange
-
Ok guys, here's how to fix this problem. in the server.js , replace the second "socket.on" with this:
socket.on('create or join', function (room) { **clients.push(arguments);** //this line fixes the problem!! console.log("line executed") **var numClients = clients.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); })
so, instead of calling the io.sockets.clients(room).length use a different method to decide the length(number of client).
-
Now getting this error
ReferenceError: clients is not defined
-
io.sockets.clients(room).length; is not supported in socket.io version 1.0 and on. I have created a repo with the server.js file updated to reflect a working version for socket.io version 1.0 and on here https://bitbucket.org/wonderdogone/webrtc_codelab_part5_fix/overview
-
The easiest way I have found to make this work is to install the older version of socket.io by using the following: npm install socket.io@0.9
-
thank you Guys I appreciate your support, hope it works for me since I have the same issue
-
My solution is using the adapter for getting clients, I know It's also mentioned by other guys (Unknown Name)
var clients = io.sockets.adapter.rooms[room]; var numClients = 0; if (typeof clients === 'undefined') { console.log("server.js:clients is type=" + clients + "/numClients="+numClients); } else { numClients = Object.keys(clients).length; console.log("server.js:clients is defined , numClients=" + numClients); }
-
Hi all, This code was running well from my end but after enabling https it's not emitting any signal (we can not see remote signal). For ssl I am using
var https = require('https'); var fs = require('fs'); var options = { key: fs.readFileSync('path.key'), cert: fs.readFileSync('path.crt'), ca: fs.readFileSync('path.crt') }; var file = new(static.Server)(); var app = https.createServer(options, function (req, res) { file.serve(req, res); }).listen(2013);
I'm beginner to node.js and socket.io. Any help would be appreciated. Thanks.
-
In step7 , The video chatting application runs perfectly fine in local host. but when I try to run the same code in a specific IP im not able to perform the same task, Error : getUserMedia() no longer works on insecure origins Any ideas on how can I fix this issue?
- Log in to comment
Not able to reproduce your issue. What version of SocketIO are you using? Make sure you use 0.9 or higher.