Kindly consider the following:
- When the user starts typing, client sends "typing notif" to the server
- If the user continues to type after 30 sec, the clients sends another "typing notif"
- The server broadcast "user typing notif" to the clients upon receipt of said (1) and (2), iff there was no prior "user typing notif" in the past 30 sec. (just to make sure the client is not illegally pushing typing notif)
- The client clears out "user typing" from the DOM upon receipt of a message from said user, or following 30sec since the server sent "user typing notif"; and,
- As for server->client notif in (3):
a. (3) is executed for all clients that notified the server, such that a single message is formed containing all "typing" users; and,
b. (3) is concatenated to a chat message sent by a user to same room (if there was one); and,
c. (3) is executed just for the online users.
While not perfect, the cost is minimal:
client -> server: 1 message per typing users per 30 sec.
server -> online clients: 1 message containing all typing users per 30sec. (potentially no message at all given 5b).
Changing the latency granularity (i.e., 30sec above) will set a tradeoff between usability and cpu cycles.
@kikii and @laserfire3 take a look at:
https://github.com/NodeBB/NodeBB/issues/7330