Skip to content

Commit

Permalink
Add support for resizing the lab window
Browse files Browse the repository at this point in the history
Add an observer to the JavaScript code to detect lab size changes
on the LMS page and send the new dimensions to the guacamole client.
  • Loading branch information
Maari Tamm committed Feb 6, 2025
1 parent 5b36637 commit f618a94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions hastexo/public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ function HastexoGuacamoleClient(configuration) {

onidle(pause) {
return pause;
},

sendSize(height, width) {
guac_client.sendSize(height, width);
}
}

Expand Down
9 changes: 9 additions & 0 deletions hastexo/public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ function HastexoXBlock(runtime, element, configuration) {
/* Show the terminal. */
$("#terminal").append(terminal_element);

// Observe the lab size in the browser and adjust when necessary
var lab = $('#terminal')[0];
const resizeObserver = new ResizeObserver(entries => {
for (const entry of entries) {
terminal_client.sendSize(entry.contentRect.width, entry.contentRect.height);
}
});
resizeObserver.observe(lab);

/* Disconnect on tab close. */
window.onunload = function() {
terminal_client.disconnect();
Expand Down
1 change: 1 addition & 0 deletions hastexo_guacamole_client/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async def connect(self):
protocol=stack.protocol,
width=params.get('width', [1024])[0],
height=params.get('height', [768])[0],
resize_method="reconnect",
hostname=stack.ip,
port=params.get('port', [default_port])[0],
username=stack.user,
Expand Down

0 comments on commit f618a94

Please sign in to comment.