Fixed race condition on socket acknowledge callback. Fixed naming on socket methods. Added error handling on socket messages.
parent
bb8cf02c23
commit
c81b377723
|
|
@ -440,17 +440,17 @@ export default class RoomClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeProfilePicture(picture)
|
async changePicture(picture)
|
||||||
{
|
{
|
||||||
logger.debug('changeProfilePicture() [picture: "%s"]', picture);
|
logger.debug('changePicture() [picture: "%s"]', picture);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await this.sendRequest('changeProfilePicture', { picture });
|
await this.sendRequest('changePicture', { picture });
|
||||||
}
|
}
|
||||||
catch (error)
|
catch (error)
|
||||||
{
|
{
|
||||||
logger.error('shareProfilePicure() | failed: %o', error);
|
logger.error('changePicture() | failed: %o', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1284,344 +1284,358 @@ export default class RoomClient
|
||||||
'socket "notification" event [method:%s, data:%o]',
|
'socket "notification" event [method:%s, data:%o]',
|
||||||
notification.method, notification.data);
|
notification.method, notification.data);
|
||||||
|
|
||||||
switch (notification.method)
|
try
|
||||||
{
|
{
|
||||||
case 'enteredLobby':
|
switch (notification.method)
|
||||||
{
|
{
|
||||||
store.dispatch(stateActions.setInLobby(true));
|
case 'enteredLobby':
|
||||||
|
|
||||||
const { displayName } = store.getState().settings;
|
|
||||||
|
|
||||||
await this.sendRequest('changeDisplayName', { displayName });
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'roomReady':
|
|
||||||
{
|
|
||||||
store.dispatch(stateActions.toggleJoined());
|
|
||||||
store.dispatch(stateActions.setInLobby(false));
|
|
||||||
|
|
||||||
await this._joinRoom({ joinVideo });
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'lockRoom':
|
|
||||||
{
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setRoomLocked());
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'Room is now locked.'
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'unlockRoom':
|
|
||||||
{
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setRoomUnLocked());
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'Room is now unlocked.'
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'parkedPeer':
|
|
||||||
{
|
|
||||||
const { peerId } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.addLobbyPeer(peerId));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'New participant entered the lobby.'
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'lobbyPeerClosed':
|
|
||||||
{
|
|
||||||
const { peerId } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.removeLobbyPeer(peerId));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'Participant in lobby left.'
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'promotedPeer':
|
|
||||||
{
|
|
||||||
const { peerId } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.removeLobbyPeer(peerId));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'lobbyPeerDisplayNameChanged':
|
|
||||||
{
|
|
||||||
const { peerId, displayName } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setLobbyPeerDisplayName(displayName, peerId));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : `Participant in lobby changed name to ${displayName}.`
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'setAccessCode':
|
|
||||||
{
|
|
||||||
const { accessCode } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setAccessCode(accessCode));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'Access code for room updated'
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'setJoinByAccessCode':
|
|
||||||
{
|
|
||||||
const { joinByAccessCode } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setJoinByAccessCode(joinByAccessCode));
|
|
||||||
|
|
||||||
if (joinByAccessCode)
|
|
||||||
{
|
{
|
||||||
|
store.dispatch(stateActions.setInLobby(true));
|
||||||
|
|
||||||
|
const { displayName } = store.getState().settings;
|
||||||
|
|
||||||
|
await this.sendRequest('changeDisplayName', { displayName });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'roomReady':
|
||||||
|
{
|
||||||
|
store.dispatch(stateActions.toggleJoined());
|
||||||
|
store.dispatch(stateActions.setInLobby(false));
|
||||||
|
|
||||||
|
await this._joinRoom({ joinVideo });
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'lockRoom':
|
||||||
|
{
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setRoomLocked());
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
store.dispatch(requestActions.notify(
|
||||||
{
|
{
|
||||||
text : 'Access code for room is now activated'
|
text : 'Room is now locked.'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
case 'unlockRoom':
|
||||||
{
|
{
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setRoomUnLocked());
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
store.dispatch(requestActions.notify(
|
||||||
{
|
{
|
||||||
text : 'Access code for room is now deactivated'
|
text : 'Room is now unlocked.'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case 'parkedPeer':
|
||||||
}
|
|
||||||
|
|
||||||
case 'activeSpeaker':
|
|
||||||
{
|
|
||||||
const { peerId } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setRoomActiveSpeaker(peerId));
|
|
||||||
|
|
||||||
if (peerId && peerId !== this._peerId)
|
|
||||||
this._spotlights.handleActiveSpeaker(peerId);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'changeDisplayName':
|
|
||||||
{
|
|
||||||
const { peerId, displayName, oldDisplayName } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.setPeerDisplayName(displayName, peerId));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : `${oldDisplayName} is now ${displayName}`
|
|
||||||
}));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'changeProfilePicture':
|
|
||||||
{
|
|
||||||
const { peerId, picture } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(stateActions.setPeerPicture(peerId, picture));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'chatMessage':
|
|
||||||
{
|
|
||||||
const { peerId, chatMessage } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(
|
|
||||||
stateActions.addResponseMessage({ ...chatMessage, peerId }));
|
|
||||||
|
|
||||||
if (
|
|
||||||
!store.getState().toolarea.toolAreaOpen ||
|
|
||||||
(store.getState().toolarea.toolAreaOpen &&
|
|
||||||
store.getState().toolarea.currentToolTab !== 'chat')
|
|
||||||
) // Make sound
|
|
||||||
{
|
{
|
||||||
this._soundNotification();
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.addLobbyPeer(peerId));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
text : 'New participant entered the lobby.'
|
||||||
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case 'lobby:peerClosed':
|
||||||
}
|
|
||||||
|
|
||||||
case 'sendFile':
|
|
||||||
{
|
|
||||||
const { peerId, magnetUri } = notification.data;
|
|
||||||
|
|
||||||
store.dispatch(stateActions.addFile(peerId, magnetUri));
|
|
||||||
|
|
||||||
store.dispatch(requestActions.notify(
|
|
||||||
{
|
|
||||||
text : 'New file available.'
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (
|
|
||||||
!store.getState().toolarea.toolAreaOpen ||
|
|
||||||
(store.getState().toolarea.toolAreaOpen &&
|
|
||||||
store.getState().toolarea.currentToolTab !== 'files')
|
|
||||||
) // Make sound
|
|
||||||
{
|
{
|
||||||
this._soundNotification();
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.removeLobbyPeer(peerId));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
text : 'Participant in lobby left.'
|
||||||
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case 'lobby:promotedPeer':
|
||||||
}
|
{
|
||||||
|
const { peerId } = notification.data;
|
||||||
case 'producerScore':
|
|
||||||
{
|
store.dispatch(
|
||||||
const { producerId, score } = notification.data;
|
stateActions.removeLobbyPeer(peerId));
|
||||||
|
|
||||||
store.dispatch(
|
break;
|
||||||
stateActions.setProducerScore(producerId, score));
|
}
|
||||||
|
|
||||||
break;
|
case 'lobby:changeDisplayName':
|
||||||
}
|
{
|
||||||
|
const { peerId, displayName } = notification.data;
|
||||||
case 'newPeer':
|
|
||||||
{
|
store.dispatch(
|
||||||
const { id, displayName, picture, device } = notification.data;
|
stateActions.setLobbyPeerDisplayName(displayName, peerId));
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(requestActions.notify(
|
||||||
stateActions.addPeer({ id, displayName, picture, device, consumers: [] }));
|
{
|
||||||
|
text : `Participant in lobby changed name to ${displayName}.`
|
||||||
store.dispatch(requestActions.notify(
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'setAccessCode':
|
||||||
|
{
|
||||||
|
const { accessCode } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setAccessCode(accessCode));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
text : 'Access code for room updated'
|
||||||
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'setJoinByAccessCode':
|
||||||
|
{
|
||||||
|
const { joinByAccessCode } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setJoinByAccessCode(joinByAccessCode));
|
||||||
|
|
||||||
|
if (joinByAccessCode)
|
||||||
{
|
{
|
||||||
text : `${displayName} joined the room.`
|
store.dispatch(requestActions.notify(
|
||||||
}));
|
{
|
||||||
|
text : 'Access code for room is now activated'
|
||||||
break;
|
}));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
case 'peerClosed':
|
{
|
||||||
{
|
store.dispatch(requestActions.notify(
|
||||||
const { peerId } = notification.data;
|
{
|
||||||
|
text : 'Access code for room is now deactivated'
|
||||||
store.dispatch(
|
}));
|
||||||
stateActions.removePeer(peerId));
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'consumerClosed':
|
|
||||||
{
|
|
||||||
const { consumerId } = notification.data;
|
|
||||||
const consumer = this._consumers.get(consumerId);
|
|
||||||
|
|
||||||
if (!consumer)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
consumer.close();
|
|
||||||
|
case 'activeSpeaker':
|
||||||
if (consumer.hark != null)
|
{
|
||||||
consumer.hark.stop();
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
this._consumers.delete(consumerId);
|
store.dispatch(
|
||||||
|
stateActions.setRoomActiveSpeaker(peerId));
|
||||||
const { peerId } = consumer.appData;
|
|
||||||
|
if (peerId && peerId !== this._peerId)
|
||||||
store.dispatch(
|
this._spotlights.handleActiveSpeaker(peerId);
|
||||||
stateActions.removeConsumer(consumerId, peerId));
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'consumerPaused':
|
|
||||||
{
|
|
||||||
const { consumerId } = notification.data;
|
|
||||||
const consumer = this._consumers.get(consumerId);
|
|
||||||
|
|
||||||
if (!consumer)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
store.dispatch(
|
|
||||||
stateActions.setConsumerPaused(consumerId, 'remote'));
|
case 'changeDisplayName':
|
||||||
|
{
|
||||||
break;
|
const { peerId, displayName, oldDisplayName } = notification.data;
|
||||||
}
|
|
||||||
|
store.dispatch(
|
||||||
case 'consumerResumed':
|
stateActions.setPeerDisplayName(displayName, peerId));
|
||||||
{
|
|
||||||
const { consumerId } = notification.data;
|
store.dispatch(requestActions.notify(
|
||||||
const consumer = this._consumers.get(consumerId);
|
{
|
||||||
|
text : `${oldDisplayName} is now ${displayName}`
|
||||||
if (!consumer)
|
}));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
store.dispatch(
|
|
||||||
stateActions.setConsumerResumed(consumerId, 'remote'));
|
case 'changePicture':
|
||||||
|
{
|
||||||
break;
|
const { peerId, picture } = notification.data;
|
||||||
}
|
|
||||||
|
store.dispatch(stateActions.setPeerPicture(peerId, picture));
|
||||||
case 'consumerLayersChanged':
|
|
||||||
{
|
|
||||||
const { consumerId, spatialLayer, temporalLayer } = notification.data;
|
|
||||||
const consumer = this._consumers.get(consumerId);
|
|
||||||
|
|
||||||
if (!consumer)
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
store.dispatch(stateActions.setConsumerCurrentLayers(
|
|
||||||
consumerId, spatialLayer, temporalLayer));
|
case 'chatMessage':
|
||||||
|
{
|
||||||
break;
|
const { peerId, chatMessage } = notification.data;
|
||||||
}
|
|
||||||
|
store.dispatch(
|
||||||
case 'consumerScore':
|
stateActions.addResponseMessage({ ...chatMessage, peerId }));
|
||||||
{
|
|
||||||
const { consumerId, score } = notification.data;
|
if (
|
||||||
|
!store.getState().toolarea.toolAreaOpen ||
|
||||||
store.dispatch(
|
(store.getState().toolarea.toolAreaOpen &&
|
||||||
stateActions.setConsumerScore(consumerId, score));
|
store.getState().toolarea.currentToolTab !== 'chat')
|
||||||
|
) // Make sound
|
||||||
break;
|
{
|
||||||
}
|
this._soundNotification();
|
||||||
|
}
|
||||||
default:
|
|
||||||
{
|
break;
|
||||||
logger.error(
|
}
|
||||||
'unknown notification.method "%s"', notification.method);
|
|
||||||
|
case 'sendFile':
|
||||||
|
{
|
||||||
|
const { peerId, magnetUri } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(stateActions.addFile(peerId, magnetUri));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
text : 'New file available.'
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (
|
||||||
|
!store.getState().toolarea.toolAreaOpen ||
|
||||||
|
(store.getState().toolarea.toolAreaOpen &&
|
||||||
|
store.getState().toolarea.currentToolTab !== 'files')
|
||||||
|
) // Make sound
|
||||||
|
{
|
||||||
|
this._soundNotification();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'producerScore':
|
||||||
|
{
|
||||||
|
const { producerId, score } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setProducerScore(producerId, score));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'newPeer':
|
||||||
|
{
|
||||||
|
const { id, displayName, picture, device } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.addPeer({ id, displayName, picture, device, consumers: [] }));
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
text : `${displayName} joined the room.`
|
||||||
|
}));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'peerClosed':
|
||||||
|
{
|
||||||
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.removePeer(peerId));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'consumerClosed':
|
||||||
|
{
|
||||||
|
const { consumerId } = notification.data;
|
||||||
|
const consumer = this._consumers.get(consumerId);
|
||||||
|
|
||||||
|
if (!consumer)
|
||||||
|
break;
|
||||||
|
|
||||||
|
consumer.close();
|
||||||
|
|
||||||
|
if (consumer.hark != null)
|
||||||
|
consumer.hark.stop();
|
||||||
|
|
||||||
|
this._consumers.delete(consumerId);
|
||||||
|
|
||||||
|
const { peerId } = consumer.appData;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.removeConsumer(consumerId, peerId));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'consumerPaused':
|
||||||
|
{
|
||||||
|
const { consumerId } = notification.data;
|
||||||
|
const consumer = this._consumers.get(consumerId);
|
||||||
|
|
||||||
|
if (!consumer)
|
||||||
|
break;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setConsumerPaused(consumerId, 'remote'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'consumerResumed':
|
||||||
|
{
|
||||||
|
const { consumerId } = notification.data;
|
||||||
|
const consumer = this._consumers.get(consumerId);
|
||||||
|
|
||||||
|
if (!consumer)
|
||||||
|
break;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setConsumerResumed(consumerId, 'remote'));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'consumerLayersChanged':
|
||||||
|
{
|
||||||
|
const { consumerId, spatialLayer, temporalLayer } = notification.data;
|
||||||
|
const consumer = this._consumers.get(consumerId);
|
||||||
|
|
||||||
|
if (!consumer)
|
||||||
|
break;
|
||||||
|
|
||||||
|
store.dispatch(stateActions.setConsumerCurrentLayers(
|
||||||
|
consumerId, spatialLayer, temporalLayer));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'consumerScore':
|
||||||
|
{
|
||||||
|
const { consumerId, score } = notification.data;
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
stateActions.setConsumerScore(consumerId, score));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
logger.error(
|
||||||
|
'unknown notification.method "%s"', notification.method);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (error)
|
||||||
|
{
|
||||||
|
logger.error('error on socket "notification" event failed:"%o"', error);
|
||||||
|
|
||||||
|
store.dispatch(requestActions.notify(
|
||||||
|
{
|
||||||
|
type : 'error',
|
||||||
|
text : 'Error on server request.'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,9 @@ const Lobby = ({
|
||||||
case 'Escape':
|
case 'Escape':
|
||||||
{
|
{
|
||||||
if (displayName === '')
|
if (displayName === '')
|
||||||
changeDisplayName('Guest');
|
roomClient.changeDisplayName('Guest');
|
||||||
|
else
|
||||||
|
roomClient.changeDisplayName(displayName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
@ -111,7 +113,9 @@ const Lobby = ({
|
||||||
onBlur={() =>
|
onBlur={() =>
|
||||||
{
|
{
|
||||||
if (displayName === '')
|
if (displayName === '')
|
||||||
changeDisplayName('Guest');
|
roomClient.changeDisplayName('Guest');
|
||||||
|
else
|
||||||
|
roomClient.changeDisplayName(displayName);
|
||||||
}}
|
}}
|
||||||
margin='normal'
|
margin='normal'
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ module.exports =
|
||||||
},*/
|
},*/
|
||||||
// session cookie secret
|
// session cookie secret
|
||||||
cookieSecret : 'T0P-S3cR3t_cook!e',
|
cookieSecret : 'T0P-S3cR3t_cook!e',
|
||||||
|
cookieName : 'multiparty-meeting.sid',
|
||||||
tls :
|
tls :
|
||||||
{
|
{
|
||||||
cert : `${__dirname}/../certs/mediasoup-demo.localhost.cert.pem`,
|
cert : `${__dirname}/../certs/mediasoup-demo.localhost.cert.pem`,
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,22 @@ class Lobby extends EventEmitter
|
||||||
peer.authenticated && this.emit('peerAuthenticated', peer);
|
peer.authenticated && this.emit('peerAuthenticated', peer);
|
||||||
});
|
});
|
||||||
|
|
||||||
peer.on('displayNameChanged', () =>
|
peer.socket.on('request', (request, cb) =>
|
||||||
{
|
{
|
||||||
this.emit('displayNameChanged', peer);
|
logger.debug(
|
||||||
});
|
'Peer "request" event [method:"%s", peer:"%s"]',
|
||||||
|
request.method, peer.id);
|
||||||
|
|
||||||
|
if (this._closed)
|
||||||
|
return;
|
||||||
|
|
||||||
peer.on('pictureChanged', () =>
|
this._handleSocketRequest(peer, request, cb)
|
||||||
{
|
.catch((error) =>
|
||||||
this.emit('pictureChanged', peer);
|
{
|
||||||
|
logger.error('request failed [error:"%o"]', error);
|
||||||
|
|
||||||
|
cb(error);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
peer.on('close', () =>
|
peer.on('close', () =>
|
||||||
|
|
@ -124,6 +132,34 @@ class Lobby extends EventEmitter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _handleSocketRequest(peer, request, cb)
|
||||||
|
{
|
||||||
|
logger.debug(
|
||||||
|
'_handleSocketRequest [peer:"%s"], [request:"%s"]',
|
||||||
|
peer.id,
|
||||||
|
request.method
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this._closed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (request.method)
|
||||||
|
{
|
||||||
|
case 'changeDisplayName':
|
||||||
|
{
|
||||||
|
const { displayName } = request.data;
|
||||||
|
|
||||||
|
peer.displayName = displayName;
|
||||||
|
|
||||||
|
this.emit('changeDisplayName', peer);
|
||||||
|
|
||||||
|
cb();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_notification(socket, method, data = {}, broadcast = false)
|
_notification(socket, method, data = {}, broadcast = false)
|
||||||
{
|
{
|
||||||
if (broadcast)
|
if (broadcast)
|
||||||
|
|
|
||||||
|
|
@ -75,14 +75,6 @@ class Peer extends EventEmitter
|
||||||
return next();
|
return next();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on('request', (request, cb) =>
|
|
||||||
{
|
|
||||||
if (this._closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
this._handleSocketRequest(request, cb).catch(cb);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.socket.on('disconnect', () =>
|
this.socket.on('disconnect', () =>
|
||||||
{
|
{
|
||||||
if (this.closed)
|
if (this.closed)
|
||||||
|
|
@ -94,37 +86,6 @@ class Peer extends EventEmitter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async _handleSocketRequest(request, cb)
|
|
||||||
{
|
|
||||||
if (this._closed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (request.method)
|
|
||||||
{
|
|
||||||
case 'changeDisplayName':
|
|
||||||
{
|
|
||||||
const { displayName } = request.data;
|
|
||||||
|
|
||||||
this.displayName = displayName;
|
|
||||||
|
|
||||||
cb();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'changeProfilePicture':
|
|
||||||
{
|
|
||||||
const { picture } = request.data;
|
|
||||||
|
|
||||||
this.picture = picture;
|
|
||||||
|
|
||||||
cb();
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_checkAuthentication()
|
_checkAuthentication()
|
||||||
{
|
{
|
||||||
if (
|
if (
|
||||||
|
|
@ -231,14 +192,7 @@ class Peer extends EventEmitter
|
||||||
|
|
||||||
set displayName(displayName)
|
set displayName(displayName)
|
||||||
{
|
{
|
||||||
if (displayName !== this._displayName)
|
this._displayName = displayName;
|
||||||
{
|
|
||||||
const oldDisplayName = this._displayName;
|
|
||||||
|
|
||||||
this._displayName = displayName;
|
|
||||||
|
|
||||||
this.emit('displayNameChanged', { oldDisplayName });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get picture()
|
get picture()
|
||||||
|
|
@ -248,14 +202,7 @@ class Peer extends EventEmitter
|
||||||
|
|
||||||
set picture(picture)
|
set picture(picture)
|
||||||
{
|
{
|
||||||
if (picture !== this._picture)
|
this._picture = picture;
|
||||||
{
|
|
||||||
const oldPicture = this._picture;
|
|
||||||
|
|
||||||
this._picture = picture;
|
|
||||||
|
|
||||||
this.emit('pictureChanged', { oldPicture });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get email()
|
get email()
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ class Room extends EventEmitter
|
||||||
}
|
}
|
||||||
else if (
|
else if (
|
||||||
this._locked ||
|
this._locked ||
|
||||||
(config.requireSignInToAccess && !peer.authenticated)
|
(Boolean(config.requireSignInToAccess) && !peer.authenticated)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this._parkPeer(peer);
|
this._parkPeer(peer);
|
||||||
|
|
@ -146,7 +146,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
this._peers.forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'promotedPeer', { peerId: id });
|
this._notification(peer.socket, 'lobby:promotedPeer', { peerId: id });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -155,23 +155,23 @@ class Room extends EventEmitter
|
||||||
!this._locked && this._lobby.promotePeer(peer.id);
|
!this._locked && this._lobby.promotePeer(peer.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._lobby.on('displayNameChanged', (changedPeer) =>
|
this._lobby.on('changeDisplayName', (changedPeer) =>
|
||||||
{
|
{
|
||||||
const { id, displayName } = changedPeer;
|
const { id, displayName } = changedPeer;
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
this._peers.forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'lobbyPeerDisplayNameChanged', { peerId: id, displayName });
|
this._notification(peer.socket, 'lobby:changeDisplayName', { peerId: id, displayName });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this._lobby.on('pictureChanged', (changedPeer) =>
|
this._lobby.on('changePicture', (changedPeer) =>
|
||||||
{
|
{
|
||||||
const { id, picture } = changedPeer;
|
const { id, picture } = changedPeer;
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
this._peers.forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'lobbyPeerPictureChanged', { peerId: id, picture });
|
this._notification(peer.socket, 'lobby:changePicture', { peerId: id, picture });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -183,7 +183,7 @@ class Room extends EventEmitter
|
||||||
|
|
||||||
this._peers.forEach((peer) =>
|
this._peers.forEach((peer) =>
|
||||||
{
|
{
|
||||||
this._notification(peer.socket, 'lobbyPeerClosed', { peerId: id });
|
this._notification(peer.socket, 'lobby:peerClosed', { peerId: id });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -312,31 +312,6 @@ class Room extends EventEmitter
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
peer.on('displayNameChanged', ({ oldDisplayName }) =>
|
|
||||||
{
|
|
||||||
if (!peer.joined)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Spread to others
|
|
||||||
this._notification(peer.socket, 'changeDisplayName', {
|
|
||||||
peerId : peer.id,
|
|
||||||
displayName : peer.displayName,
|
|
||||||
oldDisplayName : oldDisplayName
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
peer.on('pictureChanged', () =>
|
|
||||||
{
|
|
||||||
if (!peer.joined)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Spread to others
|
|
||||||
this._notification(peer.socket, 'changeProfilePicture', {
|
|
||||||
peerId : peer.id,
|
|
||||||
picture : peer.picture
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
peer.on('close', () =>
|
peer.on('close', () =>
|
||||||
{
|
{
|
||||||
if (this._closed)
|
if (this._closed)
|
||||||
|
|
@ -758,6 +733,52 @@ class Room extends EventEmitter
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'changeDisplayName':
|
||||||
|
{
|
||||||
|
// Ensure the Peer is joined.
|
||||||
|
if (!peer.data.joined)
|
||||||
|
throw new Error('Peer not yet joined');
|
||||||
|
|
||||||
|
const { displayName } = request.data;
|
||||||
|
const oldDisplayName = peer.data.displayName;
|
||||||
|
|
||||||
|
peer.displayName = displayName;
|
||||||
|
|
||||||
|
// Spread to others
|
||||||
|
this._notification(peer.socket, 'changeDisplayName', {
|
||||||
|
peerId : peer.id,
|
||||||
|
displayName : displayName,
|
||||||
|
oldDisplayName : oldDisplayName
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Return no error
|
||||||
|
cb();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'changePicture':
|
||||||
|
{
|
||||||
|
// Ensure the Peer is joined.
|
||||||
|
if (!peer.data.joined)
|
||||||
|
throw new Error('Peer not yet joined');
|
||||||
|
|
||||||
|
const { picture } = request.data;
|
||||||
|
|
||||||
|
peer.picture = picture;
|
||||||
|
|
||||||
|
// Spread to others
|
||||||
|
this._notification(peer.socket, 'changePicture', {
|
||||||
|
peerId : peer.id,
|
||||||
|
picture : picture
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
// Return no error
|
||||||
|
cb();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case 'chatMessage':
|
case 'chatMessage':
|
||||||
{
|
{
|
||||||
const { chatMessage } = request.data;
|
const { chatMessage } = request.data;
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@ app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
|
|
||||||
const session = expressSession({
|
const session = expressSession({
|
||||||
secret : config.cookieSecret,
|
secret : config.cookieSecret,
|
||||||
|
name : config.cookieName,
|
||||||
resave : true,
|
resave : true,
|
||||||
saveUninitialized : true,
|
saveUninitialized : true,
|
||||||
store : new RedisStore({ client }),
|
store : new RedisStore({ client }),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue