100ms Logo



Search docs

Reconnecting & Reconnected Callbacks

Reconnecting listener is triggered when the SDK detects a network issue or is trying to reconnect automatically on a network drop, switch etc. The Reconnected listener is triggered when the SDK has successfully recovered from a network drop, switch or a network issue etc.

💡 Note: The SDK tries to reconnect automatically for 60 seconds after that the connection is terminated and the room has to be rejoined.


When in reconnecting state the SDK emits the error Error Code: 1003, Cause: Websocket disconnected which is received in onReconnectingListener.

hmsInstance?.addEventListener(HMSUpdateListenerActions.RECONNECTING, onReconnectingListener); hmsInstance?.addEventListener(HMSUpdateListenerActions.RECONNECTED, onReconnectedListener); const onReconnectingListener = (error: HMSException) => { // show reconnecting... toast }; const onReconnectedListener = () => { // show reconnected toast };

Once the 60 seconds timeout is finished and the peer is not joined back in the room, an error Error Code: 4005, Cause: ICE Connection Failed due to network issue is emitted in onErrorListener.

hmsInstance?.addEventListener(HMSUpdateListenerActions.ON_ERROR, onErrorListener); const onErrorListener = (error: HMSException) => { // show data?.error?.message toast };

Best Practices

  • Once you receive an onReconnectingListener try and avoid the user from interacting with any APIs until onReconnectedListener is received otherwise the APIs might not be successful like join, leave, setMute etc.
  • If 60 seconds timeout is passed and you receive an onErrorListener, check for 4005 error code and redirect back to home screen as the connection is terminated and you will have to again join the room.
const onErrorListener = (error: HMSException) => { if (data?.error?.code === 4005) { // Redirect and try to rejoin once connection is established again } };

💡 Note: You can also measure a user's connection speed. Learn more about connection quality API here