The plugin provides higher-order functions to create WebSocket event handlers that interact with the Redux store. These handlers manage the connection state, settings, and sidebar button visibility when the WebSocket connects, disconnects, or reconnects.
handleConnect(store): Returns a handler that dispatches ActionTypes.RECEIVED_CONNECTED with connection data and default settings (including sidebar_buttons: Constants.SETTING_BUTTONS_TEAM and daily_reminder: true).handleDisconnect(store): Returns a handler that dispatches ActionTypes.RECEIVED_CONNECTED with connected: false and resets credentials.handleReconnect(store, reminder = false): Returns an async handler that attempts to re-establish connection using getConnected and refreshes Left Hand Side (LHS) data if successful.handleRefresh(store): Returns a handler that refreshes LHS data if the plugin is currently connected.
import { handleConnect, handleDisconnect, handleReconnect, handleRefresh } from './websocket';
// Example usage within a WebSocket listener:
const socket = new WebSocket(url);
// Initialize handlers with the Redux store
const onConnect = handleConnect(store);
const onDisconnect = handleDisconnect(store);
socket.onmessage = (event) => {
// The handlers are designed to be called with the message object
onConnect(event);
};
socket.onclose = () => {
onDisconnect();
};