Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.

API reference : client

William Mcmurray edited this page Jun 25, 2013 · 3 revisions

Events listeners

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
  • event - event
Fired when socket is closed.
message
  • data - JSON
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
  • text - string
Fired when server send alerts to the clients. The admin methods use this event to send some response to the client.
ping
  • yourPing - number
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
  • event - event
Fired when an error occurs.

Methods

Method Parameters Description
on()
  • eventName - string
  • callback - function()
Add a callback when an event occurs in client class. For a complete list of events available, scroll up in the page.
open()
  • variables - string
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()
  • action - string
  • content - *
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()
  • command - string
  • content - *
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()
  • content - *
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()
  • value - boolean
Used to enable or disable debugging functionality in client (debug texts will be displayed in JavaScript console).
Clone this wiki locally