diff --git a/.eslintrc.js b/.eslintrc.js index 7d9e2c6..f438449 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -21,5 +21,6 @@ module.exports = { 'import/extensions': 'off', camelcase: ['error', { properties: 'never', ignoreDestructuring: true }], 'no-param-reassign': ['error', { props: false }], + 'no-underscore-dangle': ['error', { allow: ['_id'] }], }, } diff --git a/app/package.json b/app/package.json index 8cc8dbe..de08c19 100644 --- a/app/package.json +++ b/app/package.json @@ -15,7 +15,11 @@ "@fortawesome/free-solid-svg-icons": "^6.4.0", "@fortawesome/vue-fontawesome": "^3.0.3", "axios": "^1.4.0", - "vue": "^3.3.4" + "socket.io-client": "^4.7.1", + "vue": "^3.3.4", + "xterm": "^5.2.1", + "xterm-addon-attach": "^0.8.0", + "xterm-addon-fit": "^0.7.0" }, "devDependencies": { "@vitejs/plugin-vue": "^4.2.3", diff --git a/app/src/App.vue b/app/src/App.vue index c0fcaaf..58f4090 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -1,11 +1,25 @@ @@ -44,32 +58,9 @@ import VisualizationPart from './components/VisualizationPart.vue' - - - - Solution - - - - Reset - - - - Continue - - + + diff --git a/app/src/components/ControlPalette.vue b/app/src/components/ControlPalette.vue new file mode 100644 index 0000000..0894bad --- /dev/null +++ b/app/src/components/ControlPalette.vue @@ -0,0 +1,40 @@ + + + + + Solution + + + + Reset + + + + Continue + + + + + diff --git a/app/src/components/TerminalPart.vue b/app/src/components/TerminalPart.vue index 9ee24ee..2b61bf5 100644 --- a/app/src/components/TerminalPart.vue +++ b/app/src/components/TerminalPart.vue @@ -1,11 +1,65 @@ - - Terminal - - - zeko@first-command:~$ - - + + + diff --git a/app/src/utils/session.js b/app/src/utils/session.js new file mode 100644 index 0000000..80ab25c --- /dev/null +++ b/app/src/utils/session.js @@ -0,0 +1,57 @@ +import { ref } from 'vue' +import api from './api' + +class SessionManager { + constructor(questId) { + this.questId = questId + this.session = ref(null) + } + + getSession() { + return this.session.value + } + + setSession(session) { + console.log('Update session:', session) + this.session.value = session + } + + async createSession() { + console.log('Creating a new session...') + const res = await api.post('/sessions', { quest_id: this.questId }) + const { data } = res + console.log('Created Session ID:', data._id) + this.setSession(data) + } + + async getSessionList() { + const res = await api.get('/sessions', { + params: { quest_id: this.questId }, + }) + const { data } = res + return data + } + + async lastSession() { + const sessions = await this.getSessionList() + if (sessions.length === 0) { + return + } + const session = sessions[sessions.length - 1] + console.log( + `Last Session ID: ${session._id}, Quest: ${session.quest}, Created At: ${session.createdAt}` + ) + this.setSession(session) + } + + async lastOrCreate() { + await this.lastSession() + if (!this.session.value) { + await this.createSession() + } + } +} + +const sessionManager = new SessionManager('helloworld') + +export default sessionManager diff --git a/app/src/utils/socket.js b/app/src/utils/socket.js new file mode 100644 index 0000000..96c66e3 --- /dev/null +++ b/app/src/utils/socket.js @@ -0,0 +1,52 @@ +import io from 'socket.io-client' + +const host = 'wss://odyssey.wancat.cc' + +class SocketWrapper { + constructor() { + this.socket = null + this.listeners = [] + } + + connect(session) { + if (this.socket) { + this.socket.off() + this.socket.disconnect() + } + + this.socket = io(host, { + query: { + session_id: session._id, + }, + }) + + this.socket.on('connect', () => { + console.log('Socket connected to session', session._id) + }) + + this.bindListeners() + } + + on(event, callback) { + this.listeners.push({ event, callback }) + if (this.socket) { + this.socket.on(event, callback) + } + } + + bindListeners() { + this.listeners.forEach(({ event, callback }) => { + this.socket.on(event, callback) + }) + } + + send(data) { + this.socket.send(data) + } + + emit(event, data) { + this.socket.emit(event, data) + } +} + +export default new SocketWrapper() diff --git a/app/vite.config.js b/app/vite.config.js index 05c1740..cf94bdc 100644 --- a/app/vite.config.js +++ b/app/vite.config.js @@ -4,4 +4,13 @@ import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue()], + server: { + proxy: { + '/api': { + // target: 'http://localhost:3000', // the server url + target: 'http://odyssey.wancat.cc ', + ws: true, + }, + }, + }, }) diff --git a/cleanup.sh b/cleanup.sh old mode 100644 new mode 100755 diff --git a/yarn.lock b/yarn.lock index 2a3ac1c..47e89d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4887,6 +4887,21 @@ xmlhttprequest-ssl@~2.0.0: resolved "https://registry.yarnpkg.com/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz#91360c86b914e67f44dce769180027c0da618c67" integrity sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A== +xterm-addon-attach@^0.8.0: + version "0.8.0" + resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.8.0.tgz#86e0ed08460efffb7d4bad74a57b600226594def" + integrity sha512-k8N5boSYn6rMJTTNCgFpiSTZ26qnYJf3v/nJJYexNO2sdAHDN3m1ivVQWVZ8CHJKKnZQw1rc44YP2NtgalWHfQ== + +xterm-addon-fit@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/xterm-addon-fit/-/xterm-addon-fit-0.7.0.tgz#b8ade6d96e63b47443862088f6670b49fb752c6a" + integrity sha512-tQgHGoHqRTgeROPnvmtEJywLKoC/V9eNs4bLLz7iyJr1aW/QFzRwfd3MGiJ6odJd9xEfxcW36/xRU47JkD5NKQ== + +xterm@^5.2.1: + version "5.2.1" + resolved "https://registry.yarnpkg.com/xterm/-/xterm-5.2.1.tgz#b3fea7bdb55b9be1d4b31f4cd1091f26ac42afb8" + integrity sha512-cs5Y1fFevgcdoh2hJROMVIWwoBHD80P1fIP79gopLHJIE4kTzzblanoivxTiQ4+92YM9IxS36H1q0MxIJXQBcA== + y18n@^5.0.5: version "5.0.8" resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55"
Solution
Reset
Continue
- zeko@first-command:~$ -