Step 5 Not Working

Issue #13 new
Kevin created an issue

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) devtools_error.jpg

From cmd: cmd_error.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.

Comments (16)

  1. Balaji Arun

    Not able to reproduce your issue. What version of SocketIO are you using? Make sure you use 0.9 or higher.

  2. Balaji Arun

    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

  3. bilal khalid

    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

  4. waht mmm

    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

  5. waht mmm

    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).

  6. Joseph Cravotta

    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

  7. salim rahal

    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);
             }
    
  8. Shekhar Jha

    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.

  9. balaji Rajendran

    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?

  10. Log in to comment