TypeError:无法读取Socket.socket.on上未定义的属性“ room”。 尽管代码对我来说看起来不错,但仍会生成类型错误。难道是因为Socket的版本?请告诉我们需要做什么来解决它。这是显示错误的代码段:
socket.on('joinRoom', ({username, room}) => {
const user = userJoin(socket.id, username, room);
socket.join(user.room);
socket.emit('message', formatMessage(botName, 'Welcome to Concord!'));
socket.broadcast.to(user.room).emit(
'message',
formatMessage(botName, `${user.username} has joined the chat!`));
io.to(user.room).emit('roomUsers' , {
room: user.room,
users: getRoomUsers(user.room)
});
});