rooms-kit / types / chat / index.d.ts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
 * Hand-authored declarations for the "./chat" export of ardegazu-rooms-kit —
 * the compiled dist/chat/index.js (ClojureScript). Mirrors the v1.0.0
 * TypeScript API surface exactly.
 */
import { EventEmitter } from "node:events";
import type { Identity, Fingerprint } from "ardegazu-id-kit";
import type { Net, RoomLog, PeerConnState, RelayConfig } from "../index.js";

export const CHAT_SALT: "chat.ardegazu.ro/v2";

/** 32 random bytes, base64url unpadded (43 chars) — the room capability. */
export declare function newRoomSecret(): string;

export interface ChatMessage {
  id: string; // log entry hash
  from: string; // durable author id (b64url Ed25519 pub) or ""
  name: string;
  ts: number;
  text?: string;
  img?: { cid: string; mime: string; bytes: number; w: number; h: number };
  thread?: string;
  reactions: Map<string, Set<string>>; // emoji → author ids
}

export interface ChatPeer {
  state: PeerConnState;
  name?: string;
  ident?: { pub: string; fp: Fingerprint };
}

export interface ChatOptions {
  roomSecret: string;
  name: string;
  /** State directory for the blockstore/log (one per room works fine). */
  dataDir: string;
  /** Suite identity for durable authorship + the identity badge; optional. */
  identity?: Identity | null;
  appSalt?: string;
  origin?: string;
  relay?: Partial<RelayConfig>;
}

export interface ChatEvents {
  /** Every message: local-replay first (oldest→newest), then live. */
  message: [m: ChatMessage];
  reaction: [target: string, emoji: string, by: string, op: "add" | "remove"];
  peer: [id: string, p: ChatPeer];
  peerGone: [id: string];
  ready: [];
  status: [relayUp: boolean];
}

export declare class ChatClient extends EventEmitter<ChatEvents> {
  readonly net: Net;
  readonly log: RoomLog;
  readonly roomId: string;
  get myAuthorId(): string;

  static join(opts: ChatOptions): Promise<ChatClient>;

  peers(): ReadonlyMap<string, ChatPeer>;
  /** Folded history, ordered by (ts, entry hash) — the same on every replica. */
  history(): ChatMessage[];
  send(text: string, thread?: string): Promise<string>;
  react(target: string, emoji: string, op?: "add" | "remove"): Promise<string>;
  setName(name: string): Promise<void>;
  close(): Promise<void>;
  private constructor();
}

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/rooms-kit.git