Skip to content
Suyash Mohan edited this page May 13, 2014 · 4 revisions

Introduction

AppWarp Chat sample is a very basic chat demo where there are four rooms each with a specific topic (music, movies, technology and books). A User has to enter his name and press connect button. Once connected he has to select one of the room. Once joined in the room, he can chat with all the other users in that room. Screenshot

AppWarp Room Properties

To differentiate between rooms, we are using room property. Each room is assigned a property representing what type of room it is. To achieve this when a user clicks on the button we join the room with such property by using JoinRoomWithProperties() method

		if (GUI.Button (new Rect (512 / 2 - 128 / 2, 178, 128, 32), "Music")) {
			Dictionary<string,object> dic = new Dictionary<string, object>();
			dic.Add("type","music");
			WarpClient.GetInstance().JoinRoomWithProperties(dic);
		}

Screenshot Here we first create a dictionary to represent a key-value structure. The dictionary contains 'type' = 'music' item. AppWarp will try to search for a room which has a room property {type: "music"}. If found, we have successfully joined the room, but if it fails, we create a new room with this property and join it. Remember the response of JoinRoomWithProperties will be called in onJoinRoomDone() listener

		if(eventObj.getResult() == WarpResponseResultCode.RESOURCE_NOT_FOUND)
		{
			Dictionary<string,object> dic = new Dictionary<string, object>();
			dic.Add("type","music");
			WarpClient.GetInstance().CreateRoom(m_apppwarp.roomType, "admin",20,dic);
		}

Once we have successfully joined a room, we subscribe to the room for enabling us to listen to room notifications. Finally we send chat messages using the sendChat() method.

onChatReceived listener will provide us all the chat messages that are sent by players in the joined room.

Clone this wiki locally