Skip to content

feat: Implement automatic host reassignment when host leaves#6

Open
balaraj74 wants to merge 7 commits intoacmpesuecc:mainfrom
balaraj74:main
Open

feat: Implement automatic host reassignment when host leaves#6
balaraj74 wants to merge 7 commits intoacmpesuecc:mainfrom
balaraj74:main

Conversation

@balaraj74
Copy link

{PR Name}

Closes #1

Which issue(s) does this PR address?

Right now, if the host leaves or disconnects, everyone gets kicked out and the jam ends. That's pretty annoying when you're in the middle of a session! This fix makes sure the jam keeps going by automatically making someone else the host.

Why do we need this PR?

On the server side:

We now keep track of who's hosting each room
When the host leaves, we pick the next person in line to be the new host
Everyone gets notified about who the new host is
On the client side:

What logical changes are present in this PR?

When someone joins as host, we let the server know
If you get promoted to host, you'll see a popup telling you## Is there some additional work to be done later that is NOT covered in this PR?
give this
The new host can then start streaming audio to everyone else

How did you test the changes in this PR?

I ran the server locally and made sure:

Are there any breaking changes in this PR?

Everything starts up properly
The server correctly tracks who's the host
When the host disconnects, someone else gets promoted
The new host gets notified and can take over

Nope! Everything that worked before still works the same way.

Yeah, a few nice-to-haves for later:

Is there some additional work to be done later that is NOT covered in this PR?

give this
Better UI showing who's currently hosting
Let hosts manually pass control to someone else
Add some automated tests to make sure this keeps working

- Track hostId in server room objects to identify current host
- Automatically promote first remaining participant when host disconnects
- Notify all clients with 'host-promoted' message including new host details
- Enable promoted joiners to acquire media and stream audio as new host
- Add role-based permissions so only host can start/end calls
- Maintain session continuity instead of closing when host leaves

Fixes #1
feat: Implement automatic host reassignment when host leaves
@bunsamosa-bot
Copy link

bunsamosa-bot bot commented Oct 17, 2025

Thank you from Opening this Pull Request, @balaraj74 ! A Maintainer will review it soon!

@maayamohan
Copy link
Contributor

@balaraj74 where are you? I wanna discuss this in person.

@balaraj74
Copy link
Author

I am in sem hall 1 5th row

@maayamohan
Copy link
Contributor

okk coming

@maayamohan
Copy link
Contributor

im in your row, in an acm hoodie

@balaraj74
Copy link
Author

where are you

@maayamohan
Copy link
Contributor

maayamohan commented Oct 17, 2025

@balaraj74 im so sorry i went to sem hall 2 (accidentally instead of sem hall 1). Can you come here

@balaraj74
Copy link
Author

ok i will

@balaraj74
Copy link
Author

I am in sem hall 2

@maayamohan
Copy link
Contributor

I am in sem hall 2

where?

@maayamohan
Copy link
Contributor

im in 5th row, wearing acm hoodie

@balaraj74
Copy link
Author

Where are you

@maayamohan
Copy link
Contributor

are u in sem hall 2

@balaraj74
Copy link
Author

No I came back

@balaraj74
Copy link
Author

I search everywhere

@balaraj74
Copy link
Author

Can I upload the screenshot for the review insted

@balaraj74
Copy link
Author

Screenshot from 2025-10-18 05-12-21 Screenshot from 2025-10-18 05-12-36 Screenshot from 2025-10-18 05-12-55 Screenshot from 2025-10-18 05-13-05

- Display local audio wrapper and hide remote audio for new host
- Show start and end buttons, hide exit button
- Enable start button with updated text "Start Jam (You are Host)"
- Add proper event listener to acquire audio and stream to participants
- Fix button references at top of join.js file

This ensures promoted hosts can actually stream audio instead of just
receiving a notification without controls.
Previously, host promotion only worked when host disconnected/closed tab.
Now when host clicks "End Jam" button:
- Server removes host from room
- Broadcasts client-left message
- Promotes first remaining participant to host
- Sends host-promoted notification to all clients

This ensures session continuity whether host disconnects or ends session properly.
- Added detailed console.log statements throughout host promotion flow
- Get fresh references to DOM elements when promoted to avoid stale references
- Use inline-block display for buttons to ensure visibility
- Added server-side logging to track promotion messages being sent
- Created TESTING_GUIDE.md with step-by-step test instructions
- Improved error handling and user feedback

This will help debug and verify that host promotion is working correctly.
…ates

- Server-side: Track host in active rooms, automatically promote first participant when host leaves (disconnect or end-call)
- Server broadcasts room-update with participants and hostId to all clients
- Client-side: Add helper functions for room state caching, UI toggles (enableHostUI/enableListenerUI)
- Client-side: Handle host-promoted and room-update messages to sync host state
- Client-side: Promoted participant gets host controls (Start/End Jam buttons) with proper label
- UI: Display participants list with crown (👑) icon for current host
- UI: Listener participants show Exit button, hosts show Start/End Jam buttons
- Enhanced logging for debugging room state transitions
feat: Implement host reassignment with automatic promotion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reassigning host when current host leaves

2 participants