[Problem/Question]
I have a React app that uses SendBird, and I’ve been trying to implement a “connection-snooze” that would disconnect the WebSocket connection if the browser tab has been idle for a certain period of time to reduce PCC.
However, when the connection is re-established, the Channel component seems to not realize that connection has been re-established, at least not fully. If there are new messages, those are pulled in, however the message input is disabled and the “Trying to reconnect…” text persists at the bottom.
I tried a hack to recreate the component when the reconnection happens, however that causes an error:
SendbirdError: Connection is required.
// If problem, please fill out the below. If question, please delete.
[UIKit Version]
@sendbird/uikit-reactt: 3.8.2
@sendbird/chat: 4.10.3
[Reproduction Steps]
I have an idle tracker set up in the useEffect of the component that houses the chat UI implementation:
const idleTracker = new IdleTracker({
timeout: 1000 * 10,
onIdleCallback: ({ idle }) => {
if (idle) {
if (sdkInstance.connectionState === ConnectionState.OPEN) {
sendbirdSelectors.getDisconnect(globalStore)();
}
} else {
if (sdkInstance.connectionState === ConnectionState.CLOSED) {
sendBirdSelectors.getConnect(globalStore)(
context.getCurrentUser()?.username as string,
MessagingService.getService().getAccessToken(),
);
}
}
},
});
idleTracker.start();
if (sdkInstance?.addConnectionHandler) {
const connectionHandlerId = uuidv4();
sdkInstance.addConnectionHandler(
connectionHandlerId,
new ConnectionHandler({
onConnected: (userId: string) => {
console.log('connected');
},
onReconnectFailed: () => {
console.log('reconnect failed');
},
onDisconnected: (userId: string) => {
console.log('disconnected');
},
onReconnectStarted: () => {
console.log('start reconnect');
},
onReconnectSucceeded: () => {
console.log('reconnection succeeded');
},
}),
);
}
f I add debug to getConnect via the promise it returns, the sdkInstance.connectionState does return “OPEN”, but the full SendBird system doesn’t seem to register that state, and the connection handler does provide the “disconnected” and “connected” events. The user returned by re-establishing the connection is also the right one.
[Frequency]
Always
[Current impact]
Due to the use case, there’s a high likelyhood of “idle” messaging instances running around and that might lead to an inflated PCC even though users aren’t actively using it. Not being able to curb this could balloon our bill with zero value added to users.