From d73b4afa2819d9766e727e6e030c80e6b09c8cc3 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Wed, 10 Feb 2021 23:21:35 -0500 Subject: [PATCH] Updated random int function to use helper numbers util in ws stream.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Updated: - random int function to use helper numbers util in ws stream.js --- app/javascript/gabsocial/stream.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/javascript/gabsocial/stream.js b/app/javascript/gabsocial/stream.js index 46998340..ff5b960d 100644 --- a/app/javascript/gabsocial/stream.js +++ b/app/javascript/gabsocial/stream.js @@ -1,8 +1,7 @@ 'use strict'; import WebSocketClient from '@gamestdio/websocket'; - -const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max)); +import { getRandomInt } from './utils/numbers' export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() { }, onDisconnect() { }, onReceive() { } })) { return (dispatch, getState) => { @@ -14,7 +13,7 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({ const setupPolling = () => { pollingRefresh(dispatch, () => { - polling = setTimeout(() => setupPolling(), 20000 + randomIntUpTo(20000)); + polling = setTimeout(() => setupPolling(), 20000 + getRandomInt(0, 20000)); }); }; @@ -36,7 +35,7 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({ disconnected() { if (pollingRefresh) { - polling = setTimeout(() => setupPolling(), randomIntUpTo(40000)); + polling = setTimeout(() => setupPolling(), getRandomInt(0, 40000)); } onDisconnect();