Handle it correctly if a user tries to share a file that has allready been shared. Closes #142

This commit is contained in:
Håvar Aambø Fosstveit
2020-03-31 20:32:36 +02:00
committed by Mészáros Mihály
parent 7ffea7b954
commit 12dc5ea28b
2 changed files with 71 additions and 15 deletions
+68 -13
View File
@@ -14,6 +14,8 @@ import * as consumerActions from './actions/consumerActions';
import * as producerActions from './actions/producerActions';
import * as notificationActions from './actions/notificationActions';
let createTorrent;
let WebTorrent;
let saveAs;
@@ -704,26 +706,48 @@ export default class RoomClient
})
}));
this._webTorrent.seed(
files,
{ announceList: [['wss://tracker.lab.vvc.niif.hu:443']] },
(torrent) =>
createTorrent(files, (err, torrent) =>
{
if (err)
{
store.dispatch(requestActions.notify(
return store.dispatch(requestActions.notify(
{
type : 'error',
text : intl.formatMessage({
id : 'filesharing.successfulFileShare',
defaultMessage : 'File successfully shared'
id : 'filesharing.unableToShare',
defaultMessage : 'Unable to share file'
})
}));
}
store.dispatch(fileActions.addFile(
this._peerId,
torrent.magnetURI
));
const existingTorrent = this._webTorrent.get(torrent);
this._sendFile(torrent.magnetURI);
});
if (existingTorrent)
{
return this._sendFile(existingTorrent.magnetURI);
}
this._webTorrent.seed(
files,
{ announceList: [ [ 'wss://tracker.lab.vvc.niif.hu:443' ] ] },
(newTorrent) =>
{
store.dispatch(requestActions.notify(
{
text : intl.formatMessage({
id : 'filesharing.successfulFileShare',
defaultMessage : 'File successfully shared'
})
}));
store.dispatch(fileActions.addFile(
this._peerId,
newTorrent.magnetURI
));
this._sendFile(newTorrent.magnetURI);
});
});
}
// { file, name, picture }
@@ -1344,6 +1368,13 @@ export default class RoomClient
async _loadDynamicImports()
{
({ default: createTorrent } = await import(
/* webpackPrefetch: true */
/* webpackChunkName: "createtorrent" */
'create-torrent'
));
({ default: WebTorrent } = await import(
/* webpackPrefetch: true */
@@ -2066,6 +2097,30 @@ export default class RoomClient
try
{
this._torrentSupport = WebTorrent.WEBRTC_SUPPORT;
this._webTorrent = this._torrentSupport && new WebTorrent({
tracker : {
rtcConfig : {
iceServers : this._turnServers
}
}
});
this._webTorrent.on('error', (error) =>
{
logger.error('Filesharing [error:"%o"]', error);
store.dispatch(requestActions.notify(
{
type : 'error',
text : intl.formatMessage({
id : 'filesharing.error',
defaultMessage : 'There was a filesharing error'
})
}));
});
this._mediasoupDevice = new mediasoupClient.Device();
const routerRtpCapabilities =