From the course: Node.js: Real-Time Web with Socket.IO

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introduction to rooms and setup

Introduction to rooms and setup

From the course: Node.js: Real-Time Web with Socket.IO

Start my 1-month free trial

Introduction to rooms and setup

- [Instructor] Now that we have a namespace ready to add rules to it, let's go ahead and add a JavaScript room our tech namespace. So the first thing you want to do is, again, go inside of our client, so index.html, and we want to go at the top of our script here and add a variable. So the variable is called room, and the value you want to to it is javascript like so. So once you have the variable room created, we need to pass it to a few things. So the first thing I want to do is pass it to the emit message once we connect here, and instead of emitting a message, we're going to emit a join event, and the join event will actually pass the room to it. So on connection we're going to change the event to a join event, and we'll use it in the server after. And we want to pass the room as the data, so basically you'll do room dot room. So I know that if you want to do ES6 syntax, you can just do room, but let's, for the sake of making sure you guys understand what we're doing, we keep it…

Contents