From 05d26587d96d379c1b9e65fb109aba42f1a593c8 Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Fri, 30 Dec 2022 00:00:02 +0100 Subject: [PATCH] WS cart sets reconnect timeout when planet_id not exists --- src/lib/websocketCart.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/websocketCart.ts b/src/lib/websocketCart.ts index 1440e3b..f411022 100644 --- a/src/lib/websocketCart.ts +++ b/src/lib/websocketCart.ts @@ -85,12 +85,16 @@ export function connectToCart(attempts = 0, maxAttempts = 6) { // TODO user feedback when max retries to reconnect, should refresh // increasing timeout by a factor - const planetId = getCookie('planetId'); - if (!planetId) return console.log('no cookie'); + const planet_id = getCookie('planet_id'); + if (!planet_id) { + const seconds = attempts ** 2; + console.debug(`no cookie. Reconnect will be attempted in ${seconds} seconds.`); + wsReconnectTimeout = setTimeout(() => connectToCart(attempts, maxAttempts), seconds * 1000); + } let url = `wss://${window.location.hostname}/ws/cart`; if (dev) { - url = `ws://${WS_HOST}:${WS_PORT}/ws/cart?planetId=${planetId}`; + url = `ws://${WS_HOST}:${WS_PORT}/ws/cart?planet_id=${planet_id}`; } ws = new WebSocket(url);