PlayerIO

The fastest way to build online games without breaking a sweat.

HTML5 (Javascript) Client Reference

javascript (html5) connection class informationClass connection

Language: Javascript (HTML5)

An instance of this class is returned after successfully joining a Multiplayer room. It encapsulates the active network connection between the user and the room, and has methods for sending and handling messages, as well as disconnecting fom the room. See the Multiplayer class for examples.

Properties

 
connected :

Indicates if the connection is still alive

Methods

 
addDisconnectCallback (callback):

Add a disconnect callback that will be called when the connection is disconnected

addMessageCallback (type, callback):

Add a message callback for the given message type.

createMessage (type):message

Create a message with arguments inline: connection.createMessage('invite', arg1, arg2...)

disconnect ():

Disconnect from the multiplayer room

removeDisconnectCallback (callback):

Remove an already registered disconnect callback

removeMessageCallback (callback):

Remove an already registered message callback

send (type):

Send a message with arguments inline: connection.createMessage('invite', arg1, arg2...)

sendMessage (message):

Send a message

connection.connected

Indicates if the connection is still alive

connection.addDisconnectCallback

addDisconnectCallback (callback):

Add a disconnect callback that will be called when the connection is disconnected

Arguments

callback:function()
The callback to be called when a disconnect happens

connection.addMessageCallback

addMessageCallback (type, callback):

Add a message callback for the given message type.

Arguments

type:string
The type of message to invoke the callback for. Use '*' to handle all message types.
callback:function(message)
The callback to be called when a message of the given type is received

connection.createMessage

createMessage (type):message

Create a message with arguments inline: connection.createMessage('invite', arg1, arg2...)

Arguments

type:string
The string type to give to the message.

connection.disconnect

Disconnect from the multiplayer room

connection.removeDisconnectCallback

Remove an already registered disconnect callback

Arguments

callback:function
The callback to remove

connection.removeMessageCallback

removeMessageCallback (callback):

Remove an already registered message callback

Arguments

callback:function
The callback to remove

connection.send

send (type):

Send a message with arguments inline: connection.createMessage('invite', arg1, arg2...)

Arguments

type:string
The string type to give to the message.

connection.sendMessage

sendMessage (message):

Send a message

Arguments

message:message
The message to send.