WS in JS anpassen
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user