connect to docker, trying to emit message

This commit is contained in:
Annie Huang authored and wancat committed 2023-08-17 19:43:55 +08:00
1 parent 0195305d0e
commit 577352e51d
2 files changed
+30 -12

No files matched your search

+30 -12
View File
@@ -16,8 +16,10 @@
<script> <script>
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 { AttachAddon } from 'xterm-addon-attach'
import { stdin, stdout, exit } from 'process'
import 'xterm/css/xterm.css' import 'xterm/css/xterm.css'
import { io } from 'socket.io-client'
// import connect from 'server/src/client' // import connect from 'server/src/client'
export default { export default {
@@ -51,18 +53,33 @@ export default {
lineHeight: 20, lineHeight: 20,
}, },
}) })
const wsHost = 'odyssey.wancat.cc' const ws = 'wss://odyssey.wancat.cc'
// const wsHost = 'localhost:3000' // const ws = 'ws://localhost:3000'
// const container = 'quest-helloworld-defaultUser-1690375754669' const socket = io(ws, {
// const container = '1690375754669' query: {
const container = '64c1164a5b34af580963da6b' // session_id: sessionId,
// const container = '423ba17d5863' session_id: '64cb80132077b982b86bdc4f',
// const container = 'dcb865c0e5a5 ' },
const ws = `wss://${wsHost}/containers/${container}/attach/ws?stream=true` })
const socket = new WebSocket(ws) socket.on('message', function incoming(data) {
const attachAddon = new AttachAddon(socket) console.log(data)
})
socket.on('open', function open() {
console.log('Connected to the server.')
})
// socket.on('message', function incoming(data) {
// stdout.write(data)
// })
socket.on('close', function close() {
console.log('Disconnected from the server.')
exit()
})
socket.on('message', (message) => {
term.onData(socket.emit('input', message))
})
// const attachAddon = new AttachAddon(socket)
// 创建terminal实例 // 创建terminal实例
term.loadAddon(attachAddon) // term.loadAddon(attachAddon)
term.open(this.$refs.terminal) term.open(this.$refs.terminal)
// 换行并输入起始符 $ // 换行并输入起始符 $
term.prompt = () => { term.prompt = () => {
@@ -83,6 +100,7 @@ export default {
} }
window.addEventListener('resize', resizeScreen) window.addEventListener('resize', resizeScreen)
xthis.term = term xthis.term = term
xthis.socket = socket
xthis.runFakeTerminal() xthis.runFakeTerminal()
}, },
runFakeTerminal() { runFakeTerminal() {
Regular → Executable
View File
File mode changed.