Attempt websocket fix

This commit is contained in:
2025-04-21 23:43:50 +02:00
parent 2e265c08f1
commit 2cff41f187
3 changed files with 23 additions and 5 deletions

View File

@@ -51,14 +51,21 @@ export class MudConnection extends EventEmitter {
return;
}
// Connect through the standalone WebSocket server on port 3001
// Determine the WebSocket URL based on environment
const wsProtocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const wsHost = `${window.location.hostname}:3001`;
let wsUrl;
const url = `${wsProtocol}://${wsHost}/mud-ws?host=${encodeURIComponent(this.host)}&port=${this.port}&useSSL=${this.useSSL}`;
console.log('Connecting to WebSocket server:', url);
// In development, use port 3001
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
wsUrl = `${wsProtocol}://${window.location.hostname}:3001/mud-ws?host=${encodeURIComponent(this.host)}&port=${this.port}&useSSL=${this.useSSL}`;
} else {
// In production, use the same domain & port as the web app
wsUrl = `${wsProtocol}://${window.location.host}/mud-ws?host=${encodeURIComponent(this.host)}&port=${this.port}&useSSL=${this.useSSL}`;
}
this.webSocket = new WebSocket(url);
console.log('Connecting to WebSocket server:', wsUrl);
this.webSocket = new WebSocket(wsUrl);
this.webSocket.binaryType = 'arraybuffer';