Fixed events on server when user logs in.

master
Håvar Aambø Fosstveit 2019-10-30 22:12:29 +01:00
parent b5dd7f0ee4
commit 549176b86e
3 changed files with 46 additions and 5 deletions

View File

@ -192,7 +192,14 @@ class Peer extends EventEmitter
set displayName(displayName) set displayName(displayName)
{ {
this._displayName = displayName; if (displayName !== this._displayName)
{
const oldDisplayName = this._displayName;
this._displayName = displayName;
this.emit('displayNameChanged', { oldDisplayName });
}
} }
get picture() get picture()
@ -202,7 +209,14 @@ class Peer extends EventEmitter
set picture(picture) set picture(picture)
{ {
this._picture = picture; if (picture !== this._picture)
{
const oldPicture = this._picture;
this._picture = picture;
this.emit('pictureChanged', { oldPicture });
}
} }
get email() get email()

View File

@ -339,6 +339,33 @@ class Room extends EventEmitter
this.selfDestructCountdown(); this.selfDestructCountdown();
} }
}); });
peer.on('displayNameChanged', ({ oldDisplayName }) =>
{
// Ensure the Peer is joined.
if (!peer.data.joined)
throw new Error('Peer not yet joined');
// Spread to others
this._notification(peer.socket, 'changeDisplayName', {
peerId : peer.id,
displayName : peer.displayName,
oldDisplayName : oldDisplayName
}, true);
});
peer.on('pictureChanged', () =>
{
// Ensure the Peer is joined.
if (!peer.data.joined)
throw new Error('Peer not yet joined');
// Spread to others
this._notification(peer.socket, 'changePicture', {
peerId : peer.id,
picture : peer.picture
}, true);
});
} }
async _handleSocketRequest(peer, request, cb) async _handleSocketRequest(peer, request, cb)

View File

@ -177,10 +177,8 @@ async function setupAuth(oidcIssuer)
// any of the supported values directly, i.e. "S256" (recommended) or "plain" // any of the supported values directly, i.e. "S256" (recommended) or "plain"
const usePKCE = false; const usePKCE = false;
const client = oidcClient;
oidcStrategy = new Strategy( oidcStrategy = new Strategy(
{ client, params, passReqToCallback, usePKCE }, { client: oidcClient, params, passReqToCallback, usePKCE },
(tokenset, userinfo, done) => (tokenset, userinfo, done) =>
{ {
const user = const user =
@ -286,6 +284,8 @@ async function setupAuth(oidcIssuer)
const peer = peers.get(state.id); const peer = peers.get(state.id);
peer && (peer.authenticated = true); peer && (peer.authenticated = true);
peer && (peer.displayName = displayName);
peer && (peer.picture = picture);
res.send(httpHelper({ res.send(httpHelper({
displayName, displayName,