-
Notifications
You must be signed in to change notification settings - Fork 0
Get Started with Spider
Gilbok Lee edited this page Nov 10, 2015
·
17 revisions
코드네임 Spider는 Hive5 SDK의 실시간(Realtime)기능 지원을 부르는 말입니다.
Hive5Client는 이미 초기화되어 있다고 가정합니다. Hive5Client 초기화는 여기를 참고하세요.
Hive5Spider spider = new Hive5Spider(Hive5Client.Instance);아래와 같이 호출하면 서버에 연결합니다.
spider.Connect(OnConnected);콜백함수의 예는 아래와 같습니다.
private void OnConnected(bool success)
{
// spider.SessionId 등에 유효한 값이 들어있을 것입니다.
}아래와 같이 호출하면 서버 접속을 끊습니다.
spider.Disconnect(OnDisconnect);콜백함수의 예는 아래와 같습니다.
private void OnDisconnect(bool success)
{
}물론 람다표현식으로 구현 가능합니다.
spider.Disconnect((success) =>
{
// 접속종료됨
});메세지 내용은 string타입의 key와 string타입의 value의 딕셔너리 타입으로 지원합니다.
Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendChannelMessage");
spider.SendChannelMessage(contents, (success, publicationId) =>
{
});Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendPrivateMessage");
spider.SendPrivateMessage(platformUserId, contents, (success, publicationId) =>
{
});Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendNoticeMessage");
spider.SendNoticeMessage(appSecret, contents, (success, publicationId) =>
{
});Dictionary<string, string> contents = new Dictionary<string, string>();
contents.Add("message", "testing SendSystemMessage");
spider.SendSystemMessage(contents, (success, publicationId) =>
{
});게임의 라이프타임 중 1번만 이벤트핸들러를 설정해 주면 됩니다.
spider.MessageReceived+= (sender, topicKind, messageContents) =>
{
switch(topicKind)
{
case TopicKind.Channel: // Channel 메세지
{
Debug.Log(messageContents["message"]);
}
break;
case TopicKind.Private: // Private 메세지
{
Debug.Log(messageContents["message"]);
}
break;
case TopicKind.Notice: // Notice 메세지
{
Debug.Log(messageContents["message"]);
}
break;
case TopicKind.System: // System 메세지
{
Debug.Log(messageContents["message"]);
}
break;
}
}아래와 같이 호출합니다.
spider.GetChannels(OnGetChannels);콜백함수의 예는 아래와 같습니다.
private void OnGetChannels(bool success, CallResult result)
{
GetChannelsResult castedResult = result as GetChannelsResult;
// castedResult.Channels에 접근이 가능합니다.
}아래와 같이 호출합니다.
spider.GetPlayers(OnGetPlayers);콜백함수의 예는 아래와 같습니다.
private void OnGetPlayers(bool success, CallResult result)
{
GetPlayersResult castedResult = result as GetPlayersResult;
// castedResult.PlatformUserIds에 접근이 가능합니다.
}스파이더에서 웹소켓에 인터페이스 하기 위해서 MIT License인 Websocket-Sharp을 사용하고 있습니다. Websocket-Sharp은 아래 링크를 통해 배포되고 있습니다. https://github.com/sta/websocket-sharp/