Rewritten filesharing to move responsability of filesharing to RoomClient. Removed and rewrote some code to clean up.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
const files = (state = {}, action) =>
|
||||
{
|
||||
switch (action.type)
|
||||
{
|
||||
case 'ADD_FILE':
|
||||
{
|
||||
const { file } = action.payload;
|
||||
|
||||
const newFile = {
|
||||
active : false,
|
||||
progress : 0,
|
||||
files : null,
|
||||
me : false,
|
||||
...file
|
||||
};
|
||||
|
||||
return { ...state, [file.magnetUri]: newFile };
|
||||
}
|
||||
|
||||
case 'ADD_FILE_HISTORY':
|
||||
{
|
||||
const { fileHistory } = action.payload;
|
||||
const newFileHistory = {};
|
||||
|
||||
fileHistory.map((file) =>
|
||||
{
|
||||
const newFile = {
|
||||
active : false,
|
||||
progress : 0,
|
||||
files : null,
|
||||
me : false,
|
||||
...file
|
||||
};
|
||||
|
||||
newFileHistory[file.magnetUri] = newFile;
|
||||
});
|
||||
|
||||
return { ...state, ...newFileHistory };
|
||||
}
|
||||
|
||||
case 'SET_FILE_ACTIVE':
|
||||
{
|
||||
const { magnetUri } = action.payload;
|
||||
const file = state[magnetUri];
|
||||
|
||||
const newFile = { ...file, active: true };
|
||||
|
||||
return { ...state, [magnetUri]: newFile };
|
||||
}
|
||||
|
||||
case 'SET_FILE_INACTIVE':
|
||||
{
|
||||
const { magnetUri } = action.payload;
|
||||
const file = state[magnetUri];
|
||||
|
||||
const newFile = { ...file, active: false };
|
||||
|
||||
return { ...state, [magnetUri]: newFile };
|
||||
}
|
||||
|
||||
case 'SET_FILE_PROGRESS':
|
||||
{
|
||||
const { magnetUri, progress } = action.payload;
|
||||
const file = state[magnetUri];
|
||||
|
||||
const newFile = { ...file, progress: progress };
|
||||
|
||||
return { ...state, [magnetUri]: newFile };
|
||||
}
|
||||
|
||||
case 'SET_FILE_DONE':
|
||||
{
|
||||
const { magnetUri, sharedFiles } = action.payload;
|
||||
const file = state[magnetUri];
|
||||
|
||||
const newFile = {
|
||||
...file,
|
||||
files : sharedFiles,
|
||||
progress : 1,
|
||||
active : false,
|
||||
timeout : false
|
||||
};
|
||||
|
||||
return { ...state, [magnetUri]: newFile };
|
||||
}
|
||||
|
||||
case 'REMOVE_FILE':
|
||||
{
|
||||
const { magnetUri } = action.payload;
|
||||
|
||||
return state.filter((file) => file.magnetUri !== magnetUri);
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default files;
|
||||
@@ -8,7 +8,7 @@ import notifications from './notifications';
|
||||
import chatmessages from './chatmessages';
|
||||
import chatbehavior from './chatbehavior';
|
||||
import toolarea from './toolarea';
|
||||
import sharing from './sharing';
|
||||
import files from './files';
|
||||
|
||||
const reducers = combineReducers(
|
||||
{
|
||||
@@ -21,7 +21,7 @@ const reducers = combineReducers(
|
||||
chatmessages,
|
||||
chatbehavior,
|
||||
toolarea,
|
||||
sharing
|
||||
files
|
||||
});
|
||||
|
||||
export default reducers;
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
const initialState = [];
|
||||
|
||||
const notifications = (state = initialState, action) =>
|
||||
const notifications = (state = [], action) =>
|
||||
{
|
||||
switch (action.type)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ const initialState =
|
||||
url : null,
|
||||
state : 'new', // new/connecting/connected/disconnected/closed,
|
||||
activeSpeakerName : null,
|
||||
torrentSupport : false,
|
||||
showSettings : false,
|
||||
advancedMode : false,
|
||||
fullScreenConsumer : null, // ConsumerID
|
||||
@@ -41,6 +42,13 @@ const room = (state = initialState, action) =>
|
||||
return { ...state, activeSpeakerName: peerName };
|
||||
}
|
||||
|
||||
case 'FILE_SHARING_SUPPORTED':
|
||||
{
|
||||
const { supported } = action.payload;
|
||||
|
||||
return { ...state, torrentSupport: supported };
|
||||
}
|
||||
|
||||
case 'TOGGLE_SETTINGS':
|
||||
{
|
||||
const showSettings = !state.showSettings;
|
||||
|
||||
@@ -70,6 +70,14 @@ export const setWebcamDevices = (devices) =>
|
||||
};
|
||||
};
|
||||
|
||||
export const setFileSharingSupported = (supported) =>
|
||||
{
|
||||
return {
|
||||
type : 'FILE_SHARING_SUPPORTED',
|
||||
payload : { supported }
|
||||
};
|
||||
};
|
||||
|
||||
export const setDisplayName = (displayName) =>
|
||||
{
|
||||
return {
|
||||
@@ -455,11 +463,11 @@ export const dropMessages = () =>
|
||||
};
|
||||
};
|
||||
|
||||
export const addFile = (payload) =>
|
||||
export const addFile = (file) =>
|
||||
{
|
||||
return {
|
||||
type : 'ADD_FILE',
|
||||
payload
|
||||
type : 'ADD_FILE',
|
||||
payload : { file }
|
||||
};
|
||||
};
|
||||
|
||||
@@ -471,6 +479,38 @@ export const addFileHistory = (fileHistory) =>
|
||||
};
|
||||
};
|
||||
|
||||
export const setFileActive = (magnetUri) =>
|
||||
{
|
||||
return {
|
||||
type : 'SET_FILE_ACTIVE',
|
||||
payload : { magnetUri }
|
||||
};
|
||||
};
|
||||
|
||||
export const setFileInActive = (magnetUri) =>
|
||||
{
|
||||
return {
|
||||
type : 'SET_FILE_INACTIVE',
|
||||
payload : { magnetUri }
|
||||
};
|
||||
};
|
||||
|
||||
export const setFileProgress = (magnetUri, progress) =>
|
||||
{
|
||||
return {
|
||||
type : 'SET_FILE_PROGRESS',
|
||||
payload : { magnetUri, progress }
|
||||
};
|
||||
};
|
||||
|
||||
export const setFileDone = (magnetUri, sharedFiles) =>
|
||||
{
|
||||
return {
|
||||
type : 'SET_FILE_DONE',
|
||||
payload : { magnetUri, sharedFiles }
|
||||
};
|
||||
};
|
||||
|
||||
export const setPicture = (picture) =>
|
||||
({
|
||||
type : 'SET_PICTURE',
|
||||
|
||||
Reference in New Issue
Block a user