渠道¶
渠道创建¶
要创建一个新的对话频道,请创建一个 CreateChannelParams 对象,然后调用 Chat 类的 createChannel() 方法。
创建频道参数¶
| 字段名称 | 描述 | 类型 | 必需 |
|---|---|---|---|
| channelId | 渠道 ID (允许英文字母、数字和某些特殊字符 ( -, ., _, ~, :),最多 100 个字符) | 字符串 | 是 |
| password | 密码(仅对 PRIVATE 渠道的必填字段)(最多 50 个字符) | 字符串 | 否 |
| channelName | 渠道名称 (最多 50 个字符) | 字符串 | 是 |
| maxMemberCount | 渠道参与者的最大人数 (最少 2 到最多 5,000) | 整数 | 是 |
| type | 渠道类型 (PRIVATE, PUBLIC, GROUP) | 枚举 | 是 |
以下是创建新对话频道的示例代码。
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 <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调用成功
}
}
})
#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调用成功
}
}];
渠道删除¶
要删除现有的聊天频道,请调用Chat类的deleteChannel()方法。
这是一个删除对话频道的示例代码。
渠道条目¶
要进入现有的聊天频道,请创建一个 EnterChannelParams 对象,然后调用 Chat 类的 enterChannel() 方法。
输入通道参数¶
| 字段名称 | 描述 | 类型 | 必需 |
|---|---|---|---|
| channelId | 渠道 ID | 字符串 | 是 |
| password | 密码(PRIVATE 渠道所需) | 字符串 | 否 |
这是一个进入对话频道的示例代码。
渠道退出¶
要退出您参与的聊天频道,请调用Chat类的exitChannel()方法。
这是一个关于退出您参与的对话频道的示例代码。
查看所有频道列表¶
要检索所有当前存在的频道列表,创建一个 GetChannelsParams 对象,然后调用 Chat 类的 getChannels() 方法。
Note
如果您不传递GetChannelsParams对象(如果没有提供对象则传递null),它将返回当前存在的所有频道的完整列表,而不进行过滤。
获取频道参数¶
| 字段名称 | 描述 | 类型 | 必需 |
|---|---|---|---|
| type | 渠道类型(PRIVATE,PUBLIC,GROUP) | 枚举 | Y |
| channelId | 检索以特定频道 ID 开头的频道 | 字符串 | N |
| channelName | 检索包含特定频道名称的频道 | 字符串 | N |
| pageOrder | 排序方式(ASC,DESC)(默认 DESC) | 字符串 | N |
| pageSize | 每页检索的频道数量 (最小 10 ~ 最大 100,默认 10) | 整数 | N |
| pageNumber | 要检索的页码 (从 1 开始,默认 1) | 整数 | N |
Channel对象和ChannelPage对象作为响应提供,结构如下。
渠道¶
| 字段名称 | 描述 | 类型 |
|---|---|---|
| channelId | 频道 ID | 字符串 |
| type | 频道类型 (PRIVATE, PUBLIC, GROUP) | 枚举 |
| owner | 频道所有者的 Hive PlayerID | 字符串 |
| channelName | 频道名称 | 字符串 |
| maxMemberCount | 频道参与者的最大数量 | 整数 |
| regTime | 频道创建日期和时间(基于 UTC+0,格式:yyyy-MM-dd'T'HH:mm:ss.SSSZ) | 字符串 |
渠道页面¶
| 字段名称 | 描述 | 类型 |
|---|---|---|
| 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 <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 | 渠道名称 | 字符串 |
| maxMemberCount | 渠道参与者的最大数量 | 整数 |
| regTime | 渠道创建日期和时间(基于 UTC+0,格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ) | 字符串 |
会员¶
| 字段名称 | 描述 | 类型 |
|---|---|---|
| playerId | Hive 玩家ID | long |
| extraData | 附加数据(基于 UTF-8)(最多256字节) | string |
| connectedTime | 连接时间(基于 UTC+0,格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ) | string |
以下是一个示例代码,用于检索特定频道的详细信息。
#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对象相同。
渠道事件管理¶
Hive 检测聊天套接字服务器的连接状态,并持续将与应用用户和频道发生的状态变化事件传递给应用。有关详细的事件处理方法,请参阅 事件管理 > 频道事件 文档。