From 2c6b33c2b8f176d020ded52713be63ffec1535b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 19 Oct 2018 11:28:17 +0200 Subject: [PATCH] Combined some socket request code --- app/lib/RoomClient.js | 46 +++++++++++++------------------------------ server/lib/Room.js | 16 +++++++-------- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/app/lib/RoomClient.js b/app/lib/RoomClient.js index de31b3f..363be30 100644 --- a/app/lib/RoomClient.js +++ b/app/lib/RoomClient.js @@ -271,14 +271,17 @@ export default class RoomClient }); } - getChatHistory() + getServerHistory() { - logger.debug('getChatHistory()'); + logger.debug('getServerHistory()'); - return this.sendRequest('chat-history') + return this.sendRequest('server-history') .then((response) => { - const { chatHistory } = response; + const { + chatHistory, + fileHistory + } = response; if (chatHistory.length > 0) { @@ -286,27 +289,6 @@ export default class RoomClient this._dispatch( stateActions.addChatHistory(chatHistory)); } - }) - .catch((error) => - { - logger.error('getChatHistory() | failed: %o', error); - - this._dispatch(requestActions.notify( - { - type : 'error', - text : `Could not get chat history: ${error}` - })); - }); - } - - getFileHistory() - { - logger.debug('getFileHistory()'); - - return this.sendRequest('file-history') - .then((response) => - { - const { fileHistory } = response; if (fileHistory.length > 0) { @@ -317,12 +299,13 @@ export default class RoomClient }) .catch((error) => { - logger.error('getFileHistory() | failed: %o', error); + logger.error('getServerHistory() | failed: %o', error); - this._dispatch(requestActions.notify({ - type : 'error', - text : 'Could not get file history' - })); + this._dispatch(requestActions.notify( + { + type : 'error', + text : `Could not get chat history: ${error}` + })); }); } @@ -1329,8 +1312,7 @@ export default class RoomClient // Clean all the existing notifcations. this._dispatch(stateActions.removeAllNotifications()); - this.getChatHistory(); - this.getFileHistory(); + this.getServerHistory(); this._dispatch(requestActions.notify( { diff --git a/server/lib/Room.js b/server/lib/Room.js index 99537fa..147df3f 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -263,10 +263,16 @@ class Room extends EventEmitter ); }); - signalingPeer.socket.on('chat-history', (request, cb) => + signalingPeer.socket.on('server-history', (request, cb) => { // Return to sender - cb(null, { chatHistory: this._chatHistory }); + cb( + null, + { + chatHistory : this._chatHistory, + fileHistory : this._fileHistory + } + ); }); signalingPeer.socket.on('send-file', (request, cb) => @@ -292,12 +298,6 @@ class Room extends EventEmitter ); }); - signalingPeer.socket.on('file-history', (request, cb) => - { - // Return to sender - cb(null, { fileHistory : this._fileHistory }); - }); - signalingPeer.socket.on('raisehand-message', (request, cb) => { // Return no error