Init displayName according LTI

master
Mészáros Mihály 2020-01-02 09:48:10 +01:00
parent e8731a37e5
commit 78fd6e1b78
4 changed files with 68 additions and 38 deletions

View File

@ -106,7 +106,7 @@ export default class RoomClient
} }
constructor( constructor(
{ peerId, accessCode, device, useSimulcast, produce, forceTcp } = {}) { peerId, accessCode, device, useSimulcast, produce, forceTcp, displayName } = {})
{ {
if (!peerId) if (!peerId)
throw new Error('Missing peerId'); throw new Error('Missing peerId');
@ -114,8 +114,8 @@ export default class RoomClient
throw new Error('Missing device'); throw new Error('Missing device');
logger.debug( logger.debug(
'constructor() [peerId: "%s", device: "%s", useSimulcast: "%s", produce: "%s", forceTcp: "%s"]', 'constructor() [peerId: "%s", device: "%s", useSimulcast: "%s", produce: "%s", forceTcp: "%s", displayName ""]',
peerId, device.flag, useSimulcast, produce, forceTcp); peerId, device.flag, useSimulcast, produce, forceTcp, displayName);
this._signalingUrl = null; this._signalingUrl = null;
@ -128,6 +128,9 @@ export default class RoomClient
// Wheter we force TCP // Wheter we force TCP
this._forceTcp = forceTcp; this._forceTcp = forceTcp;
// Use displayName
store.dispatch(settingsActions.setDisplayName(displayName));
// Torrent support // Torrent support
this._torrentSupport = null; this._torrentSupport = null;
@ -493,7 +496,7 @@ export default class RoomClient
store.dispatch( store.dispatch(
meActions.setDisplayNameInProgress(true)); meActions.setDisplayNameInProgress(true));
try try
{ {
await this.sendRequest('changeDisplayName', { displayName }); await this.sendRequest('changeDisplayName', { displayName });
@ -811,7 +814,7 @@ export default class RoomClient
catch (error) catch (error)
{ {
logger.error('unmuteMic() | failed: %o', error); logger.error('unmuteMic() | failed: %o', error);
store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
type : 'error', type : 'error',
@ -1533,7 +1536,7 @@ export default class RoomClient
case 'enteredLobby': case 'enteredLobby':
{ {
store.dispatch(roomActions.setInLobby(true)); store.dispatch(roomActions.setInLobby(true));
const { displayName } = store.getState().settings; const { displayName } = store.getState().settings;
const { picture } = store.getState().me; const { picture } = store.getState().me;
@ -1702,7 +1705,7 @@ export default class RoomClient
store.dispatch( store.dispatch(
roomActions.setJoinByAccessCode(joinByAccessCode)); roomActions.setJoinByAccessCode(joinByAccessCode));
if (joinByAccessCode) if (joinByAccessCode)
{ {
store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
@ -1742,10 +1745,10 @@ export default class RoomClient
case 'changeDisplayName': case 'changeDisplayName':
{ {
const { peerId, displayName, oldDisplayName } = notification.data; const { peerId, displayName, oldDisplayName } = notification.data;
store.dispatch( store.dispatch(
peerActions.setPeerDisplayName(displayName, peerId)); peerActions.setPeerDisplayName(displayName, peerId));
store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
text : intl.formatMessage({ text : intl.formatMessage({
@ -1756,26 +1759,26 @@ export default class RoomClient
displayName displayName
}) })
})); }));
break; break;
} }
case 'changePicture': case 'changePicture':
{ {
const { peerId, picture } = notification.data; const { peerId, picture } = notification.data;
store.dispatch(peerActions.setPeerPicture(peerId, picture)); store.dispatch(peerActions.setPeerPicture(peerId, picture));
break; break;
} }
case 'chatMessage': case 'chatMessage':
{ {
const { peerId, chatMessage } = notification.data; const { peerId, chatMessage } = notification.data;
store.dispatch( store.dispatch(
chatActions.addResponseMessage({ ...chatMessage, peerId })); chatActions.addResponseMessage({ ...chatMessage, peerId }));
if ( if (
!store.getState().toolarea.toolAreaOpen || !store.getState().toolarea.toolAreaOpen ||
(store.getState().toolarea.toolAreaOpen && (store.getState().toolarea.toolAreaOpen &&
@ -1786,16 +1789,16 @@ export default class RoomClient
roomActions.setToolbarsVisible(true)); roomActions.setToolbarsVisible(true));
this._soundNotification(); this._soundNotification();
} }
break; break;
} }
case 'sendFile': case 'sendFile':
{ {
const { peerId, magnetUri } = notification.data; const { peerId, magnetUri } = notification.data;
store.dispatch(fileActions.addFile(peerId, magnetUri)); store.dispatch(fileActions.addFile(peerId, magnetUri));
store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
text : intl.formatMessage({ text : intl.formatMessage({
@ -1803,7 +1806,7 @@ export default class RoomClient
defaultMessage : 'New file available' defaultMessage : 'New file available'
}) })
})); }));
if ( if (
!store.getState().toolarea.toolAreaOpen || !store.getState().toolarea.toolAreaOpen ||
(store.getState().toolarea.toolAreaOpen && (store.getState().toolarea.toolAreaOpen &&
@ -1814,27 +1817,27 @@ export default class RoomClient
roomActions.setToolbarsVisible(true)); roomActions.setToolbarsVisible(true));
this._soundNotification(); this._soundNotification();
} }
break; break;
} }
case 'producerScore': case 'producerScore':
{ {
const { producerId, score } = notification.data; const { producerId, score } = notification.data;
store.dispatch( store.dispatch(
producerActions.setProducerScore(producerId, score)); producerActions.setProducerScore(producerId, score));
break; break;
} }
case 'newPeer': case 'newPeer':
{ {
const { id, displayName, picture, device } = notification.data; const { id, displayName, picture, device } = notification.data;
store.dispatch( store.dispatch(
peerActions.addPeer({ id, displayName, picture, device, consumers: [] })); peerActions.addPeer({ id, displayName, picture, device, consumers: [] }));
store.dispatch(requestActions.notify( store.dispatch(requestActions.notify(
{ {
text : intl.formatMessage({ text : intl.formatMessage({
@ -1844,20 +1847,20 @@ export default class RoomClient
displayName displayName
}) })
})); }));
break; break;
} }
case 'peerClosed': case 'peerClosed':
{ {
const { peerId } = notification.data; const { peerId } = notification.data;
store.dispatch( store.dispatch(
peerActions.removePeer(peerId)); peerActions.removePeer(peerId));
break; break;
} }
case 'consumerClosed': case 'consumerClosed':
{ {
const { consumerId } = notification.data; const { consumerId } = notification.data;
@ -1891,7 +1894,7 @@ export default class RoomClient
store.dispatch( store.dispatch(
consumerActions.setConsumerPaused(consumerId, 'remote')); consumerActions.setConsumerPaused(consumerId, 'remote'));
break; break;
} }

