Skip to main content

Get Channel List

Get the list of channels.

WebSocket Method​

Get the list of currently accessible channels via WebSocket.

Method Information​

ItemContent
MethodAChatManager::GetInstance()->GetChannels()
CallbackOnChannels(const TArray<FChatChannelInfo>& Channels)

FChatChannelInfo​

FieldTypeDescription
channelFStringChannel name
countint32User count

Code Example​

void UMyGame::GetChannels()
{
AChatManager::GetInstance()->GetChannels();
}

void UMyGame::OnChannels(const TArray<FChatChannelInfo>& Channels)
{
for (const auto& Channel : Channels)
{
UE_LOG(LogTemp, Log, TEXT("Channel: %s, Users: %d"), *Channel.channel, Channel.count);
}
}

REST API Method​

Available Before Socket Connection

The REST API method can be used before WebSocket connection. Use this method if you want to query the channel list before connecting to the chat server.

URL Confirmation

This API uses the service-api.playnanoo.com domain.

API Information​

  • URL: https://service-api.playnanoo.com/chat/v20221201/channels
  • Method: GET
  • Authentication Required: No

Request Parameters​

No additional parameters required.

Response Data​

FieldTypeDescription
ItemsarrayChannel list
Items[].channelstringChannel name
Items[].countintUser count

Code Example​

void UMyGame::GetChannelList()
{
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetURL(TEXT("https://service-api.playnanoo.com/chat/v20221201/channels"));
Request->SetVerb(TEXT("GET"));
FPlayNANOOHelper::SetCommonHeaders(Request, false); // No auth token required

Request->OnProcessRequestComplete().BindLambda(
[](FHttpRequestPtr Req, FHttpResponsePtr Res, bool bSuccess)
{
if (bSuccess && Res.IsValid())
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Res->GetContentAsString());

if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
const TArray<TSharedPtr<FJsonValue>>* Items;
if (JsonObject->TryGetArrayField(TEXT("Items"), Items))
{
for (const auto& Item : *Items)
{
TSharedPtr<FJsonObject> ChannelObj = Item->AsObject();
FString Channel = ChannelObj->GetStringField(TEXT("channel"));
int32 Count = ChannelObj->GetIntegerField(TEXT("count"));
UE_LOG(LogTemp, Log, TEXT("Channel: %s, Count: %d"), *Channel, Count);
}
}
}
}
});

Request->ProcessRequest();
}