ข้ามไปที่เนื้อหา

ช่อง

การสร้างช่อง

ในการสร้างช่องสนทนาใหม่ ให้สร้างวัตถุ CreateChannelParams และจากนั้นเรียกใช้วิธี createChannel() ของคลาส Chat

สร้างพารามิเตอร์ช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท จำเป็น
channelId รหัสช่อง
(ตัวอักษรภาษาอังกฤษ, ตัวเลข, และอักขระพิเศษบางตัว (-, ., _, ~, :) ที่อนุญาต, สูงสุด 100 ตัวอักษร)
string Y
password รหัสผ่าน (ฟิลด์ที่จำเป็นเฉพาะสำหรับช่อง PRIVATE)
(สูงสุด 50 ตัวอักษร)
string N
channelName ชื่อช่อง
(สูงสุด 50 ตัวอักษร)
string Y
maxMemberCount จำนวนผู้เข้าร่วมช่องสูงสุด
(ขั้นต่ำ 2 ถึงสูงสุด 5,000)
integer Y
type ประเภทช่อง (PRIVATE, PUBLIC, GROUP) enum Y

ต่อไปนี้คือตัวอย่างโค้ดสำหรับการสร้างช่องสนทนาใหม่

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 Call Success
        }
    }
})
import com.hive.Chat;

Chat.CreateChannelParams params = new Chat.CreateChannelParams(
    "CHANNEL_ID",
    "",
    "CHANNEL_NAME",
    8,
    Chat.ChannelType.PUBLIC
);

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

