mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
refactor: centralize all variable to sessionManager
This commit is contained in:
1 parent
5a7c4da628
commit
9c3c6adb16
6 files changed
+56
-39
No files matched your search
+15
-1
@@ -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
|
||||
Reference in new issue
Block a user