Fix logic for joining rooms.

master
Håvar Aambø Fosstveit 2019-11-04 15:56:17 +01:00
parent 4b0c17c698
commit b108fbac87
2 changed files with 32 additions and 11 deletions

View File

@ -40,6 +40,10 @@ module.exports =
// If false, there is no difference between guests and signed-in
// users when joining.
requireSignInToAccess : true,
// This flag has no effect when requireSignInToAccess is false
// When truthy, the room will be open to all users when the first
// authenticated user has already joined the room.
activateOnHostJoin : true,
// Mediasoup settings
mediasoup :
{

View File

@ -129,17 +129,34 @@ class Room extends EventEmitter
else if (this._locked)
{
this._parkPeer(peer);
return;
}
else if ( Boolean(config.requireSignInToAccess) && this.checkEmpty())
else
{
peer.authenticated ?
this._peerJoining(peer) :
this._handleGuest(peer);
}
}
_handleGuest(peer)
{
if (config.requireSignInToAccess)
{
if (config.activateOnHostJoin && !this.checkEmpty())
{
this._peerJoining(peer);
}
else
{
this._parkPeer(peer);
this._notification(peer.socket, 'signInRequired');
return;
}
}
else
{
this._peerJoining(peer);
}
}
_handleLobby()
{
@ -255,7 +272,7 @@ class Room extends EventEmitter
if (this._closed)
return;
if (this.checkEmpty())
if (this.checkEmpty() && this._lobby.checkEmpty())
{
logger.info(
'Room deserted for some time, closing the room [roomId:"%s"]',
@ -270,7 +287,7 @@ class Room extends EventEmitter
// checks both room and lobby
checkEmpty()
{
return (this._peers.size == 0) && (this._lobby.checkEmpty());
return this._peers.size === 0;
}
_parkPeer(parkPeer)
@ -341,7 +358,7 @@ class Room extends EventEmitter
// If this is the last Peer in the room and
// lobby is empty, close the room after a while.
if (this.checkEmpty())
if (this.checkEmpty() && this._lobby.checkEmpty())
{
this.selfDestructCountdown();
}