API Reference - PeerGaming/peergaming GitHub Wiki

Overview

  pg.noConflict   : fn  - reset namespace
  pg.VERSION      : obj - refers to the current version
  pg.info         : obj - information about the state
  pg.config       : fn  - configuration for the network
  pg.login        : fn  - set identifier and create player
  pg.player       : obj - own user instance (writeable)
  pg.peers        : obj - list of connected players (readable)
  pg.data         : arr - shortcut to access peers.data + player.data
  pg.sync         : obj - synchronized shared object
  pg.loop         : fn  - synchronized rendering process
  pg.channel      : fn  - handler for a "Channel"
  pg.game         : fn  - handler for a "Game"
  pg.routes       : fn  - define default and custom routes
  • pg

Details

.noConflict()

Retrieving the old value of the namespace pg.

// Example
pg.noConflict();

.VERSION

Shows information about the current version.

{
  codeName - {String} - projectname of the release
  full     - {String} - 
  major    - {Number} - 
  minor    - {Number} -
  dot      - {Number} -
}

.info

Contains various information about the current state & network.

{
  route    - {String} - current route of the player
}

.config( [customConfig] )

Changes the configuration with custom settings.

  • customConfig - {Object}:

.login( name, [service] )

Creates a new instance of player (enables pg.player) and

.data

.sync

.loop( render )

.routes( [customRoutes], [defaultRoute] )

Defines custom routes to match the parameters in the URL. If just one paremeter is provided, it will use as the new defaultRoute.

User

The user model contains information about the account, the position and data.

{
  account  - {Object} -
  data     - {Object} -
  pos      - {Number} -
  id       - {String} -
}

Events:

.player

Read/Write access. Your instance, which will be synced as a peer on other systems.

.peers

Read access. Data from other player which will updated as their remote origin changes.

Rooms

Events:

.channel( [name], hook )

.game( [name], hook )