Sendibird exception: WebSocket connection must be made first

Hi, I’m getting so many occurrences of sendbird exception in sentry, most of them related to WebSocket (see image below).

Any ideas of what is causing this issue?

Sendbird version: 3.1.9
React Native version: 0.68.1
React: 18.1.0

Hi @Otavio_Barbosa
you must be connected to the Sendbird server before calling the Sendbird API.
please check which API is called before the error code,
and connect before calling the API thanks.

@Yongjun_Choi
I got this issue on changing AppState from active to inactive (background /closed app)
on change app state from ‘active’ we are calling:

      sendbird.removeAllChannelHandlers();
      sendbird.removeAllConnectionHandlers();
      sendbird.setBackgroundState();

but getting error:

[ERROR   ] [SendBirdException: WebSocket connection must be made first.]

hi @aleksandr.bolshakov
sendbird.setBackgroundState();

If the status changes to the background state, the connection with Sendbird will be lost. Before changing to setForegroundState(), can you check if Sendbird API is called?

Hi, @Yongjun_Choi !
What do you mean?
Check is I calling setForegroundState()

setBackgroundState(); - will disconnect
=> Is there any Sendbird api call before the connection? (here)
setForegroundState(); - try reconnect

@Yongjun_Choi We have handler like this:

  useEffect(() => {
    AppState.addEventListener('change', handleStateChange);

    return () => {
      sendbird.removeAllChannelHandlers();
      sendbird.removeAllConnectionHandlers();
      AppState.removeEventListener('change', handleStateChange);
    };
  }, []);

  const handleStateChange = (newState: string) => {
    if (newState === 'active') {
      sendbird.setForegroundState();
    } else {
      sendbird.setBackgroundState();
    }
  };