mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
try: manage session
This commit is contained in:
1 parent
9b5b5571ef
commit
5326fb30b4
1 file changed
+26
-26
@@ -10,11 +10,10 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { Terminal } from 'xterm'
|
import { Terminal } from 'xterm'
|
||||||
import { FitAddon } from 'xterm-addon-fit'
|
import { FitAddon } from 'xterm-addon-fit'
|
||||||
// import { AttachAddon } from 'xterm-addon-attach'
|
|
||||||
import 'xterm/css/xterm.css'
|
import 'xterm/css/xterm.css'
|
||||||
import { io } from 'socket.io-client'
|
import { io } from 'socket.io-client'
|
||||||
import { onMounted, ref } from 'vue'
|
import { onMounted, ref } from 'vue'
|
||||||
import api from '../utils/api'
|
// import api from '../utils/api'
|
||||||
|
|
||||||
const rows = ref(40)
|
const rows = ref(40)
|
||||||
const cols = ref(100)
|
const cols = ref(100)
|
||||||
@@ -40,15 +39,35 @@ onMounted(() => {
|
|||||||
const host = 'wss://odyssey.wancat.cc'
|
const host = 'wss://odyssey.wancat.cc'
|
||||||
const sessionhost = 'http://odyssey.wancat.cc'
|
const sessionhost = 'http://odyssey.wancat.cc'
|
||||||
// const host = 'ws://localhost:3000'
|
// const host = 'ws://localhost:3000'
|
||||||
|
// const sessions = async () => {
|
||||||
|
// await api.get(`/sessions`).json()
|
||||||
|
// }
|
||||||
|
// console.log(sessions)
|
||||||
|
const res = async () => {
|
||||||
|
await fetch(`${sessionhost}/api/v1/sessions`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
quest_id: 'helloworld',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const data = async () => {
|
||||||
|
await res.json()
|
||||||
|
}
|
||||||
|
const sessionId = data._id
|
||||||
|
// async () => {}
|
||||||
|
// console.log(api.get('/quests/helloworld').session)
|
||||||
|
// console.log(await sessions[sessions.length - 1].id)
|
||||||
const socket = io(host, {
|
const socket = io(host, {
|
||||||
query: {
|
query: {
|
||||||
// session_id: sessionId,
|
session_id: sessionId,
|
||||||
// session_id: '64d26a8cffab987b2bb0de38',
|
// session_id: '64c1164a5b34af580963da6b',
|
||||||
// odyssey
|
|
||||||
session_id: '64d271ce784daf755387ff4f',
|
|
||||||
// localhost
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// console.log(sessionId)
|
||||||
socket.on('connect', function open() {
|
socket.on('connect', function open() {
|
||||||
console.log('Connected to the server.')
|
console.log('Connected to the server.')
|
||||||
})
|
})
|
||||||
@@ -58,27 +77,8 @@ onMounted(() => {
|
|||||||
socket.on('message', (message) => {
|
socket.on('message', (message) => {
|
||||||
console.log(message)
|
console.log(message)
|
||||||
term.write(message)
|
term.write(message)
|
||||||
const session =
|
|
||||||
// api.get('') ||
|
|
||||||
// (program.opts().create ? (await createdSession())._id : null) ||
|
// (program.opts().create ? (await createdSession())._id : null) ||
|
||||||
// (await lastSession())._id
|
// (await lastSession())._id
|
||||||
// if (message == 'Session not found.') {
|
|
||||||
// term.write('\nSession undefined')
|
|
||||||
// console.log('Creating a new session...')
|
|
||||||
// const res = fetch(`${sessionhost}/api/v1/sessions`, {
|
|
||||||
// method: 'POST',
|
|
||||||
// headers: {
|
|
||||||
// 'Content-Type': 'application/json',
|
|
||||||
// },
|
|
||||||
// body: JSON.stringify({
|
|
||||||
// questid: 'helloworld',
|
|
||||||
// }),
|
|
||||||
// })
|
|
||||||
// const data = res.json()
|
|
||||||
console.log(res)
|
|
||||||
// console.log(data)
|
|
||||||
// console.log('Created Session ID:', data.id)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
term.onData((key) => {
|
term.onData((key) => {
|
||||||
console.log(key)
|
console.log(key)
|
||||||
|
|||||||
Reference in new issue
Block a user