From 881eac741aa71b28c99ee84a15bccdba2cb126de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 1 May 2020 21:48:09 +0200 Subject: [PATCH] Remove getServerHistory, and use 'join' callback instead. --- app/src/RoomClient.js | 98 +++++++++++++++++-------------------------- server/lib/Room.js | 30 ++++--------- 2 files changed, 48 insertions(+), 80 deletions(-) diff --git a/app/src/RoomClient.js b/app/src/RoomClient.js index 075ff94..f35488f 100644 --- a/app/src/RoomClient.js +++ b/app/src/RoomClient.js @@ -844,62 +844,6 @@ export default class RoomClient } } - async getServerHistory() - { - logger.debug('getServerHistory()'); - - try - { - const { - chatHistory, - fileHistory, - lastNHistory, - locked, - lobbyPeers, - accessCode - } = await this.sendRequest('serverHistory'); - - (chatHistory.length > 0) && store.dispatch( - chatActions.addChatHistory(chatHistory)); - - (fileHistory.length > 0) && store.dispatch( - fileActions.addFileHistory(fileHistory)); - - if (lastNHistory.length > 0) - { - logger.debug('Got lastNHistory'); - - // Remove our self from list - const index = lastNHistory.indexOf(this._peerId); - - lastNHistory.splice(index, 1); - - this._spotlights.addSpeakerList(lastNHistory); - } - - locked ? - store.dispatch(roomActions.setRoomLocked()) : - store.dispatch(roomActions.setRoomUnLocked()); - - (lobbyPeers.length > 0) && lobbyPeers.forEach((peer) => - { - store.dispatch( - lobbyPeerActions.addLobbyPeer(peer.peerId)); - store.dispatch( - lobbyPeerActions.setLobbyPeerDisplayName(peer.displayName, peer.peerId)); - store.dispatch( - lobbyPeerActions.setLobbyPeerPicture(peer.picture)); - }); - - (accessCode != null) && store.dispatch( - roomActions.setAccessCode(accessCode)); - } - catch (error) - { - logger.error('getServerHistory() | failed: %o', error); - } - } - async muteMic() { logger.debug('muteMic()'); @@ -2733,7 +2677,13 @@ export default class RoomClient peers, tracker, permissionsFromRoles, - userRoles + userRoles, + chatHistory, + fileHistory, + lastNHistory, + locked, + lobbyPeers, + accessCode } = await this.sendRequest( 'join', { @@ -2788,6 +2738,38 @@ export default class RoomClient this.updateSpotlights(spotlights); }); + (chatHistory.length > 0) && store.dispatch( + chatActions.addChatHistory(chatHistory)); + + (fileHistory.length > 0) && store.dispatch( + fileActions.addFileHistory(fileHistory)); + + if (lastNHistory.length > 0) + { + logger.debug('_joinRoom() | got lastN history'); + + this._spotlights.addSpeakerList( + lastNHistory.filter((peerId) => peerId !== this._peerId) + ); + } + + locked ? + store.dispatch(roomActions.setRoomLocked()) : + store.dispatch(roomActions.setRoomUnLocked()); + + (lobbyPeers.length > 0) && lobbyPeers.forEach((peer) => + { + store.dispatch( + lobbyPeerActions.addLobbyPeer(peer.peerId)); + store.dispatch( + lobbyPeerActions.setLobbyPeerDisplayName(peer.displayName, peer.peerId)); + store.dispatch( + lobbyPeerActions.setLobbyPeerPicture(peer.picture)); + }); + + (accessCode != null) && store.dispatch( + roomActions.setAccessCode(accessCode)); + // Don't produce if explicitly requested to not to do it. if (this._produce) { @@ -2821,8 +2803,6 @@ export default class RoomClient // Clean all the existing notifications. store.dispatch(notificationActions.removeAllNotifications()); - this.getServerHistory(); - store.dispatch(requestActions.notify( { text : intl.formatMessage({ diff --git a/server/lib/Room.js b/server/lib/Room.js index d15ae12..7c3e782 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -597,13 +597,21 @@ class Room extends EventEmitter .filter((joinedPeer) => joinedPeer.id !== peer.id) .map((joinedPeer) => (joinedPeer.peerInfo)); + const lobbyPeers = this._lobby.peerList(); + cb(null, { roles : peer.roles, peers : peerInfos, tracker : config.fileTracker, authenticated : peer.authenticated, permissionsFromRoles : permissionsFromRoles, - userRoles : userRoles + userRoles : userRoles, + chatHistory : this._chatHistory, + fileHistory : this._fileHistory, + lastNHistory : this._lastN, + locked : this._locked, + lobbyPeers : lobbyPeers, + accessCode : this._accessCode }); // Mark the new Peer as joined. @@ -1078,26 +1086,6 @@ class Room extends EventEmitter break; } - case 'serverHistory': - { - // Return to sender - const lobbyPeers = this._lobby.peerList(); - - cb( - null, - { - chatHistory : this._chatHistory, - fileHistory : this._fileHistory, - lastNHistory : this._lastN, - locked : this._locked, - lobbyPeers : lobbyPeers, - accessCode : this._accessCode - } - ); - - break; - } - case 'lockRoom': { if (