u
This commit is contained in:
parent
c62f0211b7
commit
35083bb325
@ -10,22 +10,22 @@ const my = {
|
||||
module.exports = {
|
||||
initSocket (webServer) {
|
||||
my.wsServer = new ws.Server({ server: webServer })
|
||||
console.info(new Date().toJSON(), 'Base Socket Server is initialized.')
|
||||
console.info(new Date().toJSON(), '[LOG] Base Socket Server is initialized.')
|
||||
|
||||
my.wsServer.on('connection', (socket, req) => {
|
||||
//console.info(`A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`)
|
||||
//console.info(new Date().toJSON(), `[LOG] A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`)
|
||||
|
||||
// socket.isAlive = true
|
||||
// socket.on('pong', function() { console.log('👈 ASS: on Pong'); this.isAlive = true })
|
||||
// socket.on('pong', function() { this.isAlive = true })
|
||||
|
||||
socket.on('message', (data) => {
|
||||
// 在这里统一分发消息
|
||||
let dataObj
|
||||
try {
|
||||
dataObj = JSON.parse(data)
|
||||
console.log(new Date().toJSON(), '收到 App Socket Event: ', dataObj?.skevent)
|
||||
console.log(new Date().toJSON(), '[LOG] 收到 App Socket Event: ', dataObj?.skevent)
|
||||
} catch (exception) {
|
||||
console.log(new Date().toJSON(), 'Unable to parse socket message: ', data)
|
||||
console.log(new Date().toJSON(), '[LOG] Unable to parse socket message: ', data)
|
||||
return
|
||||
}
|
||||
if (['SOCKET_OWNER', 'SOCKET_OWNER_RECONNECT'].includes(dataObj.skevent)) {
|
||||
@ -34,7 +34,7 @@ module.exports = {
|
||||
my.socketPool[dataObj._passtokenSource.usid] = socket
|
||||
socket.usid = dataObj._passtokenSource.usid
|
||||
console.log(
|
||||
new Date().toJSON(),
|
||||
new Date().toJSON(), '[LOG]',
|
||||
dataObj.skevent === 'SOCKET_OWNER' ? 'Login' : 'Reconnect',
|
||||
'绑定 socket 到',
|
||||
dataObj._passtokenSource.usid,
|
||||
@ -61,7 +61,7 @@ module.exports = {
|
||||
// }, 60000)
|
||||
|
||||
socket.on('close', () => {
|
||||
//console.log('Closing socket of usid =', socket?.usid) // don't know why, but this output happens too often without usid.
|
||||
//console.log(new Date().toJSON(), '[LOG] Closing socket of usid =', socket?.usid) // don't know why, but this output happens too often without usid.
|
||||
delete my.socketPool[socket?.usid]
|
||||
// clearInterval(heartbeat)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user