Send custom data along with handshakeData in socket.io?

前端 未结 7 1285
迷失自我
迷失自我 2020-11-28 02:18

So I have an application running node js with socket.io as a backend and normal javascript as frontend. My application has a login system which currently simply has the clie

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 02:41

    This has now been changed in v1.0.0. See the migration docs

    basically,

    io.set('authorization', function (handshakeData, callback) {
      // make sure the handshake data looks good
      callback(null, true); // error first, 'authorized' boolean second 
    });
    

    becomes :

      io.use(function(socket, next) {
      var handshakeData = socket.request;
      // make sure the handshake data looks good as before
      // if error do this:
        // next(new Error('not authorized');
      // else just call next
      next();
    });
    

提交回复
热议问题