Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9027663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:47:57+00:00 2026-06-16T06:47:57+00:00

Considering a multi-chat application. Users can join multiple rooms ( socket.join(room) ), users can

  • 0

Considering a multi-chat application.
Users can join multiple rooms ( socket.join(room) ), users can leave a room ( socket.leave(room) ).

When socket is leaving a room I notify the other room participants. If the socket is currently in 3 rooms, and he suddenly disconnects from the website without leaving the rooms the proper way, how can I notify those rooms that the user has left ?

If I work with the on socket disconnect event, the user will no longer be in any room at that point. Is the only way keeping a separate array of users, or is there some clever way I haven’t thought about?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:47:58+00:00Added an answer on June 16, 2026 at 6:47 am

    During the disconnect event the socket is still available to your process. For example, this should work

    io.socket.on('connection', function(socket){
        socket.on('disconnect', function() {
           // this returns a list of all rooms this user is in
           var rooms = io.sockets.manager.roomClients[socket.id];
           for(var room in rooms) {
               socket.leave(room);
           }
        });
    });
    

    Although this is not actually necessary as socket.io will automatically prune rooms upon a disconnect event. However this method could be used if you were looking to perform a specific action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When considering a platform for a game, I've decided on multi-platform (Win/Lin/Mac) but can't
I am building a multi-user web application. Each user can have their own site
I'm building a multi-tenant ASP .NET application. Given that each tenant can configure their
I am considering best option to create multi-purpose admin page in my asp.net application.
I'm considering a multi-threaded architecture for a processing pipeline. My main processing module has
Given multi-tenant application, How are vendors implementing email notifications from an email account setup
Both Page.Cache and Page.Application can store an application's global data, shared among requests and
I am considering creating my own web based, multi user password management software. The
I'm developing a multi-document application. Currently it uses MDI which is quite convenient for
I am in the planning phase for a multi-tenant web application primarily for US

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.