@game-vir/multiplayer - v15.1.1
    Preparing search index...

    Class LockStepGameStateController<Action>

    A wrapper for WebrtcMultiplayerController that ensures messages are sent and arrive in a lock-step fashion. Also supports singleplayer mode.

    Type Parameters

    • Action extends JsonCompatibleValue = any

    Hierarchy

    Index

    Constructors

    Properties

    clientId: `${string}-${string}-${string}-${string}-${string}`

    The current client id.

    currentFps: number = 0

    The current data flow FPS.

    webrtcController:
        | undefined
        | WebrtcMultiplayerController<LockStepMessage<Action>>

    Methods

    • Startup the controller in multiplayer mode and connect to a room.

      Parameters

      • gameId: string
      • multiplayerApi: Readonly<
            RestVirApi<
                ServiceDefinition<
                    "multiplayer-service",
                    {
                        "/": {
                            methods: { GET: true };
                            requestDataShape: undefined;
                            requiredClientOrigin: {};
                            responseDataShape: ShapeExact<readonly ["ok"]>;
                        };
                        "/health": {
                            methods: { GET: true };
                            requestDataShape: undefined;
                            requiredClientOrigin: {};
                            responseDataShape: ShapeExact<readonly ["ok"]>;
                        };
                        "/rooms": {
                            methods: { GET: true };
                            requestDataShape: undefined;
                            responseDataShape: ShapeDefinition<
                                ShapeIndexedKeys<
                                    [
                                        {
                                            keys: CustomSpecifier<
                                                `${(...)}-${(...)}-${(...)}-${(...)}-${(...)}`,
                                            >;
                                            required: false;
                                            values: ShapeDefinition<
                                                {
                                                    clientCount: ...;
                                                    hasRoomPassword: ...;
                                                    roomId: ...;
                                                    roomName: ...;
                                                },
                                                false,
                                            >;
                                        },
                                    ],
                                >,
                                false,
                            >;
                            searchParamsShape: { gameId: ShapeTuple<[string]> };
                        };
                    },
                    {
                        "/connect": {
                            messageFromClientShape: ShapeOr<
                                [
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                ShapeDefinition<(...), (...)>,
                                                { data: ...; type: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                ShapeDefinition<(...), (...)>,
                                                { clientSecret: ...; roomPassword: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                ShapeDefinition<(...), (...)>,
                                                {
                                                    clientCount: ...;
                                                    clientSecret: ...;
                                                    roomPassword: ...;
                                                    type: ...;
                                                },
                                            ],
                                        >,
                                        false,
                                    >,
                                ],
                            >;
                            messageFromHostShape: ShapeOr<
                                [
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                ShapeDefinition<(...), (...)>,
                                                { data: ...; type: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                ShapeDefinition<(...), (...)>,
                                                { data: ...; type: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                { hostClientId: ...; type: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                    ShapeDefinition<
                                        ShapeAnd<
                                            [
                                                ShapeDefinition<(...), (...)>,
                                                { errorMessage: ...; type: ... },
                                            ],
                                        >,
                                        false,
                                    >,
                                ],
                            >;
                            searchParamsShape: { gameId: ShapeTuple<[string]> };
                        };
                    },
                >,
            >,
        >
      • stunServerUrls: readonly string[]
      • multiplayerRoom: Readonly<RoomInput>

      Returns Promise<boolean>

      Whether the connection was a successful or not.

      LockStepGameStateController.startSingleplayer for starting the controller in singleplayer mode.