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. At this time, you can pass a string value as the extraData argument to provide additional information. For example, if you pass the app user's nickname string managed by the app's database as additional information, it can be used as the chat nickname in the chat window or for implementing entry event messages like "~ has entered." when entering the channel.

The following is an example code that requests a chat connection.

Warning

The 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;

String extraData = "EXTRA_DATA";
Chat.connect(extraData, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

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

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

String extraData = "EXTRA_DATA";
Chat.connect(extraData, result -> {
    if (result.isSuccess()) {
        // API Call Success
    }
});
import HIVEService

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

NSString *extraData = @"EXTRA_DATA";
[HiveChat connectWithExtraData:extraData handler:^(HIVEResultAPI * result) {
    if (result.isSuccess) {
        // API Call Success
    }
}];

Disconnection request

To disconnect the chat, call the Chat class's disconnect() method. Below is an example code to disconnect the chat.

Note

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

using hive;

Chat.disconnect((ResultAPI 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) {
    if result.isSuccess {
        // API Call Success
    }
}
#import "HIVEService.h"

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

Connection status check

Checks if the app user is currently connected to the chat. Calls the Chat class isConnected method.

The following is an example code to check the chat connection status.

using hive;

Boolean isConnected = Chat.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

Hive detects the connection status of the chat socket server and continuously delivers status change events to the app. For detailed event handling methods, please refer to the Event Management > Connection Events document.