Give client correct authentication status when joining a room. Fixes #166

auto_join_3.3
Håvar Aambø Fosstveit 2020-04-01 21:58:41 +02:00
parent b19add7599
commit fa032036d7
4 changed files with 37 additions and 7 deletions

View File

@ -2524,7 +2524,7 @@ export default class RoomClient
canShareFiles : this._torrentSupport canShareFiles : this._torrentSupport
})); }));
const { roles, peers } = await this.sendRequest( const { authenticated, roles, peers } = await this.sendRequest(
'join', 'join',
{ {
displayName : displayName, displayName : displayName,
@ -2532,7 +2532,14 @@ export default class RoomClient
rtpCapabilities : this._mediasoupDevice.rtpCapabilities rtpCapabilities : this._mediasoupDevice.rtpCapabilities
}); });
logger.debug('_joinRoom() joined [peers:"%o", roles:"%o"]', peers, roles); logger.debug(
'_joinRoom() joined [authenticated:"%s", peers:"%o", roles:"%o"]',
authenticated,
peers,
roles
);
store.dispatch(meActions.loggedIn(authenticated));
const myRoles = store.getState().me.roles; const myRoles = store.getState().me.roles;

View File

@ -25,6 +25,8 @@ class Peer extends EventEmitter
this._inLobby = false; this._inLobby = false;
this._authenticated = false;
this._roles = [ userRoles.ALL ]; this._roles = [ userRoles.ALL ];
this._displayName = false; this._displayName = false;
@ -146,6 +148,23 @@ class Peer extends EventEmitter
this._inLobby = inLobby; this._inLobby = inLobby;
} }
get authenticated()
{
return this._authenticated;
}
set authenticated(authenticated)
{
if (authenticated !== this._authenticated)
{
const oldAuthenticated = this._authenticated;
this._authenticated = authenticated;
this.emit('authenticationChanged', { oldAuthenticated });
}
}
get roles() get roles()
{ {
return this._roles; return this._roles;

View File

@ -555,7 +555,8 @@ class Room extends EventEmitter
cb(null, { cb(null, {
roles : peer.roles, roles : peer.roles,
peers : peerInfos peers : peerInfos,
authenticated : peer.authenticated
}); });
// Mark the new Peer as joined. // Mark the new Peer as joined.

View File

@ -354,10 +354,10 @@ async function setupAuth()
if (!peer) // User has no socket session yet, make temporary if (!peer) // User has no socket session yet, make temporary
peer = new Peer({ id: peerId, roomId }); peer = new Peer({ id: peerId, roomId });
if (peer && peer.roomId !== roomId) // The peer is mischievous if (peer.roomId !== roomId) // The peer is mischievous
throw new Error('peer authenticated with wrong room'); throw new Error('peer authenticated with wrong room');
if (peer && typeof config.userMapping === 'function') if (typeof config.userMapping === 'function')
{ {
await config.userMapping({ await config.userMapping({
peer, peer,
@ -366,6 +366,8 @@ async function setupAuth()
}); });
} }
peer.authenticated = true;
res.send(loginHelper({ res.send(loginHelper({
displayName : peer.displayName, displayName : peer.displayName,
picture : peer.picture picture : peer.picture
@ -530,10 +532,11 @@ async function runWebSocketServer()
_userinfo _userinfo
} = socket.handshake.session.passport.user; } = socket.handshake.session.passport.user;
peer.authId= id; peer.authId = id;
peer.displayName = displayName; peer.displayName = displayName;
peer.picture = picture; peer.picture = picture;
peer.email = email; peer.email = email;
peer.authenticated = true;
if (typeof config.userMapping === 'function') if (typeof config.userMapping === 'function')
{ {