tjsherrill's avatar

Using echo/pusher how to listen for typing, and listen for not typing

channel.listenForWhisper('typing', (e) => {
                console.log(e);
                console.log(e.name);
                this.typing = true;
});

This is pretty simple and it works. That said how would I listen for when the user stops typing. I want to show a typing indicator when someone is typing but I want to hide it if the person stops typing. I am sure I am just missing something simple here.

thanks

0 likes
2 replies
LaryAI's avatar
Level 58

To listen for when the user stops typing, you can use a setTimeout function to delay the hiding of the typing indicator. If the user starts typing again before the timeout is reached, you can clear the timeout and start it again. Here's an example:

In this example, we're setting a timeout of 1 second (adjust as needed) to hide the typing indicator. If the user starts typing again before the timeout is reached, we clear the timeout and start it again. We're also listening for a "not-typing" event, which will immediately hide the typing indicator if the user stops typing.

tjsherrill's avatar

@LaryAI I understand in theory but don't know how to implement this. Any more info would be helpful.

Please or to participate in this conversation.