Updated random int function to use helper numbers util in ws stream.js
• Updated: - random int function to use helper numbers util in ws stream.js
This commit is contained in:
parent
72162affcf
commit
d73b4afa28
|
@ -1,8 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import WebSocketClient from '@gamestdio/websocket';
|
import WebSocketClient from '@gamestdio/websocket';
|
||||||
|
import { getRandomInt } from './utils/numbers'
|
||||||
const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max));
|
|
||||||
|
|
||||||
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() { }, onDisconnect() { }, onReceive() { } })) {
|
export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() { }, onDisconnect() { }, onReceive() { } })) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
|
@ -14,7 +13,7 @@ export function connectStream(path, pollingRefresh = null, callbacks = () => ({
|
||||||
|
|
||||||
const setupPolling = () => {
|
const setupPolling = () => {
|
||||||
pollingRefresh(dispatch, () => {
|
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() {
|
disconnected() {
|
||||||
if (pollingRefresh) {
|
if (pollingRefresh) {
|
||||||
polling = setTimeout(() => setupPolling(), randomIntUpTo(40000));
|
polling = setTimeout(() => setupPolling(), getRandomInt(0, 40000));
|
||||||
}
|
}
|
||||||
|
|
||||||
onDisconnect();
|
onDisconnect();
|
||||||
|
|
Loading…
Reference in New Issue