How do I implement online/offline presence?
Maintain a Map of online users (userId → socketId). On connection, add the user and broadcast user:online. On disconnect, remove and broadcast user:offline. The client listens for these events and shows a green dot for online users in the chat list.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Typing Indicators and Online Presence Enhancing Chat UX with Socket.io
On input change, emit typing:start. Set a timeout to emit typing:stop after 3 seconds of no input. Clear the timeout on each new keystroke and on send. The server broadcasts typing:update to the room (excluding sender). The receiver shows 'User is typing...' when isTyping is true.
Don't broadcast all online users to everyone. On connection, find the user's connections (accepted ConnectionRequests) and only notify those users about the online status. This reduces traffic significantly for large apps.
Emit typing:stop after 3 seconds of no input (using a timeout that's cleared and reset on each keystroke), when the message is sent, or when the user leaves the chat. This prevents the typing indicator from showing indefinitely.
Still have questions?
Browse all our FAQs or reach out to our support team
