Properties

api: API

Useful for connecting to the main game API when none of the client helpers have the request you want to send. You can use client.api.get and client.api.post to easily send GET and POST requests.

disconnected: boolean = false

Whether the client has been disconnected. If true, the client needs to be reconnected with .reconnect() or destroyed

emit: (<T>(event: T, ...data: Types.Events.out.all[T] extends void
    ? []
    : [Types.Events.out.all[T]]) => void)

Raw ribbon handler for sending messages.

game?: Classes.Game

The game the client is currently in if it is in a game.

off: (<K>(event: K, cb: ((data: Types.Events.in.all[K]) => void)) => EventEmitter<Types.Events.in.all>)

Raw ribbon handler.

on: (<K>(event: K, cb: ((data: Types.Events.in.all[K]) => void)) => EventEmitter<Types.Events.in.all>)

Raw ribbon handler.

client.on('social.dm', () => console.log('DM received!'));
once: (<K>(event: K, cb: ((data: Types.Events.in.all[K]) => any)) => EventEmitter<Types.Events.in.all>)

Raw ribbon handler. You likely want to use client.wait instead.

ribbon: Classes.Ribbon

Raw ribbon client, the backbone of TETR.IO multiplayer. You probably don't want to touch this unless you know what you are doing.

room?: Classes.Room

The room the client is in (if it is in a room). You can make it non-nullable with client.room!

rooms: {
    create(type?: "public" | "private"): Promise<Classes.Room>;
    join(id: string): Promise<Classes.Room>;
    list(): Promise<Utils.APITypes.Rooms.Room[]>;
}
social: Classes.Social

A helpful manager for all things social on TETR.IO (friends, dms etc.)

token: string

The client's token

User information

Utils for the client.

  • functionality has been moved to other sections. This may be removed in the future.

Accessors

  • get handling(): Handling
  • The client's current handling.

    Returns Handling

  • set handling(handling): void
  • Change the client's current handling (do not use while in a room)

    Parameters

    Returns void

Methods

  • Clean up the client

    Returns Promise<void>

  • Reconnect the client to TETR.IO.

    Returns Promise<void>

    if the client is already connected

  • Wait for an event to occur. Wraps client.once into a typed Promise.

    Type Parameters

    • T extends
          | (keyof Client)
          | (keyof Game)
          | (keyof Ribbon)
          | (keyof Room)
          | (keyof Social)
          | "staff.xrc"

    Parameters

    • event: T

    Returns Promise<Types.Events.in.all[T]>

    the data from the event

    // wait for a notification (although you probably want to use `client.on` for this instead)
    console.log(await client.wait('social.notification'));
  • Send a message and then wait for another message. Throws an error if a 'err' message is received before the response message

    Type Parameters

    • O extends
          | (keyof Client)
          | (keyof Social)
          | (keyof Room)
          | (keyof Game)
          | "config.handling"
    • I extends
          | (keyof Client)
          | (keyof Game)
          | (keyof Ribbon)
          | (keyof Room)
          | (keyof Social)
          | "staff.xrc"

    Parameters

    • event: O

      the command of the event to send

    • data: Types.Events.out.all[O]

      the data to send along with the command. For void (no) data, just pass in undefined

    • listen: I

      the event to wait for before resolving.

    • error: (
          | (keyof Client)
          | (keyof Game)
          | (keyof Ribbon)
          | (keyof Room)
          | (keyof Social)
          | "staff.xrc")[] = ...

      a list of custom error events to listen for. Defaults to [client.error].

    Returns Promise<Types.Events.in.all[I]>

    the data sent by the listen event

    an error if the error event provided (or client.error) is received from TETR.IO

    // This is just for example, use `client.room!.chat` instead
    await client.wrap('room.chat', { content: 'Hello', pinned: false }, 'room.chat');
  • Create a new client

    Parameters

    Returns Promise<Client>

    const client = await Client.connect({ token: 'your.jwt.token' });
    
    const client = await Client.connect({ username: 'halp', password: 'password' });
    
    // If playing games, pass in handling
    const client = await Client.connect({
    // ...login info
    handling: {
    arr: 0,
    cancel: false,
    das: 5,
    dcd: 0,
    safelock: false,
    may20g: true,
    sdf: 41
    };
    });
    // You can pass in a custom user agent
    const client = await Client.connect({
    // ...login info
    userAgent: "v8/001"
    });