본문으로 건너뛰기

채널 목록 조회

채널 목록을 조회하는 두 가지 방법을 설명합니다.

WebSocket 방식

WebSocket을 통해 현재 접속 가능한 채널 목록을 조회합니다.

메서드 정보

항목내용
메서드ChatManager.Instance.GetChannels()
콜백OnChannels(ChatChannelInfo[] channels)

ChatChannelInfo

필드타입설명
channelstring채널 이름
countint접속자 수

사용 예제

using UnityEngine;

public class ChatExample : MonoBehaviour, IChatListener
{
public void GetChannels()
{
ChatManager.Instance.GetChannels();
}

public void OnChannels(ChatChannelInfo[] channels)
{
foreach (var channel in channels)
Debug.Log($"Channel: {channel.channel}, Users: {channel.count}");
}

// ... 기타 IChatListener 메서드 구현
}

REST API 방식

Socket 연결 전 사용 가능

REST API 방식은 WebSocket 연결 전에도 사용할 수 있습니다. 채팅 서버 연결 전에 채널 목록을 미리 조회하고 싶은 경우 이 방식을 사용하세요.

URL 확인

이 API는 service-api.playnanoo.com 도메인을 사용합니다.

API 정보

  • URL: https://service-api.playnanoo.com/chat/v20221201/channels
  • Method: GET
  • 인증 필요: 아니오

요청 파라미터

Req 클래스는 DeviceInfo를 상속받습니다.

별도의 추가 파라미터가 없습니다.

응답 데이터

Res

필드타입설명
ItemsList<ChatChannelInfo>채널 목록

ChatChannelInfo

필드타입설명
channelstring채널 이름
countint접속자 수

Unity C# 구현

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;

public class Channles
{
static string path = "https://service-api.playnanoo.com/chat/v20221201/channels";

[Serializable]
public class Req : DeviceInfo
{
public IEnumerator Send(Action<Res> onSuccess, Action<BaseResponse> onError)
{
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbGET,
path,
requireToken: false,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public List<ChatChannelInfo> Items;
}

[Serializable]
public class ChatChannelInfo
{
public string channel;
public int count;
}
}

사용 예제

using UnityEngine;

public class ChatExample : MonoBehaviour
{
public void GetChannelList()
{
Channles.Req req = new Channles.Req();
StartCoroutine(req.Send(
onSuccess: res =>
{
foreach(Channles.ChatChannelInfo item in res.Items)
{
Debug.Log($"Channel : {item.channel}");
Debug.Log($"Count : {item.count}");
}
},
onError: (error) =>
{
Debug.LogError($"GetChannelList 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
}