obby-client for TypeScript
    Preparing search index...

    Class ObbyClient

    One connection, wrapped for JavaScript.

    Every method mirrors one on [Client]. None of them can panic: a bad argument comes back as a rejected Result, which wasm-bindgen turns into a thrown JS error, because a panic inside a WebAssembly module poisons it for the rest of the host's lifetime, with no way to recover.

    import init, { ObbyClient } from "obby-client";

    await init();
    const client = new ObbyClient({ nick: "mynick" });
    const socket = new WebSocket("wss://irc.example.org/webirc");
    socket.binaryType = "arraybuffer";

    const flush = () => {
    for (let bytes; (bytes = client.pollTransmit()); ) socket.send(bytes);
    };

    socket.onopen = () => {
    client.handleConnected();
    flush();
    };

    socket.onmessage = (message) => {
    client.handleBytes(new Uint8Array(message.data as ArrayBuffer));
    client.tick(performance.now(), Date.now());

    for (const event of client.pollEvents()) {
    if (event.type === "registered") {
    client.join("#obby");
    client.sendMessage("#obby", `hello, I am ${event.nick}`);
    }
    }
    flush();
    };

    Indexable

    • [key: number]: () => void
    Index
    • Build an engine that has not connected yet. Nothing is written until [Self::handle_connected].

      config is a JS object with the same shape as [Config]. Only nick is required; every other field has a default.

      Parameters

      Returns ObbyClient

    • React to a message with an emoji.

      Parameters

      • target: string
      • msgid: string
      • emoji: string

      Returns void

    • Do anything, as a [Command] object.

      Every command also has a method of its own, such as [Self::join]; this is the one call that takes a command a host built itself.

      Anything the engine cannot read throws, rather than going quietly missing.

      Parameters

      Returns void

      const command: Command = { type: "join", channel: "#obby", key: null };
      client.command(command);
      client.command({ type: "set_topic", channel: "#obby", topic: "the new topic" });
    • Make an invitation link to a channel, or to the network when no channel is named.

      Parameters

      • Optionalchannel: string
      • Optionaldescription: string

      Returns void

    • Withdraw an invitation link.

      Parameters

      • share_id: string

      Returns void

    • Ask for older messages in a target, before the message with this id.

      Parameters

      • target: string
      • before_msgid: string
      • limit: number

      Returns void

    • Returns void

    • Mint a bearer token for one of the network's services, such as its file host.

      Parameters

      • service: string

      Returns void

    • Feed whatever the transport read. Partial lines are held until the rest arrives.

      Parameters

      • data: Uint8Array

      Returns void

    • Tell the engine the transport is up. Queues the registration burst.

      Returns void

    • Tell the engine its transport died. The model survives, so a reconnect can resume from it.

      Returns void

    • Join a channel, with its key when it has one.

      Parameters

      • channel: string
      • Optionalkey: string

      Returns void

      client.join("#obby");
      client.join("#staff", "hunter2");
    • Ask for the invitation links we have made.

      Returns void

    • Move our read marker in a target, at a time in milliseconds since the Unix epoch.

      Parameters

      • target: string
      • at_ms: number

      Returns void

    • Everything the connection knows, as a JS value: channels, members, conversations and messages. For a host that only wants the model, not a diff of what changed.

      Returns Model

    • Leave a channel, with a reason the others in it see.

      Parameters

      • channel: string
      • Optionalreason: string

      Returns void

    • Every event the engine has queued since the last call, as a JS array.

      Draining a batch instead of one event per call is what keeps this binding cheap on every target this core is bound into: a call across the WebAssembly boundary costs the same whether it carries one event or a hundred, so paying that cost once per drain rather than once per event is what actually saves work.

      Returns ObbyEvent[]

      for (const event of client.pollEvents()) {
      switch (event.type) {
      case "registered":
      console.log(`registered as ${event.nick}`);
      break;
      case "model_changed":
      if (event.change.type === "message_added") render(event.change.target);
      break;
      case "server_reply":
      console.log(event.severity, event.code, event.text);
      break;
      }
      }
    • When [Self::tick] next has something to do, as a monotonic instant, or undefined when nothing is scheduled. A host can set one timer for exactly this instant instead of polling on an interval.

      Returns number

    • Bytes the host should write to the transport, or undefined when there are none.

      One chunk per call, unlike [Self::poll_events]: a chunk is already the smallest unit a socket writes, so there is nothing to gain from batching it, and a growing [Event] never has to carry it.

      Returns Uint8Array<ArrayBuffer>

    • Leave the server, with a reason the others see.

      Parameters

      • Optionalreason: string

      Returns void

    • Ask the server to redact a message.

      Parameters

      • target: string
      • msgid: string
      • Optionalreason: string

      Returns void

    • Redeem an invitation code. Only before registering, which is the point of it.

      Parameters

      • code: string

      Returns void

    • Take one of our reactions back.

      Parameters

      • target: string
      • msgid: string
      • emoji: string

      Returns void

    • Rename a channel, keeping everyone in it and everything said in it.

      Parameters

      • channel: string
      • new_name: string
      • Optionalreason: string

      Returns void

    • Send a CTCP ACTION, the third-person form.

      Parameters

      • target: string
      • text: string

      Returns void

    • Say something to a channel or a person.

      Parameters

      • target: string
      • text: string

      Returns void

      client.sendMessage("#obby", "hello there");
      client.sendMessage("alice", "a private word");
    • Send a notice, which by convention must never be auto-replied to.

      Parameters

      • target: string
      • text: string

      Returns void

    • Send one raw protocol line, for anything this API does not name.

      Parameters

      • line: string

      Returns void

    • Send one voice signalling frame to a room.

      Parameters

      Returns void

    • Go away with a message, or come back by passing nothing.

      Parameters

      • Optionalmessage: string

      Returns void

    • Set one of our own metadata keys, or clear it by passing nothing.

      Parameters

      • key: string
      • Optionalvalue: string

      Returns void

    • Change our nick.

      Parameters

      • nick: string

      Returns void

    • Set a channel's topic, or ask for the current one by passing nothing.

      Parameters

      • channel: string
      • Optionaltopic: string

      Returns void

    • Tell a target we are composing, paused, or done.

      Parameters

      Returns void

    • Subscribe to the metadata keys we want told about.

      Parameters

      • keys: string[]

      Returns void

    • Advance the clock. monotonicMs drives every deadline; unixMs only stamps a message the server did not stamp itself with server-time.

      Parameters

      • monotonic_ms: number
      • unix_ms: number

      Returns void

    • Stop watching nicks.

      Parameters

      • nicks: string[]

      Returns void

    • Watch nicks, so we hear when they come online.

      Parameters

      • nicks: string[]

      Returns void

    • Ask the server everything it will say about someone.

      Parameters

      • nick: string

      Returns void