Skip to content

Latest commit

 

History

History
211 lines (130 loc) · 6.24 KB

PlayNetwork.md

File metadata and controls

211 lines (130 loc) · 6.24 KB

PlayNetwork (client)

extends pc.EventHandler

Main interface to connect to a server and interact with networked data.


Index

Properties

.me : User
.room : Room
.latency : number
.levels : Levels

Events

connect => (user)
disconnect
error => (error)
* => ([data])

Functions

connect(host, port, useSSL, payload, callback)
createRoom(data, callback)
joinRoom(id, callback)
leaveRoom(callback)
send(name, [data], [callback])


Properties

Local User object.

Room that User has joined.

.latency : number

Current network latency in miliseconds.

Interface that allows to save hierarchy data to a server.

Events

connect [event] => (user)

Fired when client has connected to a server and received own User data.

Param Type Description
user User Own User instance.

disconnect [event]

Fired after client has been disconnected from a server.

error [event] => (error)

Fired when networking error occurs.

Param Type
error Error

* [event] => ([data])

Fired on receive of a named network messages.

Param Type Description
data null | object | array | string | number | boolean Message data.

Functions

Create a WebSocket connection to the PlayNetwork server.

Param Type Description
host string Host of a server.
port number Port of a server.
useSSL boolean Use secure connection.
payload object | array | string | number | boolean | null Client authentication data.
callback connectCallback Will be fired when connection is succesfull or failed.

Send a request to a server, to create a Room.

Param Type Description
data object Request data that can be used by Server to decide room creation.
callback createRoomCallback Will be fired when room is created or failed.

Send a request to a server, to join a Room.

Param Type Description
id number ID of a Room to join.
callback joinRoomCallback Will be fired when Room is joined or failed.

Send a request to a server, to leave current Room.

Param Type Description
callback leaveRoomCallback Will be fired when Room is left or failed.

Send named message to the server.

Param Type Description
name string Name of a message.
data (optional) object | array | string | number | boolean JSON friendly message data.
callback (optional) responseCallback Callback that will be fired when a response message is received.

Callbacks

connectCallback [callback] => (error, user)

Param Type Description
error null | Error Error if connection failed.
user null | User Own User object.

createRoomCallback [callback] => (error, roomId)

Param Type Description
error null | Error Error if failed to create a Room.
roomId null | number ID of a created Room.

joinRoomCallback [callback] => (error)

Param Type Description
error null | Error Error if failed to join a Room.

leaveRoomCallback [callback] => (error)

Param Type Description
error null | Error Error if failed to leave a Room.

responseCallback [callback] => (error, data)

Param Type Description
error null | [Error] Error provided with with a response.
data null | object | array | string | number | boolean Data provided with a response.