我想知道如何将套接字代码从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);
});
});
});