mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 20:18:08 +00:00
Move the reconnect logic from the update presence (#6992)
This commit is contained in:
@@ -2,6 +2,7 @@ import { createConsumer } from '@rails/actioncable';
|
|||||||
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
||||||
|
|
||||||
const PRESENCE_INTERVAL = 20000;
|
const PRESENCE_INTERVAL = 20000;
|
||||||
|
const RECONNECT_INTERVAL = 1000;
|
||||||
|
|
||||||
class BaseActionCableConnector {
|
class BaseActionCableConnector {
|
||||||
static isDisconnected = false;
|
static isDisconnected = false;
|
||||||
@@ -25,6 +26,7 @@ class BaseActionCableConnector {
|
|||||||
disconnected: () => {
|
disconnected: () => {
|
||||||
BaseActionCableConnector.isDisconnected = true;
|
BaseActionCableConnector.isDisconnected = true;
|
||||||
this.onDisconnected();
|
this.onDisconnected();
|
||||||
|
this.initReconnectTimer();
|
||||||
// TODO: Remove this after completing the conversation list refetching
|
// TODO: Remove this after completing the conversation list refetching
|
||||||
window.bus.$emit(BUS_EVENTS.WEBSOCKET_DISCONNECT);
|
window.bus.$emit(BUS_EVENTS.WEBSOCKET_DISCONNECT);
|
||||||
},
|
},
|
||||||
@@ -32,11 +34,11 @@ class BaseActionCableConnector {
|
|||||||
);
|
);
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.events = {};
|
this.events = {};
|
||||||
|
this.reconnectTimer = null;
|
||||||
this.isAValidEvent = () => true;
|
this.isAValidEvent = () => true;
|
||||||
this.triggerPresenceInterval = () => {
|
this.triggerPresenceInterval = () => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.subscription.updatePresence();
|
this.subscription.updatePresence();
|
||||||
this.checkConnection();
|
|
||||||
this.triggerPresenceInterval();
|
this.triggerPresenceInterval();
|
||||||
}, PRESENCE_INTERVAL);
|
}, PRESENCE_INTERVAL);
|
||||||
};
|
};
|
||||||
@@ -48,11 +50,28 @@ class BaseActionCableConnector {
|
|||||||
const isReconnected =
|
const isReconnected =
|
||||||
BaseActionCableConnector.isDisconnected && isConnectionActive;
|
BaseActionCableConnector.isDisconnected && isConnectionActive;
|
||||||
if (isReconnected) {
|
if (isReconnected) {
|
||||||
|
this.clearReconnectTimer();
|
||||||
this.onReconnect();
|
this.onReconnect();
|
||||||
BaseActionCableConnector.isDisconnected = false;
|
BaseActionCableConnector.isDisconnected = false;
|
||||||
|
} else {
|
||||||
|
this.initReconnectTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearReconnectTimer = () => {
|
||||||
|
if (this.reconnectTimer) {
|
||||||
|
clearTimeout(this.reconnectTimer);
|
||||||
|
this.reconnectTimer = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
initReconnectTimer = () => {
|
||||||
|
this.clearReconnectTimer();
|
||||||
|
this.reconnectTimer = setTimeout(() => {
|
||||||
|
this.checkConnection();
|
||||||
|
}, RECONNECT_INTERVAL);
|
||||||
|
};
|
||||||
|
|
||||||
onReconnect = () => {};
|
onReconnect = () => {};
|
||||||
|
|
||||||
onDisconnected = () => {};
|
onDisconnected = () => {};
|
||||||
|
|||||||
Reference in New Issue
Block a user