Client: {
    connect: ((serverUrl) => Promise<void>);
    disconnect: ((force?) => Promise<void>);
    getStatus: (() => Status);
    getUsername: (() => string | undefined);
    getUsers: (() => {
        isLinked: boolean;
        username: string;
    }[]);
    leave: (() => Promise<void>);
    link: ((username, auth?) => Promise<void>);
    send: MessageConsumer;
    unlink: (() => Promise<void>);
} & EventEmitter<Events>

The client type describes the fields and methods that are accessible by using the createClient method.

Type declaration

  • connect: ((serverUrl) => Promise<void>)

    Connect to the Krmx server.

    Param: serverUrl

    For the serverUrl parameter you have to provide the ws:// or wss:// url of the websocket endpoint where your Krmx server is running. For example: ws://my-subdomain.example.org:3002/my-game or ws://localhost:1234.

      • (serverUrl): Promise<void>
      • Connect to the Krmx server.

        Parameters

        • serverUrl: string

          For the serverUrl parameter you have to provide the ws:// or wss:// url of the websocket endpoint where your Krmx server is running. For example: ws://my-subdomain.example.org:3002/my-game or ws://localhost:1234.

        Returns Promise<void>

  • disconnect: ((force?) => Promise<void>)

    Disconnect from the Krmx server. This only works when the client is connected but not yet linked. If force is passed, this will even disconnect when the client is linked to a user.

    Example: await client.unlink(); await client.disconnect(); or await client.disconnect(true);

      • (force?): Promise<void>
      • Disconnect from the Krmx server. This only works when the client is connected but not yet linked. If force is passed, this will even disconnect when the client is linked to a user.

        Example: await client.unlink(); await client.disconnect(); or await client.disconnect(true);

        Parameters

        • Optional force: boolean

        Returns Promise<void>

  • getStatus: (() => Status)

    Returns the current status of the Krmx client.

      • (): Status
      • Returns the current status of the Krmx client.

        Returns Status

  • getUsername: (() => string | undefined)

    Returns the username of the user to which the client is linked on the Krmx server.

      • (): string | undefined
      • Returns the username of the user to which the client is linked on the Krmx server.

        Returns string | undefined

  • getUsers: (() => {
        isLinked: boolean;
        username: string;
    }[])

    Returns the available information of the users on the Krmx server.

      • (): {
            isLinked: boolean;
            username: string;
        }[]
      • Returns the available information of the users on the Krmx server.

        Returns {
            isLinked: boolean;
            username: string;
        }[]

  • leave: (() => Promise<void>)

    Sends a message to the Krmx server with an intent to leave. The Krmx server will gracefully disconnect the client and inform all other connected clients that the client intended to disconnect.

      • (): Promise<void>
      • Sends a message to the Krmx server with an intent to leave. The Krmx server will gracefully disconnect the client and inform all other connected clients that the client intended to disconnect.

        Returns Promise<void>

  • link: ((username, auth?) => Promise<void>)

    Link the connection to a user.

    Param: username

    The username of the user you want to link to. For example: 'simon'.

    Param: auth

    An optional auth string. This value is sent to the Krmx server and will be available in the on('authenticate', ...) listener.

    Throws

    Error Throws an error, if the client is not connected or the client is already linked to a user.

      • (username, auth?): Promise<void>
      • Link the connection to a user.

        Parameters

        • username: string

          The username of the user you want to link to. For example: 'simon'.

        • Optional auth: string

          An optional auth string. This value is sent to the Krmx server and will be available in the on('authenticate', ...) listener.

        Returns Promise<void>

        Throws

        Error Throws an error, if the client is not connected or the client is already linked to a user.

  • send: MessageConsumer

    Send a message to the Krmx server.

    Throws

    Error Throws an error, if the client is not connected or the client is not linked to a user.

  • unlink: (() => Promise<void>)

    Unlink the connection from its user.

    Throws

    Error Throws an error, if the client is not connected or the client is not linked to a user.

      • (): Promise<void>
      • Unlink the connection from its user.

        Returns Promise<void>

        Throws

        Error Throws an error, if the client is not connected or the client is not linked to a user.