# Typing indicators

> Send and show typing, and set a channel's typing mode: named, anonymous or off.

Each channel has a **typing mode** (see [Typing indicators](/docs/guide/concepts/typing-indicators/)):
`named` (the default) shows who is typing, `anonymous` only how many, and `off` nothing at all.
The client knows each channel's mode and does the right thing.

## Sending

**JavaScript:**

```js
// Call on keystrokes; it sends at most what the host accepts, and nothing where typing is off.
const sent = channel.startTyping();   // false: typing is off here, nothing was sent
```

**Rust:**

```rust
let sent = channel.start_typing()?;   // false: typing is off here, nothing was sent
```

## Showing

**JavaScript:**

```js
client.on("typingStart", ({ channel, anonymous, count, members }) => {
  const text = anonymous
    ? count === 1 ? "Someone is typing…" : count === 2 ? "2 people are typing…" : "Several people are typing…"
    : `${members.map((m) => m.displayName).join(", ")} typing…`;
  showTyping(channel, text);
});

channel.typing;   // now: { kind: "named", member_ids } | { kind: "anonymous", count } | null
```

**Rust:**

```rust
use zaun_client::{Event, TypingNow};

if let Event::TypingStart { channel, typing } = event {
    match typing {
        TypingNow::Named { member_ids } => { /* show names */ }
        TypingNow::Anonymous { count } => { /* 1, 2, or 3 meaning "three or more" */ }
    }
}
let now = channel.typing();           // Option<TypingNow>
```

In an anonymous channel the count is capped: 1, 2, or 3 meaning "three or more", and your own
typing is never counted. A typing state lasts a few seconds unless it's repeated.

## Setting a channel's mode

Needs `MANAGE_CHANNELS`:

**JavaScript:**

```js
await channel.setTypingMode("anonymous");   // "named", "anonymous" or "off"
channel.typingMode;                          // the current mode
```

**Rust:**

```rust
use zaun_client::protocol::model::TypingMode;

channel.set_typing_mode(TypingMode::Anonymous)?;
let mode = channel.typing_mode();
```
