U 优化web终端

pull/410/head
vapao 2021-11-26 18:33:57 +08:00
parent 6392b69abf
commit 8fd9780250
2 changed files with 4 additions and 2 deletions

View File

@ -119,7 +119,7 @@ class SSHConsumer(WebsocketConsumer):
self.close()
def _init(self):
self.send(bytes_data=b'Connecting ...\r\n')
self.send(bytes_data=b'\r\33[KConnecting ...\r')
host = Host.objects.filter(pk=self.id).first()
if not host:
self.send(text_data='Unknown host\r\n')

View File

@ -18,11 +18,13 @@ function WebSSH(props) {
useEffect(() => {
const fitPlugin = new FitAddon();
term.loadAddon(fitPlugin);
term.open(container.current);
term.write('WebSocket connecting ... ');
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/ssh/${props.id}/?x-token=${X_TOKEN}`);
socket.onmessage = e => _read_as_text(e.data);
socket.onopen = () => {
term.open(container.current);
term.write('ok')
term.focus();
fitPlugin.fit();
};