Skip to content

Commit

Permalink
made console work (i hope i am unable to test)
Browse files Browse the repository at this point in the history
  • Loading branch information
PentaMine committed Mar 1, 2024
1 parent 58e27be commit 87c9075
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
3 changes: 2 additions & 1 deletion apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"dependencies": {
"@encedeus/js-api": "^0.0.101",
"@repo/ui": "*",
"apexcharts": "^3.45.2"
"apexcharts": "^3.45.2",
"ws": "^8.16.0"
},
"devDependencies": {
"@repo/tailwind-config": "*",
Expand Down
52 changes: 42 additions & 10 deletions apps/console/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import ApexCharts from "apexcharts";
import {onMount} from "svelte";
import {api} from "./lib/services/api";
import WebSocket from 'ws';
import {WebSocket} from "vite";
import RawData = WebSocket.RawData;
const urlParams = new URLSearchParams(window.location.search);
const serverId = urlParams.get("serverId");
Expand Down Expand Up @@ -153,32 +156,60 @@
const resp = await api.serversService.startServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
connectionError = resp.error?.message;
return;
}
connectionError = ""
connectionError = "";
}
async function onClickRestart() {
const resp = await api.serversService.restartServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
connectionError = resp.error?.message;
return;
}
connectionError = ""
connectionError = "";
}
async function onClickStop() {
const resp = await api.serversService.stopServer(serverId!);
if (resp.error) {
connectionError = resp.error?.message
return
connectionError = resp.error?.message;
return;
}
connectionError = ""
connectionError = "";
}
let terminal = "";
let command = "";
const ws = new WebSocket(`ws://servers/${serverId}/console`, {
perMessageDeflate: false
});
ws.on('error', console.error);
ws.on('open', function open() {console.log("WebSocket open");});
ws.on('message', function message(data: RawData) {
const newLine = data.toString()
terminal += `${newLine}\n`
});
function handleSendCommand(event: KeyboardEvent) {
if (event.key != "Enter") {
return;
}
const message = JSON.stringify({cmd: command});
ws.send(message);
}
</script>

<main class="p-10 flex flex-col">
Expand Down Expand Up @@ -240,10 +271,11 @@
</section>
<section class="w-full h-full">
<div class="bg-indigo-950 rounded-lg rounded-b-none h-[48rem] py-4 px-6 text-white overflow-y-auto break-words overflow-x-hidden">
{terminal}
</div>
<div class="bg-indigo-900 h-11 rounded-b-lg p-2.5 px-5 text-white flex gap-1.5 flex-shrink">
<span class="font-medium text-md">$</span>
<input type="text" placeholder="Type your command here"
<input on:keydown={handleSendCommand} bind:value={command} type="text" placeholder="Type your command here"
class="outline-indigo-500 opacity-85 focus:outline rounded-sm p-1 outline-2 bg-indigo-900 inline w-full">
</div>
</section>
Expand Down
23 changes: 22 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87c9075

Please sign in to comment.