Thuum Playground

Relay Broker

Serve a topic and send it requests, from two connections on this page: a server and a client. The Log shows both legs; the Code panel, each side in @thuum/client, plain browser JavaScript and Node.js.

server: connecting… client: connecting…

Server

none

Not serving. Serve to answer the requests on the topic.

Answer with

Answers with the request itself: its head, then its body parts as they arrive.

Requests received

No requests yet. Serve, then send one from the Client panel or from another window.

Client

Sends a request to whoever serves the topic; the response comes back to this connection only.

Body parts (JSON)
1
None: the head goes alone, with done. Else a part with done follows the last one.
Ctrl+Enter or ⌘+Enter in a field

Response

Send a request to see its response here, part by part.

Side
import { ThuumClient } from '@thuum/client';

// Your server's token route: it keeps the App Key, the browser gets a short-lived token.
const { token } = await fetch('/playground/relay/675ex8mhfu/token').then((r) => r.json());

const thuum = new ThuumClient({ baseUrl: 'https://api.thuum.dev' });
const socket = thuum.domain('thuum', token).relayBroker.connect();
await socket.ready;

try {
  // Resolves with the response's head; its body parts follow as they arrive.
  const response = await socket.request(
    'playground:675ex8mhfu',
    { "question": "What does the Relay Broker do?" },
    ["Hello, server"],
    { timeoutMs: 10000 }
  );
  console.log(response.head);
  for await (const part of response.body) console.log(part);
} catch (error) {
  // A RelayBrokerSocketError: 'unavailable' at once when nobody serves the topic, 'timeout',
  // 'cancelled' (pass { signal } and abort it), 'server_gone', …
  console.error(error.code, error.message);
}

Runs in the browser. The token route belongs to your server, which keeps the App Key.

Anyone with this page's link can send requests to this sandbox, and serve it. Nothing is stored. Open a second window and serve there too: one server is active, the other standby, and it takes over when the first one leaves.