WS in JS anpassen
This commit is contained in:
@@ -3,7 +3,9 @@ console.log("Meine Document-Location: " + document.location);
|
|||||||
var lastPingRequest;
|
var lastPingRequest;
|
||||||
|
|
||||||
// Use explicit '/echo' path and a small wrapper to guard sends from other modules
|
// 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
|
// socket wrapper keeps the same global identifier but guards sends when underlying ws is not open
|
||||||
var socket = {
|
var socket = {
|
||||||
@@ -11,6 +13,7 @@ var socket = {
|
|||||||
send: function(msg) {
|
send: function(msg) {
|
||||||
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
if (this._ws && this._ws.readyState === WebSocket.OPEN) {
|
||||||
this._ws.send(msg);
|
this._ws.send(msg);
|
||||||
|
console.log('Sent message with WebSocket.OPEN:', msg);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Socket not open, dropping message:', msg);
|
console.warn('Socket not open, dropping message:', msg);
|
||||||
}
|
}
|
||||||
@@ -25,7 +28,7 @@ function connect() {
|
|||||||
socket._ws = ws;
|
socket._ws = ws;
|
||||||
|
|
||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
console.log('Connected');
|
console.log('Connected to WS Server');
|
||||||
reconnectDelay = 1000;
|
reconnectDelay = 1000;
|
||||||
if (pingIntervalId) clearInterval(pingIntervalId);
|
if (pingIntervalId) clearInterval(pingIntervalId);
|
||||||
pingIntervalId = setInterval(() => {
|
pingIntervalId = setInterval(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user