Class: Scene

Scene

A Stormancer scene. Peers connected to a Scene can interact between themself.

Constructor

new Scene()

A Scene should not be created by the user. Get a Scene by using Client#getPublicScene or Client#getScene.

Source:

Members

connected :boolean

A boolean representing whether the scene is connected or not.

Type:
  • boolean
Source:

handle :number

A byte representing the index of the scene for this peer.

Type:
  • number
Source:

isHost :boolean

True if the instance is an host. False if it's a client.

Type:
  • boolean
Source:

localRoutes :Object.<string, object>

Returns a list of the routes registered on the local peer.

Type:
  • Object.<string, object>
Source:

packetReceived :Array.<function()>

Pool of functions called when a packet is received.

Type:
  • Array.<function()>
Source:

remoteRoutes :Object.<string, object>

Returns a list of the routes available on the remote peer.

Type:
  • Object.<string, object>
Source:

Methods

addRoute(route, handler, metadataopt)

Registers a route on the local peer for receiving data packets. See the {Stormancer.Packet} class to know how to get the data.

Parameters:
Name Type Attributes Default Description
route string

The route name

handler packetHandler

Function for handling the received messages. This function is called any time a Packet is received by the server on this route.

metadata object.<string, string> <optional>
{}

Some metadata attached to this route.

Source:

connect() → {Promise}

Connect the Scene to the Stormancer application scene.

Source:
Returns:

A promise which complete when the Scene is connected.

Type
Promise

disconnect() → {Promise}

Disconnect the Scene.

Source:
Returns:

A promise which complete when the Scene is disconnected.

Type
Promise

getComponent() → {object}

Returns a specific registered component.

Source:
Returns:

The wanted object.

Type
object

getHostMetadata(key) → {string}

Returns metadata informations for the remote scene host.

Parameters:
Name Type Description
key string
Source:
Returns:

Key associated value

Type
string

host() → {object}

Returns an Scene peer object that represents the scene host.

Source:
Returns:

A Scene peer object.

Type
object

registerComponent(componentName, factory)

Registers a component and provide a factory for getting it.

Parameters:
Name Type Description
componentName string

The component game.

factory function

The factory function for getting the component.

Source:

registerRoute(route, handler, metadataopt)

Registers a route on the local peer for receiving deserialised javascript objects. See {Stormancer.Scene.addRoute} to have more flexibility on the data.

Parameters:
Name Type Attributes Default Description
route string

The route name

handler dataHandler

Function for handling the received messages. This function is called any time a data is received by the server on this route.

metadata object.<string, string> <optional>
{}

Some metadata attached to this route.

Source:

send(route, data, priority, reliability)

Sends an object to the scene.

Parameters:
Name Type Description
route string

The route name.

data object

The data to send.

priority number

The packet priority on the stormancer network.

reliability number

The packet reliability on the stormancer network.

Source:

sendPacket(route, data, priority, reliability)

Sends a binary packet to the scene.

Parameters:
Name Type Description
route string

The route name.

data Uint8Array

The data to send.

priority number

The packet priority on the stormancer network.

reliability number

The packet reliability on the stormancer network.

Source: