From a7340fa15596c5add6da553c13ba096dad65917e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5var=20Aamb=C3=B8=20Fosstveit?= Date: Fri, 19 Oct 2018 11:11:49 +0200 Subject: [PATCH] Cleaned up some socket request code --- app/lib/RoomClient.js | 50 +++++++++++++++++++++---------------------- server/lib/Room.js | 22 ++++--------------- 2 files changed, 28 insertions(+), 44 deletions(-) diff --git a/app/lib/RoomClient.js b/app/lib/RoomClient.js index 6cdcba7..de31b3f 100644 --- a/app/lib/RoomClient.js +++ b/app/lib/RoomClient.js @@ -275,7 +275,18 @@ export default class RoomClient { logger.debug('getChatHistory()'); - return this.sendRequest('chat-history', {}) + return this.sendRequest('chat-history') + .then((response) => + { + const { chatHistory } = response; + + if (chatHistory.length > 0) + { + logger.debug('Got chat history'); + this._dispatch( + stateActions.addChatHistory(chatHistory)); + } + }) .catch((error) => { logger.error('getChatHistory() | failed: %o', error); @@ -292,7 +303,18 @@ export default class RoomClient { logger.debug('getFileHistory()'); - return this.sendRequest('file-history', {}) + return this.sendRequest('file-history') + .then((response) => + { + const { fileHistory } = response; + + if (fileHistory.length > 0) + { + logger.debug('Got files history'); + + this._dispatch(stateActions.addFileHistory(fileHistory)); + } + }) .catch((error) => { logger.error('getFileHistory() | failed: %o', error); @@ -1169,18 +1191,6 @@ export default class RoomClient stateActions.addResponseMessage({ ...chatMessage, peerName })); }); - this._signalingSocket.on('chat-history-receive', (data) => - { - const { chatHistory } = data; - - if (chatHistory.length > 0) - { - logger.debug('Got chat history'); - this._dispatch( - stateActions.addChatHistory(chatHistory)); - } - }); - this._signalingSocket.on('file-receive', (data) => { const payload = data.file; @@ -1191,18 +1201,6 @@ export default class RoomClient text : `${payload.name} shared a file` })); }); - - this._signalingSocket.on('file-history-receive', (data) => - { - const files = data.fileHistory; - - if (files.length > 0) - { - logger.debug('Got files history'); - - this._dispatch(stateActions.addFileHistory(files)); - } - }); } _joinRoom({ displayName, device }) diff --git a/server/lib/Room.js b/server/lib/Room.js index 663b099..99537fa 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -265,14 +265,8 @@ class Room extends EventEmitter signalingPeer.socket.on('chat-history', (request, cb) => { - // Return no error - cb(null); - - // Return to socket - signalingPeer.socket.emit( - 'chat-history-receive', - { chatHistory: this._chatHistory } - ); + // Return to sender + cb(null, { chatHistory: this._chatHistory }); }); signalingPeer.socket.on('send-file', (request, cb) => @@ -300,16 +294,8 @@ class Room extends EventEmitter signalingPeer.socket.on('file-history', (request, cb) => { - // Return no error - cb(null); - - // Return to socket - signalingPeer.socket.emit( - 'file-history-receive', - { - fileHistory : this._fileHistory - } - ); + // Return to sender + cb(null, { fileHistory : this._fileHistory }); }); signalingPeer.socket.on('raisehand-message', (request, cb) =>