Triangle.js Docs
    Preparing search index...

    Class Client

    Index

    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

    game?: Classes.Game

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

    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.)

    suppressWarnings?: Warning[]

    The warnings that the client will suppress

    token: string

    The client's token

    User information

    Accessors

    • get handling(): Handling

      The client's current handling. Do not change the client's handling while in a room.

      Returns Handling

    • set handling(handling: Handling): void

      Parameters

      Returns void

    Methods

    • Clean up the client. Leaves any rooms first.

      Returns Promise<void>

    • Raw ribbon handler for sending messages.

      Type Parameters

      • K extends
            | (keyof Client)
            | (keyof Social)
            | (keyof Room)
            | (keyof Game)
            | "config.handling"

      Parameters

      Returns this

    • Raw ribbon handler.

      Type Parameters

      • K extends
            | (keyof Client)
            | (keyof Game)
            | (keyof Ribbon)
            | (keyof Room)
            | (keyof Social)
            | (keyof Staff)

      Parameters

      Returns this

      const listener = () => console.log('DM received!');
      client.on('client.dm', listener);

      // later
      client.off('client.dm', listener);
    • Raw ribbon handler.

      Type Parameters

      • K extends
            | (keyof Client)
            | (keyof Game)
            | (keyof Ribbon)
            | (keyof Room)
            | (keyof Social)
            | (keyof Staff)

      Parameters

      Returns this

      client.on('client.dm', () => console.log('DM received!'));
      
    • Raw ribbon handler. You might want to use client.wait instead.

      Type Parameters

      • K extends
            | (keyof Client)
            | (keyof Game)
            | (keyof Ribbon)
            | (keyof Room)
            | (keyof Social)
            | (keyof Staff)

      Parameters

      Returns this

      client.once('social.invite', ({ roomid }) => console.log(`Invited to room ${roomid}`));
      
    • 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)
            | (keyof Staff)

      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)
            | (keyof Staff)

      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)
            | (keyof Staff)
        )[] = ...

        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.create({ token: 'your.jwt.token' });
      
      const client = await Client.create({ username: 'halp', password: 'password' });
      
      // If playing games, pass in handling
      const client = await Client.create({
      // ...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.create({
      // ...login info
      userAgent: "v8/001"
      });