Socket.Io将多个插座推入房间

时间:2016-05-19 08:29:59

标签: socket.io

我需要能够在创建的同时将几个“插座”推入房间

Socket.io收到用户ID列表

通过'var s = c_user_socket [d];'找到正确的套接字ID 其中d是user_id,c_user_sockets保存user_id-socket_id关系

如果找到匹配,则变量's'变为类似

'/# - TVfzhM9oGLtmiPdAAAC

要加入我的房间:s.join(“conversation_”+ chat_id);

然后Socket.io以错误退出

socket上缺少错误处理程序。

TypeError: s.join is not a function
at /var/www/html/controller/servers/socket_io_server.js:29:7
at Array.forEach (native)
at Socket.<anonymous> (/var/www/html/controller/servers/socket_io_server.js:24:16)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at Socket.onevent (/node_modules/socket.io/lib/socket.js:335:8)
at Socket.onpacket (/node_modules/socket.io/lib/socket.js:295:12)
at Client.ondecoded (/node_modules/socket.io/lib/client.js:193:14)
at Decoder.Emitter.emit (/node_modules/socket.io/node_modules/socket.io-parser/node_modules/component-emitter/index.js:134:20)
at Decoder.add (/node_modules/socket.io/node_modules/socket.io-parser/index.js:247:12)

如何一次将多个插座推入房间?

通过数组找到套接字:

socket.on('identify', function(data) {
    data = String(data);
    c_socket_user[socket.id] = data;
    c_user_socket[data] = socket.id;
})

0 个答案:

没有答案