You may wish to consider the lockRoom method with the systemAction event

lockRoom is a function that locks the current Room when in session to prevent other Peers from joining the Room. This can be utilised to lock the room after a certain number of peers have joined the room. To calculate the number of peers in a room, you can use the getPeersInRoom method.

 

The "ROOM_LOCKED" property of "SYSTEM_ACTION_REASON" returns the value : "locked" when the room is locked. This can be used to determine the locked status of a room and accordingly alert and redirect users attempting to enter a locked room elsewhere.