Skip to content

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.

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.

using hive;

Chat.connect((ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include "HiveChat.h"

FHiveChat::Connect(FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

Chat::connect([=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

Chat.connect(object : Chat.ConnectListener {
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

Chat.connect(result -> {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import HIVEService

ChatInterface.connect { result in
    if result.isSuccess() {
        // API Call Success
    }
}
#import "HIVEService.h"

[HiveChat connectWithHandler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API Call Success
    }
}];

Reconnection request

The chat connection can be temporarily disconnected depending on network conditions or changes in the app state.

Automatic reconnection request

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 OnConnectStarted event is triggered.

Manual reconnection request

To reconnect manually, call Chat.connect().

Automatic channel rejoin on reconnection

During both manual reconnection and automatic reconnection, the SDK automatically attempts to rejoin only the previously joined channels except PUBLIC channels. PUBLIC channels are not rejoined automatically. If you left a PUBLIC channel, handle it in your game by retrieving the PUBLIC channel list and rejoining it.

Disconnection request

To disconnect the chat, call the disconnect() method of the Chat class.

Note

The chat disconnection request is automatically executed when the app user account logs out.

using hive;

Chat.disconnect((ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include "HiveChat.h"

FHiveChat::Disconnect(FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
    if (Result.IsSuccess()) {
        // API Call Success
    }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

Chat::disconnect([=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

Chat.disconnect(object : Chat.DisconnectListener {
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

Chat.disconnect(result -> {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import HIVEService

ChatInterface.disconnect { result in
    if result.isSuccess() {
        // API Call Success
    }
}
#import "HIVEService.h"

[HiveChat disconnectWithHandler:^(HIVEResultAPI * result) {
    if ([result isSuccess]) {
        // API Call Success
    }
}];

Check connection status

To check whether the app user is currently connected to the chat, call the isConnected method of the Chat class.

using hive;

Boolean isConnected = Chat.isConnected();
#include "HiveChat.h"

bool IsConnected = FHiveChat::IsConnected();
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

bool isConnected = Chat::isConnected();
import com.hive.Chat;

val isConnected = Chat.isConnected()
import com.hive.Chat;

Boolean isConnected = Chat.isConnected();
import HIVEService

let isConnected = ChatInterface.isConnected()
#import "HIVEService.h"

bool isConnected = [ChatInterface isConnected];

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.