remove sockets when closed
This commit is contained in:
parent
11e5c08154
commit
1c9fc428b9
2 changed files with 9 additions and 10 deletions
|
|
@ -31,7 +31,6 @@ class WebSocketServer {
|
||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.config = config
|
this.config = config
|
||||||
this._websocketserver = null
|
this._websocketserver = null
|
||||||
this._interval = null
|
|
||||||
|
|
||||||
this.evt = new EvtBus()
|
this.evt = new EvtBus()
|
||||||
}
|
}
|
||||||
|
|
@ -49,15 +48,13 @@ class WebSocketServer {
|
||||||
socket.close()
|
socket.close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('message', (data) => {
|
socket.on('message', (data) => {
|
||||||
console.log(`ws`, socket.protocol, data)
|
console.log(`ws`, socket.protocol, data)
|
||||||
this.evt.dispatch('message', {socket, data})
|
this.evt.dispatch('message', {socket, data})
|
||||||
})
|
})
|
||||||
})
|
socket.on('close', () => {
|
||||||
|
this.evt.dispatch('close', {socket})
|
||||||
this._websocketserver.on('close', () => {
|
})
|
||||||
clearInterval(this._interval)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,11 +121,13 @@ const notify = (data, sockets) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
wss.on('close', async ({socket}) => {
|
wss.on('close', async ({socket}) => {
|
||||||
const proto = socket.protocol.split('|')
|
try {
|
||||||
const clientId = proto[0]
|
const proto = socket.protocol.split('|')
|
||||||
const gameId = proto[1]
|
const clientId = proto[0]
|
||||||
if (Game.exists(gameId)) {
|
const gameId = proto[1]
|
||||||
GameSockets.removeSocket(gameId, socket)
|
GameSockets.removeSocket(gameId, socket)
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue