refactor: centralize all variable to sessionManager

This commit is contained in:
wancat committed 2023-10-30 23:12:50 +08:00
1 parent 5a7c4da628
commit 9c3c6adb16
6 files changed
+56 -39

No files matched your search

+15 -1
View File
@@ -22,6 +22,14 @@ class SocketWrapper {
console.log('Socket connected to session', session._id)
})
this.socket.on('disconnect', () => {
console.log('Socket disconnected from session', session._id)
})
this.socket.on('error', (err) => {
console.log('Socket error', err)
})
this.bindListeners()
}
@@ -32,6 +40,12 @@ class SocketWrapper {
}
}
once(event, callback) {
if (this.socket) {
this.socket.once(event, callback)
}
}
bindListeners() {
this.listeners.forEach(({ event, callback }) => {
this.socket.on(event, callback)
@@ -47,4 +61,4 @@ class SocketWrapper {
}
}
export default new SocketWrapper()
export default SocketWrapper