javaterminal / cloudterm

Cloud Web Terminal Emulator. Opens your terminal to Web.
MIT License
78 stars 37 forks source link

fix resize window in `main.js` #5

Closed Xarrow closed 4 years ago

rahmanusta commented 4 years ago

Thanks @Xarrow, what was the problem with the previous implementation?

Xarrow commented 4 years ago

Thanks @Xarrow, what was the problem with the previous implementation?

$(window).resize(function() {
  resizeTerm(term, ws);
});

$(() => {
  let ws = new WebSocket('ws://' + location.host + '/terminal');
  let term = new Terminal({
    cursorBlink: true,
  });

  term.on('data', command => {
    console.log(command);
    ws.send(
      action('TERMINAL_COMMAND', {
        command,
      })
    );
  });
.....

term is not in resize scope, and it always throw term is not defined when window resize . So resize is not work.

image

In fixed main.js

$(() => {
  let ws = new WebSocket('ws://' + location.host + '/terminal');
  let term = new Terminal({
    cursorBlink: true,
  });
//.......
  ws.onopen = () => {
    ws.send(action('TERMINAL_INIT'));
    ws.send(action('TERMINAL_READY'));
    term.open(document.getElementById('#terminal'), true);
    term.toggleFullscreen(true);
    $(window).resize(function() {
      resizeTerm(term, ws);
    });
  };

I put resize function into ws.open block , it will trigger resize when ws onopen at once. And log has been print in console .

image

rahmanusta commented 4 years ago

Thanks for explanation. I appreciate your effort.