let params = Chat.CreateChannelParams(
    channelId: "CHANNEL_ID",
    password: "",
    channelName: "CHANNEL_NAME",
    maxMemberCount: 8,
    type: .public
)
ChatInterface.createChannel(params) { result in
    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()

นี่คือตัวอย่างโค้ดสำหรับการลบช่องสนทนา

using hive;

String channelId = "CHANNEL_ID";

Chat.deleteChannel(channelId, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

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

val channelId = "CHANNEL_ID"

Chat.deleteChannel(channelId, object: Chat.DeleteChannelListener{
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

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

let channelId = "CHANNEL_ID"
ChatInterface.deleteChannel(channelId: channelId) { result in
    if result.isSuccess {
        // API Call Success
    }
}
#import "HIVEService.h"

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

การเข้าช่อง

ในการเข้าสู่ช่องแชทที่มีอยู่ ให้สร้างวัตถุ EnterChannelParams และจากนั้นเรียกใช้วิธี enterChannel() ของคลาส Chat

ป้อนพารามิเตอร์ช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท จำเป็น
channelId รหัสช่อง string ใช่
password รหัสผ่าน (จำเป็นสำหรับช่อง PRIVATE) string ไม่

นี่คือตัวอย่างโค้ดสำหรับการเข้าร่วมช่องสนทนา

using hive;

EnterChannelParams enterChannelParams = new EnterChannelParams();
enterChannelParams.channelId = "CHANNEL_ID";
enterChannelParams.password = "";

Chat.enterChannel(enterChannelParams, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

EnterChannelParams param;
param.channelId = "CHANNEL_ID";
param.password = "";

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

val params = Chat.EnterChannelParams(
    channelId = "CHANNEL_ID",
    password = ""
)

Chat.enterChannel(params, object: Chat.EnterChannelListener{
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

Chat.EnterChannelParams params = new Chat.EnterChannelParams(
    "CHANNEL_ID",
    ""
);

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

let params = HiveChatParams.EnterChannelParams(
    channelId: "CHANNEL_ID",
    password: ""
)

ChatInterface.enterChannel(enterChannelParams: params) { result in
    if result.isSuccess {
        // API Call Success
    }
}
#import "HIVEService.h"

HiveChatEnterChannelParams* params = [[HiveChatEnterChannelParams alloc] init];
params.channelId = @"CHANNEL_ID";
params.password = @"";

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

ช่องทางออก

ในการออกจากช่องแชทที่คุณเข้าร่วม ให้เรียกใช้คลาส Chat เมธอด exitChannel()

นี่คือตัวอย่างโค้ดสำหรับการออกจากช่องสนทนาที่คุณเข้าร่วม

using hive;

String channelId = "CHANNEL_ID";

Chat.exitChannel(channelId, (ResultAPI result) => {
    if (result.isSuccess()) {
        // API Call Success
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

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

val channelId = "CHANNEL_ID"

Chat.exitChannel(channelId, object: Chat.ExitChannelListener {
    override fun onResult(result: ResultAPI) {
        if (result.isSuccess) {
            // API Call Success
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

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

let channelId = "CHANNEL_ID"
ChatInterface.exitChannel(channelId: channelId) { result in
    if result.isSuccess {
        // API Call Success
    }
}
#import "HIVEService.h"

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

ดูรายการช่องทั้งหมด

ในการดึงรายการช่องที่มีอยู่ทั้งหมดในปัจจุบัน ให้สร้างวัตถุ GetChannelsParams และจากนั้นเรียกใช้วิธี getChannels() ของคลาส Chat

Note

หากคุณไม่ส่งวัตถุ GetChannelsParams (ส่ง null หากไม่มีวัตถุที่ให้ไว้) มันจะส่งคืนรายการทั้งหมดของช่องที่มีอยู่ในปัจจุบันโดยไม่กรอง

รับพารามิเตอร์ช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท จำเป็น
ประเภท ประเภทช่อง (PRIVATE, PUBLIC, GROUP) enum ใช่
channelId ดึงช่องที่เริ่มต้นด้วย ID ช่องเฉพาะ string ไม่ใช่
channelName ดึงช่องที่มีชื่อช่องเฉพาะ string ไม่ใช่
pageOrder ลำดับการจัดเรียง (ASC, DESC)
(ค่าเริ่มต้น DESC)
string ไม่ใช่
pageSize จำนวนช่องที่ดึงต่อหน้า
(ขั้นต่ำ 10 ~ สูงสุด 100, ค่าเริ่มต้น 10)
integer ไม่ใช่
pageNumber หมายเลขหน้าที่จะดึง
(เริ่มต้นจาก 1, ค่าเริ่มต้น 1)
integer ไม่ใช่

วัตถุ Channel และวัตถุ ChannelPage จะถูกจัดเตรียมเป็นการตอบสนอง และโครงสร้างมีดังนี้

ช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท
channelId รหัสช่อง สตริง
type ประเภทช่อง (PRIVATE, PUBLIC, GROUP) enum
owner เจ้าของช่อง Hive PlayerID สตริง
channelName ชื่อช่อง สตริง
maxMemberCount จำนวนสูงสุดของผู้เข้าร่วมช่อง จำนวนเต็ม
regTime วันที่และเวลาที่สร้างช่อง (ตาม UTC+0, รูปแบบ: yyyy-MM-dd'T'HH:mm:ss.SSSZ) สตริง

หน้าช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท
ขนาด จำนวนรายการต่อหน้า จำนวนเต็ม
หน้าปัจจุบัน หมายเลขหน้าปัจจุบัน จำนวนเต็ม
จำนวนทั้งหมด จำนวนรายการทั้งหมด จำนวนเต็ม
จำนวนหน้าทั้งหมด จำนวนหน้าทั้งหมด จำนวนเต็ม

ต่อไปนี้คือตัวอย่างโค้ดเพื่อดึงรายการช่องประเภท 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 Call Success

        สำหร (Chat::Channel channel : channels) {
            // ดึงข้อมูลช่อง
        }

        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

        สำหร (Chat::Channel *channel : channels) {
            // ดึงช่อง
        }

        if (channelPage != null) {
            // Retrieve ChannelPage
        }
    }
}];

การสอบถามข้อมูลช่อง

ในการดึงข้อมูลรายละเอียดเกี่ยวกับช่องเฉพาะ ให้เรียกใช้เมธอด getChannelInfo() ของคลาส Chat

การตอบสนองรวมถึงวัตถุ Channel และวัตถุ Member โดยโครงสร้างมีดังนี้

ช่อง

ชื่อฟิลด์ คำอธิบาย ประเภท
channelId รหัสช่อง string
type ประเภทช่อง (PRIVATE, PUBLIC, GROUP) enum
owner เจ้าของช่อง Hive PlayerID string
channelName ชื่อช่อง string
maxMemberCount จำนวนสูงสุดของผู้เข้าร่วมช่อง integer
regTime วันที่และเวลาการสร้างช่อง (ตาม UTC+0, รูปแบบ yyyy-MM-dd'T'HH:mm:ss.SSSZ) string

สมาชิก

ชื่อฟิลด์ คำอธิบาย ประเภท
playerId Hive PlayerID long
extraData ข้อมูลเพิ่มเติม (ตาม UTF-8)
(สูงสุด 256 ไบต์)
string
connectedTime เวลาการเชื่อมต่อ (ตาม UTC+0, รูปแบบ yyyy-MM-dd'T'HH:mm:ss.SSSZ) string

ต่อไปนี้คือตัวอย่างโค้ดเพื่อดึงข้อมูลรายละเอียดเกี่ยวกับช่องเฉพาะ

using hive;

String channelId = "CHANNEL_ID";

Chat.getChannelInfo(channelId, (ResultAPI result, Channel channel, List<Member> members) => {
    if (result.isSuccess()) {
        if (channel != null) {
            // Retrieve Channel
        }

        foreach (Member member in 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
        }

        สำหร (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 com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.getChannelInfo(channelId, (result, channel, members) -> {
    if(result.isSuccess()) {
        if (channel != null) {
            // Retrieve Channel
        }
        for (Chat.Member member : members) {
            // Retrieve Member
        }
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.getChannelInfo(channelId: channelId) { result, channel, members  in
    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

ค่าตอบกลับจะเหมือนกับวัตถุ Member ที่ส่งจาก getChannelInfo().

using hive;

String channelId = "CHANNEL_ID";

Chat.getChannelMembers(channelId, (ResultAPI result, List<Member> members) => {
    if (result.isSuccess()) {
        foreach (Member member in members) {
            // Retrieve Member
        }
    }
});
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace hive;

std::string channelId = "CHANNEL_ID";

Chat::getChannelMembers(channelId, [=](ResultAPI const & result, std::vector<Member> const & members) {
    if (result.isSuccess()) {
        for (Chat::Member member : members) {
            // Retrieve Member
        }
    }
});
import com.hive.Chat;
import com.hive.ResultAPI;

val channelId = "CHANNEL_ID"

Chat.getChannelMembers(channelId, object: Chat.GetChannelMembersListener{
    override fun onResult(result: ResultAPI, members: ArrayList<Chat.Member>) {
        if (result.isSuccess) {
            members.forEach { 
                // Retrieve Member
            }
        }
    }
})
import com.hive.Chat;

String channelId = "CHANNEL_ID";

Chat.getChannelMembers(channelId, (result, members) -> {
    if (result.isSuccess()) {
        for (Chat.Member member : members) {
            // Retrieve Member
        }
    }
});
import HIVEService

let channelId = "CHANNEL_ID"
ChatInterface.getChannelMembers(channelId: channelId) { result, members in
    if result.isSuccess {
        members.forEach {
            // Retrieve Member
        }
    }
}
#import "HIVEService.h"

NSString *channelId = @"CHANNEL_ID";
[HiveChat getChannelMembersWithChannelId:channelId handler:^(HIVEResultAPI * result, NSArray<HiveChatMember *> * members) {
    if (result.isSuccess) {
        for (Chat::Member *member : members) {
            // Retrieve Member
        }
    }
}];

การจัดการเหตุการณ์ช่อง

Hive ตรวจจับสถานะการเชื่อมต่อของเซิร์ฟเวอร์ซ็อกเก็ตแชทและส่งมอบเหตุการณ์การเปลี่ยนแปลงสถานะที่เกิดขึ้นกับผู้ใช้แอปและช่องอย่างต่อเนื่องไปยังแอป สำหรับวิธีการจัดการเหตุการณ์โดยละเอียด โปรดดูเอกสาร การจัดการเหตุการณ์ > เหตุการณ์ช่อง