perf: reduce presence update frequency and fix background tab throttling (#13726)
## Description Reduces the frequency of update_presence WebSocket calls from the live chat widget and fixes agents appearing offline when the dashboard is in a background tab. ## Fixes # (issue) https://github.com/chatwoot/chatwoot/issues/13720 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
committed by
GitHub
parent
f4e6aa1bd2
commit
11826e2a21
@@ -6,7 +6,12 @@ const RECONNECT_INTERVAL = 1000;
|
||||
class BaseActionCableConnector {
|
||||
static isDisconnected = false;
|
||||
|
||||
constructor(app, pubsubToken, websocketHost = '') {
|
||||
constructor(
|
||||
app,
|
||||
pubsubToken,
|
||||
websocketHost = '',
|
||||
presenceInterval = PRESENCE_INTERVAL
|
||||
) {
|
||||
const websocketURL = websocketHost ? `${websocketHost}/cable` : undefined;
|
||||
|
||||
this.consumer = createConsumer(websocketURL);
|
||||
@@ -37,7 +42,7 @@ class BaseActionCableConnector {
|
||||
setTimeout(() => {
|
||||
this.subscription.updatePresence();
|
||||
this.triggerPresenceInterval();
|
||||
}, PRESENCE_INTERVAL);
|
||||
}, presenceInterval);
|
||||
};
|
||||
this.triggerPresenceInterval();
|
||||
}
|
||||
|
||||
@@ -13,9 +13,11 @@ const isMessageInActiveConversation = (getters, message) => {
|
||||
return activeConversationId && conversationId !== activeConversationId;
|
||||
};
|
||||
|
||||
const WIDGET_PRESENCE_INTERVAL = 60000;
|
||||
|
||||
class ActionCableConnector extends BaseActionCableConnector {
|
||||
constructor(app, pubsubToken) {
|
||||
super(app, pubsubToken);
|
||||
super(app, pubsubToken, '', WIDGET_PRESENCE_INTERVAL);
|
||||
this.events = {
|
||||
'message.created': this.onMessageCreated,
|
||||
'message.updated': this.onMessageUpdated,
|
||||
|
||||
Reference in New Issue
Block a user