Constructor
new Scene()
A Scene should not be created by the user. Get a Scene by using Client#getPublicScene or Client#getScene.
Members
connected :boolean
A boolean representing whether the scene is connected or not.
Type:
- boolean
handle :number
A byte representing the index of the scene for this peer.
Type:
- number
isHost :boolean
True if the instance is an host. False if it's a client.
Type:
- boolean
localRoutes :Object.<string, object>
Returns a list of the routes registered on the local peer.
Type:
- Object.<string, object>
packetReceived :Array.<function()>
Pool of functions called when a packet is received.
Type:
- Array.<function()>
remoteRoutes :Object.<string, object>
Returns a list of the routes available on the remote peer.
Type:
- Object.<string, object>
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. |
connect() → {Promise}
Connect the Scene to the Stormancer application scene.
Returns:
A promise which complete when the Scene is connected.
- Type
- Promise
disconnect() → {Promise}
Disconnect the Scene.
Returns:
A promise which complete when the Scene is disconnected.
- Type
- Promise
getComponent() → {object}
Returns a specific registered component.
Returns:
The wanted object.
- Type
- object
getHostMetadata(key) → {string}
Returns metadata informations for the remote scene host.
Parameters:
Name | Type | Description |
---|---|---|
key |
string |
Returns:
Key associated value
- Type
- string
host() → {object}
Returns an Scene peer object that represents the scene host.
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. |
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. |
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. |
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. |