This repository was archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
API reference : client
William Mcmurray edited this page Jun 25, 2013
·
3 revisions
The client class got an internal events listeners system on which you can subscribe with the on() method. Here is a list of available events you can subscribe :
| Event name | Parameters | Description |
|---|---|---|
| open | Fired when the socket is successfully open (connected to server). | |
| close |
|
Fired when socket is closed. |
| message |
|
Fired when the client socket receive data from server. Data is in JSON format. It contains two parts, the action name and the actual content. |
| alert |
|
Fired when server send alerts to the clients. The admin methods use this event to send some response to the client. |
| ping |
|
Fired when server respond to a ping request sent by client. It gives you your ping in milliseconds (time spent for data to travel to server and come back) |
| error |
|
Fired when an error occurs. |
| Method | Parameters | Description |
|---|---|---|
| on() |
|
Add a callback when an event occurs in client class. For a complete list of events available, scroll up in the page. |
| open() |
|
Open a socket connection with variables passed in parameter. These variables are formatted like this : "myvar=value&myOtherVar=value". |
| close() | Close the current socket connection. | |
| send() |
|
Send data to server. Every data that travels between client and server are composed of two parts : an action string to tell the server how to handle data, and a content containing the actual data. |
| sys_send() |
|
Works the same as the above method, except this one is used for system communications only. Admins calls, pings requests, socket closing and such all pass here instead of the normal send() method to prevent mixing your app actions with system actions. |
| raw_send() |
|
Send raw data to the server which doesn't use the default JSON transmission method. It can be useful if you want to send data in a specific optimized way instead of the "all in one" default JSON method. Coordinates by example could be sent like this "5,10,0" instead of this "{action:"coords", content:{x:5,y:10,z:0}}" which would save lots of bandwidth. |
| ping() | Send a ping request to the server. To handle server response you need to subscribe to the "ping" event. | |
| set_debug() |
|
Used to enable or disable debugging functionality in client (debug texts will be displayed in JavaScript console). |