diff --git a/server/config/config.example.js b/server/config/config.example.js index 71b2bdb..84abff6 100644 --- a/server/config/config.example.js +++ b/server/config/config.example.js @@ -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 : { diff --git a/server/lib/Room.js b/server/lib/Room.js index bf4f107..9ae9a80 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -126,19 +126,36 @@ class Room extends EventEmitter return; } - else if ( this._locked ) + else if (this._locked) { this._parkPeer(peer); - return; } - else if ( Boolean(config.requireSignInToAccess) && this.checkEmpty()) - { - this._parkPeer(peer); - this._notification(peer.socket, 'signInRequired'); - return; + else + { + peer.authenticated ? + this._peerJoining(peer) : + this._handleGuest(peer); } + } - this._peerJoining(peer); + _handleGuest(peer) + { + if (config.requireSignInToAccess) + { + if (config.activateOnHostJoin && !this.checkEmpty()) + { + this._peerJoining(peer); + } + else + { + this._parkPeer(peer); + this._notification(peer.socket, 'signInRequired'); + } + } + 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(); }