I am currently working on implementing a "User is Typing" feature for a multi-user chat room. With my limited knowledge of RXJS I was able to produce the following snippet of code which meets the bare minimum for the "User is Typing" feature:
this.messageForm.message.valueChanges
.pipe(
tap(() => this.convoService.isUserTyping(true)),
debounceTime(500),
map(() => this.convoService.isUserTyping(false))
)
.subscribe();
However this implementation is not ideal since it produces too many requests to the server. My goal is to limit requests to 2, and using RXJS operators create the following behaviors:
- Only emit a request on the first keypress
- Ignore all subsequent keypresses
- Wait an X amount of time after what may be the last keypress
- Reset the countdown if new keypress is introduced before the countdown expires
- Emit a request once the countdown expires