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,6 +1284,8 @@ 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);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
switch (notification.method)
|
switch (notification.method)
|
||||||
{
|
{
|
||||||
case 'enteredLobby':
|
case 'enteredLobby':
|
||||||
|
|
@ -1347,7 +1349,7 @@ export default class RoomClient
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'lobbyPeerClosed':
|
case 'lobby:peerClosed':
|
||||||
{
|
{
|
||||||
const { peerId } = notification.data;
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
|
|
@ -1362,7 +1364,7 @@ export default class RoomClient
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'promotedPeer':
|
case 'lobby:promotedPeer':
|
||||||
{
|
{
|
||||||
const { peerId } = notification.data;
|
const { peerId } = notification.data;
|
||||||
|
|
||||||
|
|
@ -1372,7 +1374,7 @@ export default class RoomClient
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'lobbyPeerDisplayNameChanged':
|
case 'lobby:changeDisplayName':
|
||||||
{
|
{
|
||||||
const { peerId, displayName } = notification.data;
|
const { peerId, displayName } = notification.data;
|
||||||
|
|
||||||
|
|
@ -1455,7 +1457,7 @@ export default class RoomClient
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'changeProfilePicture':
|
case 'changePicture':
|
||||||
{
|
{
|
||||||
const { peerId, picture } = notification.data;
|
const { peerId, picture } = notification.data;
|
||||||
|
|
||||||
|
|
@ -1622,6 +1624,18 @@ export default class RoomClient
|
||||||
'unknown notification.method "%s"', notification.method);
|
'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);
|
||||||
|
|
||||||
peer.on('pictureChanged', () =>
|
if (this._closed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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)
|
|
||||||
{
|
|
||||||
const oldDisplayName = this._displayName;
|
|
||||||
|
|
||||||
this._displayName = 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)
|
|
||||||
{
|
|
||||||
const oldPicture = this._picture;
|
|
||||||
|
|
||||||
this._picture = 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