This commit is contained in:
RobinLinus 2018-09-22 08:47:40 +02:00
parent 891859680a
commit c04cdad7db

View file

@ -2,8 +2,8 @@ class ServerConnection {
constructor() { constructor() {
this._connect(); this._connect();
Events.on('beforeunload', e => this._disconnect(), false); Events.on('beforeunload', e => this._disconnect());
Events.on('pagehide', e => this._disconnect(), false); Events.on('pagehide', e => this._disconnect());
document.addEventListener('visibilitychange', e => this._onVisibilityChange()); document.addEventListener('visibilitychange', e => this._onVisibilityChange());
} }
@ -60,6 +60,7 @@ class ServerConnection {
_disconnect() { _disconnect() {
this.send({ type: 'disconnect' }); this.send({ type: 'disconnect' });
this._socket.onclose = null;
this._socket.close(); this._socket.close();
} }
@ -130,7 +131,7 @@ class Peer {
} }
_onReceivedPartitionEnd(offset) { _onReceivedPartitionEnd(offset) {
this.sendJSON({ type: 'partition_received', offset: offset }); this.sendJSON({ type: 'partition-received', offset: offset });
} }
_sendNextPartition() { _sendNextPartition() {
@ -156,7 +157,7 @@ class Peer {
case 'partition': case 'partition':
this._onReceivedPartitionEnd(message); this._onReceivedPartitionEnd(message);
break; break;
case 'partition_received': case 'partition-received':
this._sendNextPartition(); this._sendNextPartition();
break; break;
case 'progress': case 'progress':
@ -448,7 +449,7 @@ class FileChunker {
} }
class FileDigester { class FileDigester {
constructor(meta, callback) { constructor(meta, callback) {
this._buffer = []; this._buffer = [];
this._bytesReceived = 0; this._bytesReceived = 0;
@ -464,8 +465,8 @@ class FileDigester {
const totalChunks = this._buffer.length; const totalChunks = this._buffer.length;
this.progress = this._bytesReceived / this._size; this.progress = this._bytesReceived / this._size;
if (this._bytesReceived < this._size) return; if (this._bytesReceived < this._size) return;
// we are done
let received = new Blob(this._buffer, { type: this._mime }); // pass a useful mime type here let received = new Blob(this._buffer, { type: this._mime });
let url = URL.createObjectURL(received); let url = URL.createObjectURL(received);
this._callback({ this._callback({
name: this._name, name: this._name,
@ -473,7 +474,6 @@ class FileDigester {
size: this._size, size: this._size,
url: url url: url
}); });
this._callback = null;
} }
} }