Initial work for file sharing using WebTorrent

This commit is contained in:
Torjus
2018-07-26 15:29:52 +02:00
parent 4f8c896a43
commit 7efaf092c8
9 changed files with 1306 additions and 107 deletions
+12 -2
View File
@@ -1,6 +1,7 @@
import
{
createNewMessage
createNewMessage,
createNewFile
} from './helper';
const chatmessages = (state = [], action) =>
@@ -11,7 +12,16 @@ const chatmessages = (state = [], action) =>
{
const { text } = action.payload;
const message = createNewMessage(text, 'client', 'Me');
const message = createNewMessage(text, 'client', 'Me', undefined);
return [ ...state, message ];
}
case 'ADD_NEW_USER_FILE':
{
const { file } = action.payload;
const message = createNewFile(file, 'client', 'Me', undefined);
return [ ...state, message ];
}
+12
View File
@@ -8,4 +8,16 @@ export function createNewMessage(text, sender, name, picture)
sender,
picture
};
}
export function createNewFile(file, sender, name, picture)
{
return {
type: 'file',
file,
time: Date.now(),
name,
sender,
picture
};
}
+12 -1
View File
@@ -2,7 +2,8 @@ import randomString from 'random-string';
import * as stateActions from './stateActions';
import
{
createNewMessage
createNewMessage,
createNewFile
} from './reducers/helper';
export const joinRoom = (
@@ -213,6 +214,16 @@ export const sendChatMessage = (text, name, picture) =>
};
};
export const sendChatFile = (magnet, name, picture) =>
{
const message = createNewFile(magnet, 'response', name, picture);
return {
type: 'SEND_CHAT_MESSAGE',
payload: { message }
};
};
// This returns a redux-thunk action (a function).
export const notify = ({ type = 'info', text, timeout }) =>
{
+8
View File
@@ -410,6 +410,14 @@ export const addUserMessage = (text) =>
};
};
export const addUserFile = (file) =>
{
return {
type: 'ADD_NEW_USER_FILE',
payload: { file }
};
};
export const addResponseMessage = (message) =>
{
return {