modify this.connections before emiting join event

This commit is contained in:
SrGooglo 2023-05-18 20:08:55 +00:00
parent 1c5f5a75b4
commit 4195d9e772

View File

@ -79,6 +79,9 @@ class Room {
// join room
socket.join(this.roomName)
// add to connections
this.connections.push(socket)
// emit to self
socket.emit("room:joined", {
room: this.roomName,
@ -110,9 +113,6 @@ class Room {
socket.on(event, handler)
}
// add to connections
this.connections.push(socket)
console.log(`[${socket.id}][@${socket.userData.username}] joined room ${this.roomName}`)
}
@ -129,6 +129,8 @@ class Room {
socket.leave(this.roomName)
this.connections.splice(this.connections.indexOf(socket), 1)
socket.emit("room:left", {
room: this.roomName,
})
@ -146,8 +148,6 @@ class Room {
socket.off(event, handler)
}
this.connections.splice(this.connections.indexOf(socket), 1)
console.log(`[${socket.id}][@${socket.userData.username}] left room ${this.roomName}`)
}
}