Constructor
new Client()
- Source:
Example
import soundworks from '@soundworks/core/client';
// create a new `soundworks.Client` instance
const client = new soundworks.Client();
// initialize the client (mainly connect and initialize WebSockets)
await client.init(config);
// create application specific experience (extends `client.AbstractExperience`
const playerExperience = new PlayerExperience(client);
// start the client
await client.start();
// when everything is ready, the experience can be safely started
playerExperience.start();
Members
config :Object
- Source:
- See:
Configuration object, typically contains the configuration sent by the server (cf. server.Server#init).
Type:
- Object
id :Number
- Source:
Session id of the client (incremeted positive number), generated and retrieved by the server on start. The counter is reset when the server restarts.
Type:
- Number
pluginManager :client.PluginManager
- Source:
- See:
Instance of the PluginManager
class.
Type:
socket :client.Socket
- Source:
- See:
Instance of the Socket
class that handle communications with the server.
Type:
stateManager :client.SharedStateManagerClient
- Source:
- See:
Instance of the SharedStateManagerClient
class.
Type:
type :String
- Source:
Type of the client, this can generally be considered as the role of the client in the application.
Type:
- String
uuid :String
- Source:
Unique session uuid of the client (uuidv4), generated and retrieved by the server on start.
Type:
- String
Methods
(async) init(config)
- Source:
- See:
Method to be called before client.Client#start in the initialization lifecycle of the soundworks client.
Basically waits for the socket to be connected.
Parameters:
Name | Type | Description |
---|---|---|
config |
Object | Configuration object (cf. server.Server#init) |
(async) start()
- Source:
- See:
Method to be called when client.Client#init has finished in the initialization lifecycle of the soundworks client.
Initilialize the client.SharedStateManagerClient and all required plugins. When done, the client.AbstractExperience#start method should be consider as being safely called.