ModelService

ModelService

A singleton with a well-known name that provides a model-side global service. You can define your own services and add them in your model root.

Extends

Methods

# init(name, optionsopt)

Called when the new service is instantiated. An options object may be supplied by the model root. You should overload this when you create your own service and name the service using super.init(). If the service needs to regularly update itself, start a tick here using this.future().

Warning: Never create a service directly. Always use modelServices() in the model root.

Parameters:
Name Type Attributes Description
name string

The public name of the service. Use super.init() in your service to set its name.

options Object <optional>

An options object that is supplied to when the service is added.

Example
class MyModelService extends ModelService {
        init(options = {}) {
            super.init("MyModelServiceName");
            // Apply options and perform other initialization.
        }
    }

# (async, static) asyncStart()

This method is called before the Croquet session starts. If you're writing a custom service that requires some sort of installation or initization before Croquet runs Session.join that code should go here.

Example
class MyModelService extends ModelService {
        static async asyncStart() {
            RAPIER = await import("@dimforge/rapier3d"); // Installs Rapier physics package
        }
    }

# service(name) → {ModelService}

Returns a pointer to the named model service.

Parameters:
Name Type Description
name string

The public name of the model service.

Inherited From:
Returns:
Type
ModelService