feat: socket error handling

* create a new session when failed to connect to socket
* reset termnal on connect
This commit is contained in:
wancat committed 2023-10-30 23:31:58 +08:00
1 parent 9c3c6adb16
commit 252781477a
4 files changed
+39 -31

No files matched your search

+20 -22
View File
@@ -7,30 +7,28 @@ class SocketWrapper {
}
connect(session) {
if (this.socket) {
this.socket.off()
this.socket.disconnect()
}
return new Promise((resolve, reject) => {
if (this.socket) {
this.socket.off()
this.socket.disconnect()
}
this.socket = io('', {
query: {
session_id: session._id,
},
this.socket = io('', {
query: {
session_id: session._id,
},
})
this.socket.on('connect', () => {
console.log('Socket connected to session', session._id)
})
this.socket.once('terminal', () => {
resolve()
})
this.socket.once('error', reject)
this.bindListeners()
})
this.socket.on('connect', () => {
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()
}
on(event, callback) {