From 35b3da155d7a3985e841f965d734e0fd86a1d1d2 Mon Sep 17 00:00:00 2001 From: Torjus Date: Tue, 31 Jul 2018 09:56:29 +0200 Subject: [PATCH] Store file upload history on server --- app/lib/RoomClient.js | 35 ++++++++++++++++++++++++++++++- app/lib/redux/reducers/sharing.js | 3 +++ app/lib/redux/stateActions.js | 8 +++++++ server/lib/Room.js | 15 +++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/lib/RoomClient.js b/app/lib/RoomClient.js index 5ae52af..6302710 100644 --- a/app/lib/RoomClient.js +++ b/app/lib/RoomClient.js @@ -238,6 +238,22 @@ export default class RoomClient }); } + getFileHistory() + { + logger.debug('getFileHistory()'); + + return this._protoo.send('file-history', {}) + .catch((error) => + { + logger.error('getFileHistory() | failed: %o', error); + + this._dispatch(requestActions.notify({ + type: 'error', + text: 'Could not get file history' + })); + }) + } + muteMic() { logger.debug('muteMic()'); @@ -1177,6 +1193,22 @@ export default class RoomClient break; } + case 'file-history-receive': + { + accept(); + + const files = request.data.fileHistory; + + if (files.length > 0) + { + logger.debug('Got files history'); + + this._dispatch(stateActions.addFileHistory(files)); + } + + break; + } + default: { logger.error('unknown protoo method "%s"', request.method); @@ -1314,7 +1346,8 @@ export default class RoomClient this._dispatch(stateActions.removeAllNotifications()); this.getChatHistory(); - + this.getFileHistory(); + this._dispatch(requestActions.notify( { text : 'You are in the room', diff --git a/app/lib/redux/reducers/sharing.js b/app/lib/redux/reducers/sharing.js index 270844f..299a155 100644 --- a/app/lib/redux/reducers/sharing.js +++ b/app/lib/redux/reducers/sharing.js @@ -8,6 +8,9 @@ const sharing = (state = [], action) => case 'ADD_FILE': return [ ...state, action.payload ]; + case 'ADD_FILE_HISTORY': + return [ ...action.payload.fileHistory, ...state ]; + default: return state; } diff --git a/app/lib/redux/stateActions.js b/app/lib/redux/stateActions.js index a83e25c..6843ed8 100644 --- a/app/lib/redux/stateActions.js +++ b/app/lib/redux/stateActions.js @@ -449,6 +449,14 @@ export const addFile = (payload) => }; }; +export const addFileHistory = (fileHistory) => +{ + return { + type: 'ADD_FILE_HISTORY', + payload: { fileHistory } + }; +}; + export const setPicture = (picture) => ({ type : 'SET_PICTURE', diff --git a/server/lib/Room.js b/server/lib/Room.js index 6d0b79c..5cf87f0 100644 --- a/server/lib/Room.js +++ b/server/lib/Room.js @@ -28,6 +28,8 @@ class Room extends EventEmitter this._chatHistory = []; + this._fileHistory = []; + try { // Protoo Room instance. @@ -278,6 +280,8 @@ class Room extends EventEmitter const { file } = request.data; + this._fileHistory.push(file); + this._protooRoom.spread('file-receive', { file }, [ protooPeer ]); @@ -285,6 +289,17 @@ class Room extends EventEmitter break; } + case 'file-history': + { + accept(); + + protooPeer.send('file-history-receive', { + fileHistory: this._fileHistory + }); + + break; + } + case 'raisehand-message': { accept();