From c077bf57c6563a2c0911d53cf1a445732ebd2d0a Mon Sep 17 00:00:00 2001 From: ChK Date: Wed, 4 Feb 2026 17:44:43 +0100 Subject: [PATCH] WS in JS anpassen --- public/WebService.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/WebService.js b/public/WebService.js index 0f89a02..cf5b345 100755 --- a/public/WebService.js +++ b/public/WebService.js @@ -3,7 +3,9 @@ console.log("Meine Document-Location: " + document.location); var lastPingRequest; // Use explicit '/echo' path and a small wrapper to guard sends from other modules -var socketUrl = (location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host + '/echo'; +var socketUrl = (location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/echo'; + +console.log("WebSocket URL: " + socketUrl); // socket wrapper keeps the same global identifier but guards sends when underlying ws is not open var socket = { @@ -11,6 +13,7 @@ var socket = { send: function(msg) { if (this._ws && this._ws.readyState === WebSocket.OPEN) { this._ws.send(msg); + console.log('Sent message with WebSocket.OPEN:', msg); } else { console.warn('Socket not open, dropping message:', msg); } @@ -25,7 +28,7 @@ function connect() { socket._ws = ws; ws.onopen = () => { - console.log('Connected'); + console.log('Connected to WS Server'); reconnectDelay = 1000; if (pingIntervalId) clearInterval(pingIntervalId); pingIntervalId = setInterval(() => {