View File

@ -100,7 +100,8 @@ function run()
const produce = parameters.get('produce') !== 'false'; const produce = parameters.get('produce') !== 'false';
const useSimulcast = parameters.get('simulcast') === 'true'; const useSimulcast = parameters.get('simulcast') === 'true';
const forceTcp = parameters.get('forceTcp') === 'true'; const forceTcp = parameters.get('forceTcp') === 'true';
const displayName = parameters.get('displayName');
// Get current device. // Get current device.
const device = deviceInfo(); const device = deviceInfo();
@ -112,7 +113,7 @@ function run()
); );
roomClient = new RoomClient( roomClient = new RoomClient(
{ peerId, accessCode, device, useSimulcast, produce, forceTcp }); { peerId, accessCode, device, useSimulcast, produce, forceTcp, displayName });
global.CLIENT = roomClient; global.CLIENT = roomClient;

View File

@ -405,6 +405,27 @@ class Room extends EventEmitter
case 'join': case 'join':
{ {
try
{
if (peer.socket.handshake.session.passport.user.displayName)
{
this._notification(
peer.socket,
'changeDisplayname',
{
peerId : peer.id,
displayName : peer.socket.handshake.session.passport.user.displayName,
oldDisplayName : ''
},
true
);
}
}
catch (error)
{
logger.error(error);
}
// Ensure the Peer is not already joined. // Ensure the Peer is not already joined.
if (peer.joined) if (peer.joined)
throw new Error('Peer already joined'); throw new Error('Peer already joined');

View File

@ -390,9 +390,14 @@ async function runHttpsServer()
{ {
if (req.secure) if (req.secure)
{ {
if (req.isAuthenticated && req.user && req.user._lti) const ltiURL = new URL(req.protocol + '://' + req.get('host') + req.originalUrl);
if (req.isAuthenticated && req.user && req.user.displayName && !ltiURL.searchParams.get('displayName'))
{ {
logger.error(req.user._lti);
ltiURL.searchParams.append('displayName', req.user.displayName);
res.redirect(ltiURL);
} }
return next(); return next();