Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
Adapt my chat app to work with socket.io rooms

I have this chat app that I'm working on for a school project, and I need to improve it a little bit since it is pretty basic and simple. How can I make it so users can choose the room where they want their messages to be sent to? As a start, I created 4 room buttons that change the window.location.href (for example, if you click on the "room1" button, it changes the link to "http://127.0.0.1:5500/Client/index.html#room1", this way I can grab the room name and use it later, but I'm not sure if it is the right approach so I'll just change it if suggested). What would be the next steps?

Client side:

 //This changes the link so I can grab the room name when needed
 room1Btn.addEventListener('click', () =>{
        window.location.href='#room1';      
    })


 //This sends the message to the server when clicking on the Submit button
 sendBtn.addEventListener('click', () =>{
        sendMessage();
        })
 function sendMessage(){
        if(messageInput.value === ""){
            return;
        } else {
            const text = messageInput.value;
            socket.emit('message', text);
            socket.emit('sendName', name);
                       
        //This function displays the message
        messageDisplay();
        }
    }

Server side:

io.on('connection', (socket) => { 
 
        //Sends the message to the clients
        socket.on('message', (message) => {
            socket.broadcast.emit('message', `${message}`);        
        });
});

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!