socketio / socket.io-p2p

MIT License
1.02k stars 180 forks source link

TypeError: fns[i] is not a function #29

Open Charles101993 opened 7 years ago

Charles101993 commented 7 years ago

This error originates in the namespace.js file inside of the socket.io module. This happens when io.use(p2p) has been called and another person attempts to connect. This happens both for my own socket.io project and the chat example that I used to debug the original issue. I used browserify both times to create my bundle.js file and have made only minor modifications to the require('') commands in the index.js file(inside socket.io-p2p-master) to elucidate the path for the node.js modules. Below is the run function inside namespace.js (which is where the error occurs). I'm not sure exactly what files are relevant but I've attached is my bundle.js file that I generated using browserify. I've gotten this error for my original project and the example so it may be my machine (windows) but I'm wondering if anyone else has had this problem as well.

Namespace.prototype.run = function(socket, fn){
  var fns = this.fns.slice(0);
  if (!fns.length) return fn(null);

  function run(i){
    fns[i](socket, function(err){        //this is the line that causes the error

      // upon error, short-circuit
      if (err) return fn(err);

      // if no middleware left, summon callback
      if (!fns[i + 1]) return fn(null);

      // go on to next
      run(i + 1);
    });
  }

  run(0);
};

bundle.zip

SlausB commented 7 years ago

Seems like io.use( 'some literal', function(){} ) used instead of io.use( function(){} ) when migrated to socket >1.0.

PramodMahajan14 commented 5 months ago

I have been getting this error when I applying authorization middleware - io.use(authorizerUser)