reconnect on ws connection loss
This commit is contained in:
parent
459664a9a8
commit
90f8bb67b3
@ -14,10 +14,11 @@ let area;
|
|||||||
let ws;
|
let ws;
|
||||||
|
|
||||||
const uuid = self.crypto.randomUUID();
|
const uuid = self.crypto.randomUUID();
|
||||||
|
const wsUrl = "ws://localhost:3000/ws";
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
area = document.querySelector(`#${areaId}`);
|
area = document.querySelector(`#${areaId}`);
|
||||||
ws = new WebSocket("ws://localhost:3000/ws");
|
ws = new WebSocket(wsUrl);
|
||||||
|
|
||||||
setupUi();
|
setupUi();
|
||||||
setupWs();
|
setupWs();
|
||||||
@ -29,6 +30,12 @@ function setupUi() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupWs() {
|
function setupWs() {
|
||||||
|
ws.onclose = function () {
|
||||||
|
setTimeout(() => {
|
||||||
|
ws = new WebSocket(wsUrl);
|
||||||
|
}, 2000);
|
||||||
|
};
|
||||||
|
|
||||||
ws.onmessage = function (e) {
|
ws.onmessage = function (e) {
|
||||||
let payload = JSON.parse(e.data);
|
let payload = JSON.parse(e.data);
|
||||||
if (payload.client !== uuid) {
|
if (payload.client !== uuid) {
|
||||||
@ -37,7 +44,7 @@ function setupWs() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSelectionChange(event) {
|
function onSelectionChange() {
|
||||||
const activeElement = document.activeElement;
|
const activeElement = document.activeElement;
|
||||||
|
|
||||||
if (activeElement && activeElement.id === areaId) {
|
if (activeElement && activeElement.id === areaId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user