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 78b605e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 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
31 changes: 18 additions & 13 deletions hastexo_guacamole_client/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ async def connect(self):

self.read_only = bool(strtobool(params.get('read_only')[0]))

connection_args = {
'protocol': stack.protocol,
'width': params.get('width', [1024])[0],
'height': params.get('height', [768])[0],
'hostname': stack.ip,
'port': params.get('port', [default_port])[0],
'username': stack.user,
'password': stack.password,
'private-key': stack.key,
'color-scheme': settings.get("terminal_color_scheme"),
"font-name": settings.get("terminal_font_name"),
"font-size": settings.get("terminal_font_size"),
}

if stack.protocol == 'rdp':
connection_args['resize-method'] = 'reconnect'

self.client = GuacamoleClient(guacd_hostname, guacd_port)
self.client.handshake(
protocol=stack.protocol,
width=params.get('width', [1024])[0],
height=params.get('height', [768])[0],
hostname=stack.ip,
port=params.get('port', [default_port])[0],
username=stack.user,
password=stack.password,
private_key=stack.key,
color_scheme=settings.get("terminal_color_scheme"),
font_name=settings.get("terminal_font_name"),
font_size=settings.get("terminal_font_size"),
)
self.client.handshake(**connection_args)

if self.client.connected:
# start receiving data from GuacamoleClient
Expand Down

0 comments on commit 78b605e

Please sign in to comment.