mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
feat: socket error handling
* create a new session when failed to connect to socket * reset termnal on connect
This commit is contained in:
1 parent
2639c0ddda
commit
ed14491cfc
4 files changed
+39
-31
No files matched your search
@@ -48,13 +48,14 @@ class SessionManager {
|
||||
return this.session.value
|
||||
}
|
||||
|
||||
setSession(session) {
|
||||
async setSession(session) {
|
||||
this.session.value = session
|
||||
this.graph.value = new FileGraph(session.graph)
|
||||
this.hints.value = session.hints
|
||||
this.status.value = session.status
|
||||
this.term.clear()
|
||||
this.socket.connect(session)
|
||||
this.term.reset()
|
||||
await this.socket.connect(session)
|
||||
this.term.focus()
|
||||
}
|
||||
|
||||
handleGraphUpdate(event) {
|
||||
@@ -92,7 +93,12 @@ class SessionManager {
|
||||
})
|
||||
const session = res.data
|
||||
console.log(session)
|
||||
this.setSession(session)
|
||||
try {
|
||||
await this.setSession(session)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
this.createSession().catch(console.error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-22
@@ -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) {
|
||||
|
||||
@@ -33,6 +33,10 @@ class SocketTerminal {
|
||||
this.term.onData(callback)
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.term.focus()
|
||||
}
|
||||
|
||||
resizeScreen() {
|
||||
this.fitAddon.fit()
|
||||
}
|
||||
@@ -43,8 +47,8 @@ class SocketTerminal {
|
||||
this.resizeScreen()
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.term.clear()
|
||||
reset() {
|
||||
this.term.reset()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user