Server

server. Server

Server side entry point for a soundworks application.

This object hosts configuration informations, as well as methods to initialize and start the application. It is also responsible for creating the static file (http) server as well as the socket server.

Constructor

new Server()

Source:
Example
import * as soundworks from 'soundworks/server';
import MyExperience from './MyExperience';

soundworks.server.init(config);
const myExperience = new MyExperience();
soundworks.server.start();

Members

config

Source:

Configuration informations. Defaults to:

{
  env: {
    type: 'development',
    port: 8000,
    subfolder: '',
    useHttps: false,
  },
  app: {
    name: 'soundworks',
  },
}

httpServer

Source:

Http(s) server instance. The node http or https module instance (cf. https://nodejs.org/api/http.html)

pluginManager :server.PluginManager

Source:
See:

The server.PluginManager instance.

Type:

router

Source:

Router. Internally use polka. (cf. https://github.com/lukeed/polka)

sockets :server.Sockets

Source:
See:

The server.Sockets instance. A small wrapper around ws server.

Type:

stateManager :server.SharedStateManagerServer

Source:
See:
Type:

templateDirectory

Source:

Path to the directory containing the templates. Any filename corresponding to a registered browser client type will be used in priority, if not present fallback to default, i.e ${clientType}.tmpl fallbacks to default.tmpl. Template files should have the .tmpl extension.

templateEngine :Object

Source:

Template engine that should implement a compile method.

Type:
  • Object

Methods

(async) init(config, clientConfigFunction)

Source:

Method to be called before start in the initialization lifecycle of the soundworks server.

Example
// defaults to
await server.init(
  {
    env: {
      type: 'development',
      port: 8000,
      subpath: '',
      useHttps: false,
    },
    app: {
      name: 'soundworks',
      author: 'someone'
    }
  },
  (clientType, serverConfig, httpRequest) => {
    return { clientType, ...serverConfig };
  }
);
Parameters:
Name Type Description
config Object
Properties
Name Type Attributes Default Description
defaultClient String <optional>
'player'

Client that can access the application at its root url.

env String <optional>
'development'
port String <optional>
8000

Port on which the http(s) server will listen

subpath String <optional>

If the application runs behind a proxy server (e.g. https://my-domain.com/my-app/`), path to the application root (i.e. 'my-app')

useHttps Boolean <optional>
false

Define wheter to use or not an an https server.

httpsInfos Object <optional>
null

if useHttps is true, object that give the path to cert and key files ({ cert, key }). If null an auto generated certificate will be generated, be aware that browsers will consider the application as not safe in the case.

clientConfigFunction function

function that filters / defines the configuration object that will be sent to a connecting client.

(async) start()

Source:

Method to be called when init step is done in the initialization lifecycle of the soundworks server. Basically initialize plugins, define the routing and start the http-server.