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

    Class WebrtcMultiplayerController<MessageData>

    A controller that connects to the multiplayer api and establishes a WebRTC connection to the selected room, or, if the room does not exist yet, creates the room and becomes the host.

    Make sure, after constructing this class, to call WebrtcMultiplayerController.initConnection when you're ready to being the connection.

    Type Parameters

    • MessageData extends JsonCompatibleValue = any

    Hierarchy

    Index

    Constructors

    • Type Parameters

      • MessageData extends JsonCompatibleValue = any

      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>
      • clientId: `${string}-${string}-${string}-${string}-${string}` = ...

        The randomized client id for this controller and client.

      • shouldAllowConnectionCheck: ShouldAllowConnectionCheck<WebrtcMultiplayerController<MessageData>> = ...

        This is fired when a WebRTC peer attempts to connect to the host client (this will only be fired if your client is the host). Return true to accept the connection. Return false to reject it.

        accept all connections
        

      Returns WebrtcMultiplayerController<MessageData>

    Properties

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

    The randomized client id for this controller and client.

    hostClientId: undefined | `${string}-${string}-${string}-${string}-${string}`
    isDestroyed: boolean = ...
    multiplayerRoom: Readonly<RoomInput>
    stunServerUrls: readonly string[]

    Methods

    • If this controller is the host, it'll behave differently:

      • Hosts hold WebRTC connections to all clients (non-hosts only hold a WebRTC connection to the host).
      • Hosts hold a WebSocket connection to the signal server so they can receive more clients at any time.

      Returns boolean