Chat server connection¶
The Hive SDK Chat feature uses WebSocket communication with the Hive Chat socket server. Therefore, to use the Hive SDK Chat feature, you must first refer to the guide below to connect to the Hive Chat socket server.
Connection request¶
To connect to the chat, call the connect method of the Chat class.
Here is an example code that requests a Chat connection.
Warning
Hive SDK Chat feature can only be used by users (including guest accounts) who have logged in using the Hive SDK Authentication feature and have been issued a PlayerID.
Reconnection request¶
The chat connection can be temporarily disconnected depending on network conditions or changes in the app state.
Situations that trigger automatic reconnection¶
If one of the following situations occurs, the SDK starts automatic reconnection.
- If the network connection is temporarily unavailable
- If the app returns to the foreground after being in the background
- If the connection is closed due to a temporary server issue
When automatic reconnection starts, the OnReconnectStarted event is triggered.
Manual reconnection request¶
If you need to reconnect immediately without waiting for automatic reconnection, call Chat.reconnect(). If you request reconnection within 10 minutes after the chat socket server connection is disconnected, the SDK automatically attempts to rejoin the channels you previously joined. The response returns a list of channels that were rejoined successfully and a list of channels that failed.
Example code for a manual reconnection request¶
Here is an example code for requesting a chat reconnection.
Disconnection request¶
To disconnect the chat, call the Chat class's disconnect() method. Below is an example code for disconnecting the chat connection.
Note
The chat disconnection request is automatically executed when the app user account logs out.
Check connection status¶
Checks if the app user is currently connected to the chat. Calls the Chat class isConnected method.
Here is an example code to check the chat connection status.
Connection event management¶
The Hive Chat socket server detects the connection status and continuously delivers status change events to the app. For detailed event handling methods, please refer to the Event Management > Connection Events document.