Fix async WebAssembly loading in RDP page

- Made connect() function async to properly load WallixModule
- Moved WebAssembly initialization into connect function
- Set module constants after loading
- Ensured module is ready before creating RDP client
parent 9e9f7ec6
......@@ -326,36 +326,10 @@ for (let i = 0; i < layouts.length; ++i) {
let kbdInputLayoutEvent = () => {};
let _Module;
WallixModule({
// INITIAL_MEMORY: 16777216, // 16**6
// INITIAL_MEMORY: 268435456, // 16**7
}).then((Module) => {
_Module = Module;
// optional
const LogLevel = Module.LogLevel;
Module.log = function(priority, msg) {
const logger = (priority === LogLevel.Info) ? console.log
: (priority === LogLevel.Warning) ? console.warn
: (priority === LogLevel.Error) ? console.error
: (priority === LogLevel.Debug) ? (s) => {
console.debug("%c%s", 'color:yellow', s)
}
: console.info;
logger(msg);
};
}).catch((e) => {
console.error('Failed to load WebAssembly module:', e);
showNotification('Failed to load RDP WebAssembly module', 'danger');
});
let _Module = null;
const RdpClient = _Module ? _Module.RdpClient : null;
const ClipboardChannel = _Module ? _Module.ClipboardChannel : null;
const MouseFlags = _Module ? _Module.MouseFlags : null;
const InputFlags = _Module ? _Module.InputFlags : null;
// Constants will be set after module loads
let RdpClient, ClipboardChannel, MouseFlags, InputFlags;
function MultiSelectToInt(e, constants)
{
......@@ -835,7 +809,7 @@ function startRdpConnection() {
connect();
}
function connect() {
async function connect() {
if (connected) return;
// Hide the status text and show loading message
......@@ -843,6 +817,44 @@ function connect() {
document.getElementById('rdp_loading').style.display = 'block';
document.getElementById('cancelConnectBtn').style.display = 'inline-block';
// Load WebAssembly module if not already loaded
if (!_Module) {
try {
_Module = await WallixModule({
// INITIAL_MEMORY: 16777216, // 16**6
// INITIAL_MEMORY: 268435456, // 16**7
});
// optional
const LogLevel = _Module.LogLevel;
_Module.log = function(priority, msg) {
const logger = (priority === LogLevel.Info) ? console.log
: (priority === LogLevel.Warning) ? console.warn
: (priority === LogLevel.Error) ? console.error
: (priority === LogLevel.Debug) ? (s) => {
console.debug("%c%s", 'color:yellow', s)
}
: console.info;
logger(msg);
};
// Set constants now that module is loaded
RdpClient = _Module.RdpClient;
ClipboardChannel = _Module.ClipboardChannel;
MouseFlags = _Module.MouseFlags;
InputFlags = _Module.InputFlags;
} catch (e) {
console.error('Failed to load WebAssembly module:', e);
showNotification('Failed to load RDP WebAssembly module', 'danger');
// Reset UI
document.getElementById('rdp_status').style.display = 'block';
document.getElementById('rdp_loading').style.display = 'none';
document.getElementById('cancelConnectBtn').style.display = 'none';
return;
}
}
const wsProtocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = wsProtocol + '//' + window.location.host + '/rdp/%s/ws';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment