Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the previous video, we added the front-end for our chat room in Joomla! Now let's add the back-end code so Joomla! users can talk to each other through the chat room. First, make sure you have at least two users in Joomla! I've added Joe and Tom both as users. Next, we're going to work with the server. I've copied the code from the exercise files, and it has a package.json file. Several dependencies are listed, so let's install them.
After the modules are installed open up the server.js. In addition to the modules that we used in the original chat room, we're also loading the Joomla! module and the Cookie module, both of these modules are going to work together to authenticate users in Joomla! There are two options for configuring the Joomla! module. You can either pass in the full path to the Joomla! site, or you can pass in an object with the configuration values. I'm going to find the path to the Joomla! site and pass it in here.
The Joomla! module will automatically load your configuration.php file, run it and extract the configuration information. Once the configuration information is loaded, we log a message to the console, saying that the Joomla! site is ready. Now let's take a look at the function attached to the connection event. First, we're using cookie.parse to parse the cookies from the socket. Then we pass this object into the off cookies method of the Joomla! module.
Finally, this function returns the Joomla! user. If the username of the Joomla! user object is blank, that means the authentication failed. In this case we call the failure method of the chatter module. Otherwise, we connect the chatter to the chat room. We're passing in the username property of the Joomla! user object as the username. Let's start the server and start chatting. Now let's Refresh this page. The server responds saying, Please login to the chat room.
I'm going to login as Joe. Now that I've logged in as Joe the chat server sees my cookie, authenticates me, and then greets me by name. Now let's use a separate browser to login as Tom. It's important to use a separate browser, because this browser already has the cookie for Joe. I'm going to open up Safari. Again, we get a message saying, Please login to the chat room. Now that I've logged in as Tom, it shows me as online.
If I go back to the original chat room, I see the message that I just typed. The Joomla! module for Node allows you to connect to the database and authenticate users through cookies. Doing this allows you to associate the correct username with the socket. Once the server is running, users can log into Joomla! as they normally would, then talk to each other in the chat room.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92459 Viewers
82 Video lessons · 104136 Viewers
71 Video lessons · 75591 Viewers
56 Video lessons · 106967 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.