index/interfaces/TypingIndicatorConfig.md
Typing Indicator Debouncer
Debounces typing indicator events to reduce message volume. Multiple typing events from the same user within the debounce window are collapsed into a single indicator.
Features:
- Per-user debouncing (independent timers for each user)
- Automatic cleanup of pending indicators
- Configurable debounce delay
- Prevents spam of typing events
Example
// Test case: Typing indicator debouncing
const debouncer = new TypingIndicatorDebouncer({
delayMs: 100,
onTyping: (userId, roomId) => {
console.log(`User ${userId} is typing in ${roomId}`);
},
onStopTyping: (userId, roomId) => {
console.log(`User ${userId} stopped typing in ${roomId}`);
}
});
const events: string[] = [];
debouncer.onTyping = (userId, roomId) => {
events.push(`typing:${userId}:${roomId}`);
};
debouncer.onStopTyping = (userId, roomId) => {
events.push(`stop:${userId}:${roomId}`);
};
// Rapid typing events from same user
debouncer.indicate('user123', 'room1');
debouncer.indicate('user123', 'room1');
debouncer.indicate('user123', 'room1');
// Only one typing event sent (debounced)
console.assert(events.filter(e => e.startsWith('typing')).length === 1);
// Different users send independent indicators
debouncer.indicate('user456', 'room1');
debouncer.indicate('user789', 'room1');
console.assert(events.filter(e => e.startsWith('typing')).length === 3);
Since
6.6.0
Properties
| Property | Type |
|---|---|
delayMs? | number |
onStopTyping? | (userId, roomId) => void | Promise<void> |
onTyping? | (userId, roomId) => void | Promise<void> |
delay ms on stop typing user id room