ช่อง¶
การสร้างช่อง¶
ในการสร้างช่องสนทนาใหม่ ให้สร้างวัตถุ CreateChannelParams
และจากนั้นเรียกใช้วิธี createChannel()
ของคลาส Chat
สร้างพารามิเตอร์ช่อง¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น |
---|---|---|---|
channelId | รหัสช่อง (ตัวอักษรภาษาอังกฤษ, ตัวเลข, และอักขระพิเศษบางตัว ( - , . , _ , ~ , : ) ที่อนุญาต, สูงสุด 100 ตัวอักษร) | สตริง | ใช่ |
password | รหัสผ่าน (จำเป็นเฉพาะสำหรับช่อง PRIVATE )(สูงสุด 50 ตัวอักษร) | สตริง | ไม่ |
channelName | ชื่อช่อง (สูงสุด 50 ตัวอักษร) | สตริง | ใช่ |
maxMemberCount | จำนวนผู้เข้าร่วมช่องสูงสุด (ขั้นต่ำ 2 ถึงสูงสุด 5,000) | จำนวนเต็ม | ใช่ |
type | ประเภทช่อง (PRIVATE , PUBLIC , GROUP ) | enum | ใช่ |
chatHistoryAllowed | ว่าการดึงประวัติการแชทได้รับอนุญาตหรือไม่ | enum | ไม่ |
นี่คือตัวอย่างโค้ดในการสร้างช่องสนทนาใหม่
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
และจากนั้นเรียกใช้วิธี enterChannel()
ของคลาส Chat
ป้อนพารามิเตอร์ช่อง¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท | จำเป็น |
---|---|---|---|
channelId | รหัสช่อง | string | ใช่ |
password | รหัสผ่าน (จำเป็นสำหรับช่อง PRIVATE ) | string | ไม่ |
นี่คือตัวอย่างโค้ดสำหรับการเข้าช่องสนทนา
#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
}
}));
ช่องทางออก¶
ในการออกจากช่องแชทที่คุณเข้าร่วม ให้เรียกใช้วิธี exitChannel()
ของคลาส Chat
นี่คือตัวอย่างโค้ดสำหรับการออกจากช่องสนทนาที่คุณเข้าร่วม
ดูรายการช่องทั้งหมด¶
ในการดึงรายการช่องที่มีอยู่ทั้งหมดในขณะนี้ ให้สร้างวัตถุ GetChannelsParams
และจากนั้นเรียกใช้เมธอด getChannels()
ของคลาส Chat
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 | รหัสช่อง | string |
type | ประเภทช่อง (PRIVATE , PUBLIC , GROUP ) | enum |
owner | เจ้าของช่อง Hive PlayerID | string |
channelName | ชื่อช่อง | string |
memberCount | จำนวนสมาชิกที่เข้าร่วมปัจจุบัน | integer |
maxMemberCount | จำนวนผู้เข้าร่วมสูงสุดในช่อง | integer |
regTime | วันที่และเวลาที่สร้างช่อง (ตาม UTC+0 , รูปแบบ yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | string |
regTimeMillis | วันที่และเวลาที่สร้างช่อง (Unix Timestamp) | long |
chatHistoryAllowed | ว่าการดึงประวัติช่องได้รับอนุญาตหรือไม่ | bool |
query | วิธีการดึงประวัติข้อความช่อง | method |
หน้าช่อง¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท |
---|---|---|
ขนาด | จำนวนรายการต่อหน้า | จำนวนเต็ม |
หน้าปัจจุบัน | หมายเลขหน้าปัจจุบัน | จำนวนเต็ม |
จำนวนทั้งหมด | จำนวนรายการทั้งหมด | จำนวนเต็ม |
จำนวนหน้าทั้งหมด | จำนวนหน้าทั้งหมด | จำนวนเต็ม |
ต่อไปนี้คือตัวอย่างโค้ดเพื่อดึงรายการช่องประเภท 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 Call Success
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 Call Success
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 Call Success
for (Chat::Channel *channel : channels) {
// Retrieve Channel
}
if (channelPage != null) {
// Retrieve ChannelPage
}
}
}];
การดึงข้อมูลช่อง¶
ในการดึงข้อมูลรายละเอียดเกี่ยวกับช่องเฉพาะ ให้เรียกใช้เมธอด getChannelInfo()
ของคลาส Chat
การตอบสนองรวมถึงวัตถุ Channel
และวัตถุ Member
และโครงสร้างมีดังนี้
ช่อง¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท |
---|---|---|
channelId | รหัสช่อง | string |
type | ประเภทช่อง (PRIVATE , PUBLIC , GROUP ) | enum |
owner | เจ้าของช่อง Hive PlayerID | string |
channelName | ชื่อช่อง | string |
memberCount | จำนวนสมาชิกที่เข้าร่วมในปัจจุบัน | integer |
maxMemberCount | จำนวนสมาชิกสูงสุดที่เข้าร่วมช่อง | integer |
regTime | วันที่และเวลาที่สร้างช่อง (ตาม UTC+0 , รูปแบบ yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | string |
regTimeMillis | วันที่และเวลาที่สร้างช่อง (Unix Timestamp) | long |
chatHistoryAllowed | ว่าประวัติช่องสามารถถูกค้นหาได้หรือไม่ | bool |
query | วิธีการค้นหาประวัติข้อความในช่อง | method |
สมาชิก¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท |
---|---|---|
playerId | Hive PlayerID | long |
connectedTime | เวลาการเชื่อมต่อ (ตาม UTC+0 , รูปแบบ yyyy-MM-dd'T'HH:mm:ss.SSSZ ) | string |
connectedTimeeMillis | เวลาการเชื่อมต่อ (Unix Timestamp) | 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
ถ้า (channel != nullptr) {
// ดึงข้อมูล Channel
}
สำหรับ (const FHiveMember& Member : Members) {
// ดึงข้อมูลสมาชิก
}
}
}));
#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
}
สำหรับ (Chat::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
}
}
}];
การสอบถามสมาชิกช่อง¶
ในการดูสมาชิกผู้เข้าร่วมช่อง ให้เรียกใช้วิธี getChannelMembers() ของคลาส Chat
Note
ค่าที่ตอบกลับจะเหมือนกับวัตถุ Member
ที่ส่งจาก getChannelInfo()
.
#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 | สตริงดัชนีที่จำเป็นสำหรับการค้นหาเพิ่มเติม ทิ้งว่างไว้สำหรับการค้นหาครั้งแรก | สตริง | ใช่ |
Channelmessagelistquerylistener¶
ชื่อฟิลด์ | คำอธิบาย | ประเภท |
---|---|---|
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 ตรวจจับสถานะการเชื่อมต่อและส่งเหตุการณ์การเปลี่ยนแปลงสถานะที่เกิดขึ้นระหว่างผู้ใช้แอปและช่องทางไปยังแอปอย่างต่อเนื่อง สำหรับวิธีการจัดการเหตุการณ์อย่างละเอียด โปรดดูเอกสาร การจัดการเหตุการณ์ > เหตุการณ์ช่องทาง