Add notification when Blob converting fails
parent
734bb1eb0a
commit
088f3ccc7c
|
|
@ -1,22 +1,9 @@
|
|||
import React, { Component, Fragment } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { notifyAction } from '../../redux/stateActions';
|
||||
import { saveAs } from 'file-saver/FileSaver';
|
||||
import { client } from './FileSharing';
|
||||
|
||||
const saveFile = (file) =>
|
||||
{
|
||||
file.getBlob((err, blob) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
console.error('WebTorrent error');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('TRYING TO SAVE BLOB', blob)
|
||||
saveAs(blob, file.name);
|
||||
});
|
||||
};
|
||||
|
||||
class FileChatEntry extends Component
|
||||
{
|
||||
state = {
|
||||
|
|
@ -26,6 +13,21 @@ class FileChatEntry extends Component
|
|||
files : null
|
||||
};
|
||||
|
||||
saveFile = (file) =>
|
||||
{
|
||||
file.getBlob((err, blob) =>
|
||||
{
|
||||
if (err)
|
||||
{
|
||||
return this.props.notify({
|
||||
text : 'An error occurred while saving a file'
|
||||
});
|
||||
}
|
||||
|
||||
saveAs(blob, file.name);
|
||||
});
|
||||
};
|
||||
|
||||
download = () =>
|
||||
{
|
||||
this.setState({
|
||||
|
|
@ -45,7 +47,8 @@ class FileChatEntry extends Component
|
|||
setInterval(onProgress, 500);
|
||||
onProgress();
|
||||
|
||||
torrent.on('done', () => {
|
||||
torrent.on('done', () =>
|
||||
{
|
||||
onProgress();
|
||||
clearInterval(onProgress);
|
||||
|
||||
|
|
@ -76,7 +79,9 @@ class FileChatEntry extends Component
|
|||
<div>
|
||||
{this.state.files.map((file, i) => (
|
||||
<div key={i}>
|
||||
<button onClick={() => saveFile(file)}>download {file.name}</button>
|
||||
<button onClick={() => this.saveFile(file)}>
|
||||
download {file.name}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -87,4 +92,11 @@ class FileChatEntry extends Component
|
|||
}
|
||||
}
|
||||
|
||||
export default FileChatEntry;
|
||||
const mapDispatchToProps = {
|
||||
notify : notifyAction
|
||||
};
|
||||
|
||||
export default connect(
|
||||
undefined,
|
||||
mapDispatchToProps
|
||||
)(FileChatEntry);
|
||||
|
|
@ -1,23 +1,24 @@
|
|||
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';
|
||||
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) => {
|
||||
client.seed(files, (torrent) =>
|
||||
{
|
||||
notifyPeers({
|
||||
magnet : torrent.magnetURI
|
||||
});
|
||||
|
|
@ -26,7 +27,8 @@ const shareFiles = (files) =>
|
|||
|
||||
dragDrop('body', shareFiles);
|
||||
|
||||
class FileSharing extends Component {
|
||||
class FileSharing extends Component
|
||||
{
|
||||
constructor(props)
|
||||
{
|
||||
super(props);
|
||||
|
|
@ -43,7 +45,7 @@ class FileSharing extends Component {
|
|||
render()
|
||||
{
|
||||
return (
|
||||
<input type="file" onChange={this.handleFileChange} />
|
||||
<input type='file' onChange={this.handleFileChange} />
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue