WS in JS anpassen

This commit is contained in:
ChK
2026-02-04 17:44:43 +01:00
parent 6c034f2838
commit c077bf57c6

View File

@@ -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(() => {