webssh_plus/index.html

37 lines
1.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>bash</title>
<link rel="stylesheet" href="/node_modules/xterm/dist/xterm.css" />
<link rel="stylesheet" href="/node_modules/xterm/dist/addons/fullscreen/fullscreen.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.auto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js"></script>
<script src="/node_modules/xterm/dist/xterm.js"></script>
<script src="/node_modules/xterm/dist/addons/fit/fit.js"></script>
<script src="/node_modules/xterm/dist/addons/attach/attach.js"></script>
</head>
<body>
<div id="terminal"></div>
<script>
// No idea what these are about. Just copied them from the demo code
Terminal.applyAddon(attach);
Terminal.applyAddon(fit);
// The terminal
const term = new Terminal();
// This kinda makes sense
const container = document.getElementById('terminal');
term.open(container);
// Open the websocket connection to the backend
const protocol = (location.protocol === 'https:') ? 'wss://' : 'ws://';
const port = location.port ? `:${location.port}` : '';
const socketUrl = `${protocol}${location.hostname}${port}/shell`;
const socket = new WebSocket(socketUrl);
// Attach the socket to the terminal
socket.onopen = (ev) => { term.attach(socket); };
// Not going to worry about close/error for the websocket
</script>
</body>
</html>