html5-usage-guide

*We assure you that we do not spam. You may receive occasional emails from us.
 You can always unsubscribe.
HTML5

HTML5 Getting Started

WarpClient provides an interface for applications to interact with the cloud services. It allows client side applications to connect, subscribe and manage server side rooms, lobbies and users. The APIs are developed to be used asynchronously, which means you simply add the corresponding request listeners to the WarpClient instance to receive responses and updates. This page describes to how to set up your connection with the cloud server and introduces API usage. For a complete API reference, please visit this page.

In order to use the various functions available, you will have to initialize, connect and authenticate the instance of WarpClient. WarpClient is initialized by passing the apiKey and secretKey which you received after creating an app from AppHq (App42 management console). If you are not a registered App42 user, you can sign up here.

Sign up


  

Warpclient follows singleton pattern. Use getInstance() to get the instance of WarpClient. Every thing in AppWarp SDK is defined inside `AppWarp` namespace. After initialization, it is recommended that you implement and add a response and notification listeners which will be called by WarpClient with the result of the requests. WarpClient comprises different listeners for different type of requests and notifications namely

    Response Listeners
  • onConnectDone
  • onDisconnectDone
  • onJoinLobbyDone
  • onLeaveLobbyDone
  • onSubscribeLobbyDone
  • onUnsubscribeLobbyDone
  • onGetLiveLobbyInfoDone
  • onSubscribeRoomDone
  • onUnsubscribeRoomDone
  • onJoinRoomDone
  • onLeaveRoomDone
  • onGetLiveRoomInfoDone
  • onSetCustomRoomDataDone
  • onUpdatePropertyDone
  • onLockPropertiesDone
  • onUnlockPropertiesDone
  • onCreateRoomDone
  • onDeleteRoomDone
  • onGetAllRoomsDone
  • onGetOnlineUsersDone
  • onGetLiveUserInfoDone
  • onSetCustomUserDataDone
  • onGetMatchedRoomsDone
  • onSendChatDone
  • onSendPrivateChatDone
  • onSendUpdateDone
  • onSendMoveDone
    Notification Listeners
  • onRoomCreated
  • onRoomDestroyed
  • onUserLeftRoom
  • onUserJoinedRoom
  • onUserLeftLobby
  • onUserJoinedLobby
  • onChatReceived
  • onUpdatePeersReceived
  • onUserChangeRoomProperty
  • onPrivateChatReceived
  • onMoveCompleted


Once you have supplied all the listeners you have to call the connect() method of WarpClient with a username as argument to connect to the AppWarp servers.

_warpclient.connect(nameId);

Result Codes : These can be retrieved when an event callback is invoked from the event instance.

byte SUCCESS = 0;    
byte AUTH_ERROR = 1;    
byte RESOURCE_NOT_FOUND = 2;    
byte RESOURCE_MOVED = 3;     
byte BAD_REQUEST = 4;
byte CONNECTION_ERR = 5;
byte UNKNOWN_ERROR = 6;

Once you have successfully joined you can either join the lobby or join a particular room. You should also subscribe the lobby or the room joined to catch the notifications generated in that particular room or lobby.

_warpclient.joinRoom(roomId);
_warpclient.subscribeRoom(roomID);

To exchanges messages you can either send messages in plain text format using sendChat() method or send messages in binary format using sendUpdate() method respectively. To catch the messages send through sendChat() method use the onChatReceived() method of MyNotificationListener and to catch the messages send through onUpdatePeersReceived() method of MyNotificationListener. You can also exchange messages in JSON by simply using JSON.stringify() and JSON.parse() methods to transform messages into strings and then sending them through sendChat() method of WarpClient.

var msg = {
action: 'move',
pos_x: 120,
pos_y: 200
};
_warpclient.sendChat(JSON.stringify(msg));

Appwarp also allows you to set custom data for users and rooms through the methods setCustomUserData() and setCustomRoomData(). To retrieve the custom data and other information WarpClient comprises getLiveUserInfo() and getLiveRoomInfo() methods.