Broadcasting events

Now that we have our custom event listeners and emitters in place, it's time to actually wire up the message system so when one user sends a message to the server, it actually gets sent to every connected user. If I have two tabs open and I emit a createMessage event from one tab, I should see the message arrive in the second one.

To test things locally, we'll be using separate tabs, but the same would work on Heroku with separate browsers on separate networks; as long as everyone has the same URL on their browser, they will be connected, regardless of which machine they're on. Now, for localhost, we obviously don't have the right privilege, but as we deploy to Heroku, which we will be doing in this section, we'll be able ...

Get Advanced Node.js Development 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.