diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index 2c4f6c2..3662bd4 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -321,12 +321,7 @@ export default class RoomClient const { displayName, picture } = data; - if (store.getState().room.joined || store.getState().room.inLobby) - { - this.changeDisplayName(displayName); - this.changeProfilePicture(picture); - } - + store.dispatch(stateActions.setDisplayName(displayName)); store.dispatch(stateActions.setPicture(picture)); store.dispatch(stateActions.loggedIn()); diff --git a/server/lib/Peer.js b/server/lib/Peer.js index 847ac52..a527a6a 100644 --- a/server/lib/Peer.js +++ b/server/lib/Peer.js @@ -12,18 +12,24 @@ class Peer extends EventEmitter this._id = id; + this._authId = null; + this._socket = socket; this._closed = false; this._joined = false; + this._inLobby = false; + this._authenticated = false; this._displayName = false; this._picture = null; + this._email = null; + this._device = null; this._rtpCapabilities = null; @@ -71,20 +77,10 @@ class Peer extends EventEmitter this.socket.on('request', (request, cb) => { - logger.debug( - 'Peer "request" event [method:"%s", peer:"%s"]', - request.method, this.id); - if (this._closed) return; - this._handleSocketRequest(request, cb) - .catch((error) => - { - logger.error('request failed [error:"%o"]', error); - - cb(error); - }); + this._handleSocketRequest(request, cb).catch(cb); }); this.socket.on('disconnect', () => @@ -100,12 +96,6 @@ class Peer extends EventEmitter async _handleSocketRequest(request, cb) { - logger.debug( - '_handleSocketRequest [peer:"%s"], [request:"%s"]', - this.id, - request.method - ); - if (this._closed) return; @@ -121,14 +111,45 @@ class Peer extends EventEmitter break; } + + case 'changeProfilePicture': + { + const { picture } = request.data; + + this.picture = picture; + + cb(); + + break; + } } } _checkAuthentication() { - this.authenticated = + if ( Boolean(this.socket.handshake.session.passport) && - Boolean(this.socket.handshake.session.passport.user); + Boolean(this.socket.handshake.session.passport.user) + ) + { + const { + id, + displayName, + picture, + email + } = this.socket.handshake.session.passport.user; + + id && (this.authId = id); + displayName && (this.displayName = displayName); + picture && (this.picture = picture); + email && (this.email = email); + + this.authenticated = true; + } + else + { + this.authenticated = false; + } } get id() @@ -141,6 +162,16 @@ class Peer extends EventEmitter this._id = id; } + get authId() + { + return this._authId; + } + + set authId(authId) + { + this._authId = authId; + } + get socket() { return this._socket; @@ -166,6 +197,16 @@ class Peer extends EventEmitter this._joined = joined; } + get inLobby() + { + return this._inLobby; + } + + set inLobby(inLobby) + { + this._inLobby = inLobby; + } + get authenticated() { return this._authenticated; @@ -217,6 +258,16 @@ class Peer extends EventEmitter } } + get email() + { + return this._email; + } + + set email(email) + { + this._email = email; + } + get device() { return this._device; diff --git a/server/lib/Room.js b/server/lib/Room.js index 4567495..564a573 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -263,10 +263,7 @@ class Room extends EventEmitter // checks both room and lobby checkEmpty() { - if ((this._peers.size == 0) && (this._lobby.checkEmpty())) - return true; - else - return false; + return (this._peers.size == 0) && (this._lobby.checkEmpty()); } _parkPeer(parkPeer) diff --git a/server/package.json b/server/package.json index 67da924..2079986 100644 --- a/server/package.json +++ b/server/package.json @@ -12,6 +12,7 @@ "body-parser": "^1.19.0", "colors": "^1.4.0", "compression": "^1.7.4", + "connect-redis": "^4.0.3", "cookie-parser": "^1.4.4", "debug": "^4.1.1", "express": "^4.17.1", @@ -21,6 +22,7 @@ "mediasoup": "^3.0.12", "openid-client": "^3.7.3", "passport": "^0.4.0", + "redis": "^2.8.0", "socket.io": "^2.3.0", "spdy": "^4.0.1" } diff --git a/server/server.js b/server/server.js index 8b72025..2511333 100755 --- a/server/server.js +++ b/server/server.js @@ -20,8 +20,11 @@ const helmet = require('helmet'); const httpHelper = require('./httpHelper'); // auth const passport = require('passport'); +const redis = require('redis'); +const client = redis.createClient(); const { Issuer, Strategy } = require('openid-client'); const expressSession = require('express-session'); +const RedisStore = require('connect-redis')(expressSession); const sharedSession = require('express-socket.io-session'); /* eslint-disable no-console */ @@ -67,6 +70,7 @@ const session = expressSession({ secret : config.cookieSecret, resave : true, saveUninitialized : true, + store : new RedisStore({ client }), cookie : { secure : true, httpOnly : true @@ -165,16 +169,15 @@ async function setupAuth(oidcIssuer) // optional, defaults to false, when true req is passed as a first // argument to verify fn - const passReqToCallback = false; + const passReqToCallback = false; // optional, defaults to false, when true the code_challenge_method will be // resolved from the issuer configuration, instead of true you may provide // any of the supported values directly, i.e. "S256" (recommended) or "plain" const usePKCE = false; - const client = oidcClient; oidcStrategy = new Strategy( - { client, params, passReqToCallback, usePKCE }, + { oidcClient, params, passReqToCallback, usePKCE }, (tokenset, userinfo, done) => { const user =