Sending messages to the user's friends only

The last change in our backend dispatches the received chat messages to all the users in our social network. This is of course not really practical, because we may exchange text with people who do not know each other. We have to change our code accordingly so that we send messages only to the users in our friends list.

With Socket.IO, we do not have access to the request and response objects as we do in the backend API by default. This will make the solving of the problem a bit more interesting because we can't recognize the user sending the message. Thankfully, Socket.IO gives us access to the active session. It is in a raw format. So, we will need to parse it and extract the user's profile data. To ...

Get Node.js By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.