multiparty-meeting/app/lib/components/Chat/FileSharing.jsx

51 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

import React, { Component } from 'react';
import { connect } from 'react-redux';
import WebTorrent from 'webtorrent';
import dragDrop from 'drag-drop';
import * as stateActions from '../../redux/stateActions';
import * as requestActions from '../../redux/requestActions';
import { store } from '../../store';
export const client = new WebTorrent();
const notifyPeers = (file) =>
{
const { displayName, picture } = store.getState().me;
store.dispatch(stateActions.addUserFile(file));
store.dispatch(requestActions.sendChatFile(file, displayName, picture));
};
const shareFiles = (files) =>
{
client.seed(files, (torrent) => {
notifyPeers({
magnet: torrent.magnetURI
});
});
};
dragDrop('body', shareFiles);
class FileSharing extends Component {
constructor(props)
{
super(props);
}
handleFileChange = (event) =>
{
if (event.target.files.length > 0)
{
shareFiles(event.target.files);
}
};
render()
{
return (
<input type="file" onChange={this.handleFileChange} />
);
}
}
export default FileSharing;