Socket.io 1.0 | socket.set()和socket.get()的替换

时间:2015-08-21 07:48:15

标签: node.js socket.io

我想知道如何将套接字代码从socket.io 0.9更改为socket.io 1.0。

我知道不推荐使用socket.get(key,callback)和socket.set(key,value,callback)。 但是,我不知道如何迁移它。

socket.on('check credential', function (client) {

  ...

  socket.set('client', client, function () {
    socketsOf[client.roomId][client.userName] = socket;
    if (client.userName) {
           console.log('user ' + client.userName + '@' + client.roomId + ' connected');
    }
  });
});


socket.on('request log', function (data) {
  socket.get('client', function (err, client) {
    if (err || client === undefined) {
      return;
    }
    emitToRoom(client.roomId, 'request log', {}, function (log) {
      socket.emit('update log', log);
    });
  });
});

0 个答案:

没有答案