# Signal

URL: https://docs.folkways.io/docs/primitives/signal

Short-lived, best-effort values per sender, for typing indicators, live cursors and "here now" markers.

A **signal** is a value that is stale within seconds. Folkways keeps the latest signal for each event name and
sender until it expires (5 seconds by default), and drops it silently after that.

**Use it for:** typing indicators, live cursors and selections, "is speaking", a progress bar's position.

## How it behaves [#how-it-behaves]

- **Latest per sender.** Each sender has one value per event name; a new signal replaces their old one.
- **Expires.** A signal lives 5 seconds unless the rule or the publish sets another lifetime. Expiry is silent: no
  deletion event is sent, so clients drop expired signals themselves. Events carry the absolute expiry time and the
  server clock, so clients can tell how long a signal has left without trusting their own clock.
- **Best effort.** Signals aren't numbered, aren't replayed and aren't retried. One sent while offline is dropped.
- **Snapshot of live signals.** A new subscriber gets the signals that haven't expired yet, then new ones.
- **Cheap to send.** By default a signal gets no acknowledgement.

## Sending typing indicators well [#sending-typing-indicators-well]

Send `typing` when the user starts typing, then again every 2 to 3 seconds while they keep typing, each with a
lifetime a little longer than that interval. Clients show "alice is typing" while alice's signal is alive. No "stopped
typing" event is needed, though you can send one to clear it sooner.

## Settings [#settings]

| Setting | Default | Meaning |
| --- | --- | --- |
| Time-to-live | 5 s | Default lifetime; a publish can set its own |
| Max keys | 10,000 per topic | KV values and signals held per topic, together |

Sending needs `signal` (or `publish`) in both the token and the rule. A viewer with `subscribe` and `signal` can type
without being able to post messages.

## In code [#in-code]

<Tabs items={['JavaScript', 'Realtime API']}>
  <Tab value="JavaScript">
    ```ts
    void room.publish('typing', { on: true }, { delivery: 'signal', ttlMs: 3_000 });
    ```

    See [Signals in the SDK](/docs/js-sdk/signals).
  </Tab>
  <Tab value="Realtime API">
    Send [`Publish`](/docs/realtime-api/publish) with `delivery: Ephemeral` and an optional `ttl_ms`.
  </Tab>
</Tabs>
