頻道¶
頻道創建¶
要創建一個新的對話頻道,請創建一個 CreateChannelParams
物件,然後調用 Chat 類的 createChannel()
方法。
創建頻道參數¶
欄位名稱 | 描述 | 類型 | 是否必填 |
---|---|---|---|
channelId | 頻道 ID (允許英文字母、數字和某些特殊字符( - 、. 、_ 、~ 、: ),最多 100 個字符) | 字串 | 是 |
password | 密碼(僅對於 PRIVATE 頻道必填)(最多 50 個字符) | 字串 | 否 |
channelName | 頻道名稱 (最多 50 個字符) | 字串 | 是 |
maxMemberCount | 頻道參與者的最大人數 (最少 2 到最多 5,000) | 整數 | 是 |
type | 頻道類型(PRIVATE 、PUBLIC 、GROUP ) | 列舉 | 是 |
chatHistoryAllowed | 是否允許檢索聊天歷史 | 列舉 | 否 |
這是一個創建新對話頻道的示例代碼。
using hive;
CreateChannelParams createChannelParams = new CreateChannelParams();
createChannelParams.channelId = "CHANNEL_ID";
createChannelParams.password = "";
createChannelParams.channelName = "CHANNEL_NAME";
createChannelParams.maxMemberCount = 8;
createChannelParams.type = ChannelType.PUBLIC;
Chat.createChannel(createChannelParams, (ResultAPI result) => {
if (result.isSuccess()) {
// API Call Success
}
});
#include "HiveChat.h"
FHiveCreateChannelParams CreateChannelParams = FHiveCreateChannelParams();
CreateChannelParams.ChannelId = TEXT("CHANNEL_ID");
CreateChannelParams.Password = TEXT("");
CreateChannelParams.ChannelName = TEXT("CHANNEL_NAME");
CreateChannelParams.MaxMemberCount = 8;
CreateChannelParams.Type = EHiveChannelType::Public;
FHiveChat::CreateChannel(CreateChannelParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
if (Result.IsSuccess()) {
// API Call Success
}
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
CreateChannelParams param;
param.channelId = "CHANNEL_ID";
param.channelName = "CHANNEL_NAME";
param.password = "";
param.maxMemberCount = 8;
param.type = ChannelType::PUBLIC;
Chat::createChannel(param, [=](ResultAPI const & result) {
if (result.isSuccess()) {
// API Call Success
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val params = Chat.CreateChannelParams(
channelId = "CHANNEL_ID",
password = "",
channelName = "CHANNEL_NAME",
maxMemberCount = 8,
type = Chat.ChannelType.PUBLIC
)
Chat.createChannel(params, object: Chat.CreateChannelListener{
override fun onResult(result: ResultAPI) {
if (result.isSuccess) {
// API Call Success
}
}
})
#import "HIVEService.h"
HiveChatCreateChannelParams* params = [[HiveChatCreateChannelParams alloc] init];
params.channelId = @"CHANNEL_ID";
params.password = @"";
params.channelName = @"CHANNEL_NAME";
params.maxMemberCount = 8;
params.type = Chat::ChannelType::PUBLIC;
[HiveChat createChannelWithCreateParams:params handler:^(HIVEResultAPI * result) {
if (result.isSuccess) {
// API Call Success
}
}];
渠道刪除¶
要刪除現有的對話頻道,請調用Chat類的deleteChannel()
方法。
這是一個刪除對話頻道的示例代碼。
頻道條目¶
要進入現有的對話頻道,請創建一個 EnterChannelParams
對象,然後調用 Chat 類的 enterChannel()
方法。
進入通道參數¶
欄位名稱 | 描述 | 類型 | 必填 |
---|---|---|---|
channelId | 頻道 ID | 字串 | 是 |
password | 密碼(PRIVATE 頻道必填) | 字串 | 否 |
這裡是一個進入對話頻道的示例代碼。
#include "HiveChat.h"
FHiveEnterChannelParams EnterChannelParams = FHiveEnterChannelParams();
EnterChannelParams.ChannelId = TEXT("CHANNEL_ID");
EnterChannelParams.Password = TEXT("");
FHiveChat::EnterChannel(EnterChannelParams, FHiveChatOnResultDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
if (Result.IsSuccess()) {
// API Call Success
}
}));
渠道退出¶
要退出您参与的聊天频道,请调用Chat类的exitChannel()
方法。
這是一個退出您參與的對話頻道的示例代碼。
查看所有頻道列表¶
要檢索所有當前存在的頻道列表,請創建一個 GetChannelsParams
對象,然後調用 Chat 類的 getChannels()
方法。
Note
如果您不传递 GetChannelsParams
对象(如果没有提供对象则传递 null
),它将返回当前存在的所有频道的完整列表,而不进行过滤。
獲取頻道參數¶
欄位名稱 | 描述 | 類型 | 是否必填 |
---|---|---|---|
type | 頻道類型 (PRIVATE , PUBLIC , GROUP ) | enum | Y |
channelId | 根據特定頻道 ID 檢索頻道 | string | N |
channelName | 根據特定頻道名稱檢索頻道 | string | N |
sort | 頻道排序標準 (ChannelId , ChannelName , RegTime ) | enum | N |
pageOrder | 排序方法 (ASC , DESC )(預設為 DESC ) | string | N |
pageSize | 每頁檢索的頻道數量 (最少 10 ~ 最多 100,預設為 10) | integer | N |
pageNumber | 要檢索的頁碼 (從 1 開始,預設為 1) | integer | N |
Channel
物件和 ChannelPage
物件作為回應提供,結構如下。
頻道¶
字段名称 | 描述 | 类型 |
---|---|---|
channelId | 频道 ID | 字符串 |
type | 频道类型 (PRIVATE , PUBLIC , GROUP ) | 枚举 |
owner | 频道所有者的 Hive 玩家 ID | 字符串 |
channelName | 频道名称 | 字符串 |
memberCount | 当前参与成员的数量 | 整数 |
maxMemberCount | 频道中最大参与者数量 | 整数 |
regTime | 频道创建日期和时间(基于 UTC+0 ,格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | 字符串 |
regTimeMillis | 频道创建日期和时间(Unix 时间戳) | 长整型 |
chatHistoryAllowed | 是否允许检索频道历史 | 布尔值 |
query | 检索频道消息历史的方法 | 方法 |
頻道頁面¶
欄位名稱 | 描述 | 類型 |
---|---|---|
size | 每頁項目數量 | 整數 |
currentPage | 當前頁碼 | 整數 |
totalElements | 總項目數 | 整數 |
totalPages | 總頁數 | 整數 |
以下是一個範例代碼,用於檢索所有現有的PUBLIC
類型頻道的列表。
using hive;
GetChannelsParams getChannelsParams = new GetChannelsParams();
getChannelsParams.type = ChannelType.PUBLIC;
Chat.getChannels(getChannelsParams, (ResultAPI result, List<Channel> channels, ChannelPage channelPage) => {
if (result.isSuccess()) {
// API Call Success
foreach (Channel channel in channels) {
// Retrieve Channel
}
if (channelPage != null) {
// Retrieve ChannelPage
}
}
});
#include "HiveChat.h"
TOptional<FHiveGetChannelsParams> GetChannelsParams = FHiveGetChannelsParams();
GetChannelsParams->Type = EHiveChannelType::Public;
FHiveChat::GetChannels(GetChannelsParams, FHiveChatOnGetChannelsDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FHiveChannel>& channels, FHiveChannelPage const & channelPage) {
if (Result.IsSuccess()) {
// API Call Success
for (const FHiveChannel& Channel : Channels) {
// Retrieve Channel
}
if (ChannelPage != nullptr) {
// Retrieve ChannelPage
}
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
Chat::GetChannelsParams params = Chat::GetChannelsParams();
params.type = Chat::ChannelType::PUBLIC;
Chat::getChannels(param, [=](ResultAPI const & result, std::vector<Channel> const & channels, ChannelPage const & pageInfo) {
if (result.isSuccess()) {
// API 呼叫成功
for (Chat::Channel channel : channels) {
// Retrieve Channel
}
if (channelPage != null) {
// Retrieve ChannelPage
}
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val params = Chat.GetChannelsParams(type = Chat.ChannelType.PUBLIC)
Chat.getChannels(params, object: Chat.GetChannelsListener{
override fun onResult(
result: ResultAPI,
channels: ArrayList<Chat.Channel>,
channelPage: Chat.ChannelPage?
) {
if (result.isSuccess) {
// API 呼叫成功
channels.forEach {
// Retrieve Channel
}
channelPage?.let {
// Retrieve ChannelPage
}
}
}
})
import com.hive.Chat;
Chat.GetChannelsParams params = new Chat.GetChannelsParams(Chat.ChannelType.PUBLIC, null, null, null, null, null);
Chat.getChannels(params, (result, channels, channelPage) -> {
if (result.isSuccess()) {
// API Call Success
for (Chat.Channel channel : channels) {
// Retrieve Channel
}
if (channelPage != null) {
// Retrieve ChannelPage
}
}
});
import HIVEService
let params = HiveChatParams.GetChannelsParams(type: .public, null, null, null, null, null)
ChatInterface.getChannels(getChannelsParams: params) { result, channels, pageInfo in
if result.isSuccess {
channels.forEach {
// Retrieve Channel
}
channelPage?.let {
// Retrieve ChannelPage
}
}
}
#import "HIVEService.h"
HiveChatGetChannelsParams* params = [[HiveChatGetChannelsParams alloc] init];
params.type = Chat::ChannelType::PUBLIC;
[HiveChat getChannelsWithGetChannelsParams:params handler:^(HIVEResultAPI * result, NSArray<HiveChatChannelContent *> * channels, HiveChatPageInfo * pageInfo) {
if (result.isSuccess) {
// API 呼叫成功
for (Chat::Channel *channel : channels) {
// Retrieve Channel
}
if (channelPage != null) {
// Retrieve ChannelPage
}
}
}];
渠道信息檢索¶
要檢索有關特定頻道的詳細信息,請調用Chat類的getChannelInfo()
方法。
回應包括Channel
物件和Member
物件,結構如下。
頻道¶
字段名稱 | 描述 | 類型 |
---|---|---|
channelId | 頻道 ID | 字串 |
type | 頻道類型 (PRIVATE , PUBLIC , GROUP ) | 列舉 |
owner | 頻道擁有者的 Hive PlayerID | 字串 |
channelName | 頻道名稱 | 字串 |
memberCount | 目前參與成員的數量 | 整數 |
maxMemberCount | 頻道參與者的最大數量 | 整數 |
regTime | 頻道創建日期和時間(基於 UTC+0 ,格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | 字串 |
regTimeMillis | 頻道創建日期和時間(Unix 時間戳) | 長整數 |
chatHistoryAllowed | 是否可以查詢頻道歷史 | 布林 |
query | 查詢頻道消息歷史的方法 | 方法 |
會員¶
欄位名稱 | 描述 | 類型 |
---|---|---|
playerId | Hive 玩家ID | long |
connectedTime | 連接時間(基於 UTC+0 ,格式為 yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | string |
connectedTimeeMillis | 連接時間(Unix 時間戳) | long |
以下是檢索特定頻道詳細信息的示例代碼。
#include "HiveChat.h"
FString ChannelId = TEXT("CHANNEL_ID");
FHiveChat::GetChannelInfo(ChannelId, FHiveChatOnGetChannelInfoDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FHiveChannel& channel, const TArray<FHiveMember>& members) {
if (Result.IsSuccess()) {
// API Call Success
if (channel != nullptr) {
// Retrieve Channel
}
for (const FHiveMember& Member : Members) {
// Retrieve Member
}
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
std::string channelId = "CHANNEL_ID";
Chat::getChannelInfo(channelId, [=](ResultAPI const & result, Channel const & channel, std::vector<Member> const & members) {
if (result.isSuccess()) {
if (channel != null) {
// Retrieve Channel
}
for (Chat::Member member : members) {
// Retrieve Member
}
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val channelId = "CHANNEL_ID"
Chat.getChannelInfo(channelId, object: Chat.GetChannelInfoListener {
override fun onResult(
result: ResultAPI,
channel: Chat.Channel?,
members: ArrayList<Chat.Member>
) {
if (result.isSuccess) {
channel?.let {
// Retrieve Channel
}
members.forEach {
// Retrieve Member
}
}
}
})
#import "HIVEService.h"
NSString *channelId = @"CHANNEL_ID";
[HiveChat getChannelInfoWithChannelId:channelId handler:^(HIVEResultAPI * result, HiveChatChannelContent * channel, NSArray<HiveChatMember *> * members) {
if (result.isSuccess) {
if (channel != null) {
// Retrieve Channel
}
for (Chat::Member *member : members) {
// Retrieve Member
}
}
}];
頻道成員查詢¶
要查看频道参与者成员,请调用Chat类的getChannelMembers()
方法。
Note
响应值与从getChannelInfo()
传递的Member
对象相同。
#include "HiveChat.h"
FString ChannelId = TEXT("CHANNEL_ID");
FHiveChat::GetChannelMembers(ChannelId, FHiveChatOnGetChannelMembersDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FHiveMember>& members) {
if (Result.IsSuccess()) {
for (const FHiveMember& Member : members) {
// Retrieve Member
}
}
}));
頻道消息歷史查詢¶
呼叫channel.query(ChannelMessageListQueryParams, ChannelMessageListQueryListener)
方法以檢索先前的聊天記錄。
只有將屬性 chatHistoryAllowed
設置為 true
的頻道才能檢索歷史記錄。
頻道消息列表查詢參數¶
欄位名稱 | 描述 | 類型 | 必需 |
---|---|---|---|
size | 要接收的消息大小(最小1 ~ 最大50) | 整數 | 是 |
index | 進行額外查詢所需的索引字串。第一次查詢請留空 | 字串 | 是 |
頻道訊息列表查詢監聽器¶
欄位名稱 | 描述 | 類型 |
---|---|---|
hasNext | 一個標誌,指示是否可以進行額外的查詢 | long |
nextIndex | 進行額外查詢所需的索引字串 | string |
content | 一個檢索到的 ChannelMessage 物件的陣列 | ChannelMessage |
using hive;
ChannelMessageListQueryParams queryParams = new ChannelMessageListQueryParams(10, "");
channel.query(queryParams, (ResultAPI result, ChannelMessageListQueryResponse response) => {
if (result.isSuccess() && response != null) {
foreach (ChannelMessage message in response.content) {
// channel message list
}
}
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;
ChannelMessageListQueryParams queryParams;
params.size = 10;
params.queryIndex = "";
channel.query(queryParams, [=](ResultAPI const & result, ChannelMessageListQueryResponse const & response) {
if (result.isSuccess()) {
for (auto message : response.message) {
// channel message list
}
}
});
import com.hive.Chat;
import com.hive.ResultAPI;
val queryParams = Chat.ChannelMessageListQueryParams(size = 50)
channel.query(queryParams, object : Chat.ChannelMessageListQueryListener {
override fun onResult(
result: ResultAPI,
response: Chat.ChannelMessageListQueryResponse?
) {
if(result.isSuccess && response != null) {
response.content.forEach {
// channel message list
}
}
}
})
import com.hive.Chat;
Chat.ChannelMessageListQueryParams queryParams = new Chat.ChannelMessageListQueryParams(50);
channel.query(queryParams, (result, response) -> {
if (result.isSuccess() && response != null) {
for (HiveChatChannelMessage message : response.getContent()) {
// channel message list
}
}
});
#import "HIVEService.h"
HiveChatChannelMessageListQueryParams *queryParams = [[HiveChatChannelMessageListQueryParams alloc] initWithSize:10 index:@""];
[channel queryWithParams:queryParams listener:^(HIVEResultAPI * result, HiveChatChannelMessageListQueryResponse* response) {
if (result.isSuccess() && response.content) {
for (HiveChatChannelMessage *message in response.content) {
// channel message list
}
}
}];
頻道自動翻譯接收設置¶
您可以設定是否接收來自此頻道的自動翻譯消息。
翻譯的消息可以在接收到的 ChannelMessage 物件中檢查。
頻道事件管理¶
Hive 聊天插座伺服器檢測連接狀態,並持續將應用程式用戶與頻道之間發生的狀態變更事件傳遞給應用程式。有關詳細的事件處理方法,請參考 事件管理 > 頻道事件 文件。