confusion about examples/private-messaging #4424
Unanswered
yangxiao235
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
hi, i'm currently hacking on examples/private-messaging, i found there is a little bit confusing on file index.js:
io.on("connection", async (socket) => {
.......
// join the "userID" room
socket.join(socket.userID);
......
}
socket.on("disconnect", async () => {
const matchingSockets = await io.in(socket.userID).allSockets();
const isDisconnected = matchingSockets.size === 0;
........
}
the socket.userID room is only used by the client the socket corresponding to and server, why should check number of allSockets equal to 0 ? is there other clients join the room?
as my understanding, when user select different usename on browser, the client should go there(App.vue):
methods: {
onUsernameSelection(username) {
this.usernameAlreadySelected = true;
socket.auth = { username };
console.log(
begin to connect
); // logs addedsocket.connect();
},
},
but nothing printed on the console. please help me
Beta Was this translation helpful? Give feedback.
All reactions