From 00888e3b3724a2597e31820a3bdf82bb81f78fee Mon Sep 17 00:00:00 2001 From: PWhiddy Date: Mon, 12 Feb 2024 03:46:02 -0500 Subject: [PATCH] add new ws server --- visualizer_live.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/visualizer_live.js b/visualizer_live.js index 6933483..d8307bd 100644 --- a/visualizer_live.js +++ b/visualizer_live.js @@ -11,6 +11,7 @@ const app = new PIXI.Application({ } }); +let socketOld = null; let socket = null; let lastFrameTime = Date.now(); @@ -162,8 +163,8 @@ PIXI.Assets.load([ container.addChild(backgroundSharp); // Function to initialize WebSocket connection - function initializeWebSocket() { - const ws = new WebSocket('wss://poke-ws-test-ulsjzjzwpa-ue.a.run.app/receive'); + function initializeWebSocket(url) { + const ws = new WebSocket(url); ws.onmessage = function(event) { const data = JSON.parse(event.data); // Assuming the data is JSON-encoded const path = data["coords"]; @@ -176,14 +177,22 @@ PIXI.Assets.load([ return ws; } - socket = initializeWebSocket(); + const refreshWS = () => { + console.log("Refreshing WebSocket connection."); + if (socketOld !== null) { + socketOld.close(); // Close the current connection + } + socketOld = initializeWebSocket("wss://poke-ws-test-ulsjzjzwpa-ue.a.run.app/receive"); // Reinitialize the connection + if (socket !== null) { + socket.close(); // Close the current connection + } + socket = initializeWebSocket("wss://transdimensional.xyz/receive"); + }; + + refreshWS(); // Refresh WebSocket connection every 2 minutes (120000 milliseconds) - setInterval(() => { - console.log("Refreshing WebSocket connection."); - socket.close(); // Close the current connection - socket = initializeWebSocket(); // Reinitialize the connection - }, 120000); + setInterval(refreshWS, 120000); let baseTextureChar = new PIXI.BaseTexture("assets/characters_transparent.png", { scaleMode: PIXI.SCALE_MODES.NEAREST,