mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 11:10:11 +08:00
refactor: centralize all variable to sessionManager
This commit is contained in:
1 parent
801d1aa07b
commit
2639c0ddda
6 files changed
+56
-39
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { ref } from 'vue'
|
||||
import { FileGraph } from '@linux-odyssey/file-graph'
|
||||
import api from './api'
|
||||
import Socket from './socket'
|
||||
import SocketTerminal from './terminal'
|
||||
|
||||
class SessionManager {
|
||||
constructor(questId) {
|
||||
@@ -16,6 +18,30 @@ class SessionManager {
|
||||
)
|
||||
this.pwd = ref('')
|
||||
this.status = ref('inactive')
|
||||
this.socket = new Socket()
|
||||
this.term = new SocketTerminal(40, 80)
|
||||
}
|
||||
|
||||
init() {
|
||||
this.socket.on('terminal', (data) => {
|
||||
this.term.write(data)
|
||||
})
|
||||
this.term.onData((data) => {
|
||||
this.socket.emit('terminal', data)
|
||||
})
|
||||
this.socket.on('graph', (event) => {
|
||||
this.handleGraphUpdate(event)
|
||||
})
|
||||
this.socket.on('hints', (event) => {
|
||||
this.handleHintUpdate(event)
|
||||
})
|
||||
this.socket.on('tasks', (tasks) => {
|
||||
this.setTasks(tasks)
|
||||
})
|
||||
this.socket.on('status', (event) => {
|
||||
this.handleStatusUpdate(event)
|
||||
})
|
||||
return this.getActiveSession()
|
||||
}
|
||||
|
||||
getSession() {
|
||||
@@ -27,6 +53,8 @@ class SessionManager {
|
||||
this.graph.value = new FileGraph(session.graph)
|
||||
this.hints.value = session.hints
|
||||
this.status.value = session.status
|
||||
this.term.clear()
|
||||
this.socket.connect(session)
|
||||
}
|
||||
|
||||
handleGraphUpdate(event) {
|
||||
|
||||
Reference in new issue
Block a user