diff --git a/src/components/pages/NodeFilesPage.vue b/src/components/pages/NodeFilesPage.vue index 53e5c54..e3bb3ec 100644 --- a/src/components/pages/NodeFilesPage.vue +++ b/src/components/pages/NodeFilesPage.vue @@ -108,7 +108,7 @@ -
+
diff --git a/src/js/Connection.js b/src/js/Connection.js index 8e1b5ee..245d663 100644 --- a/src/js/Connection.js +++ b/src/js/Connection.js @@ -526,7 +526,7 @@ class Connection { filename: fileTransferOffer.fileName, filesize: fileTransferOffer.fileSize, progress: 0, - chunks: {}, + data: new Uint8Array(0), }; GlobalState.fileTransfers.push(fileTransfer); @@ -634,12 +634,17 @@ class Connection { return; } + // do nothing if file transfer completed, cancelled or rejected + if(fileTransfer.status === FileTransferrer.STATUS_COMPLETED || fileTransfer.status === FileTransferrer.STATUS_CANCELLED || fileTransfer.status === FileTransferrer.STATUS_REJECTED){ + console.log(`[FileTransfer] ${fileTransfer.id} cancelled, but already in completed state`); + return; + } + console.log(`[FileTransfer] ${fileTransfer.id} requested FileChunk[offset=${requestFileChunk.offset}, length=${requestFileChunk.length}]`); // update file transfer progress - const filePointer = requestFileChunk.offset + requestFileChunk.length; fileTransfer.status = FileTransferrer.STATUS_SENDING; - fileTransfer.progress = Math.min(100, Math.ceil(filePointer / fileTransfer.filesize * 100)); + fileTransfer.progress = Math.min(100, Math.ceil(requestFileChunk.offset + requestFileChunk.length / fileTransfer.filesize * 100)); // send file part await FileTransferrer.sendFileChunk(fileTransfer, requestFileChunk.offset, requestFileChunk.length); diff --git a/src/js/FileTransferrer.js b/src/js/FileTransferrer.js index 71fe40f..6cc90f1 100644 --- a/src/js/FileTransferrer.js +++ b/src/js/FileTransferrer.js @@ -9,7 +9,6 @@ class FileTransferrer { static DIRECTION_OUTGOING = "outgoing"; static STATUS_OFFERING = "offering"; - static STATUS_ACCEPTED = "accepted"; static STATUS_REJECTED = "rejected"; static STATUS_CANCELLED = "cancelled"; static STATUS_COMPLETED = "completed"; @@ -69,7 +68,7 @@ class FileTransferrer { static async acceptFileTransfer(fileTransfer) { // create buffer for file data - fileTransfer.status = this.STATUS_ACCEPTED; + fileTransfer.status = this.STATUS_RECEIVING; fileTransfer.data = new Uint8Array(0); // loop until all bytes received @@ -106,9 +105,7 @@ class FileTransferrer { } // update file transfer progress - const filePointer = fileChunk.offset + fileChunk.length; - fileTransfer.status = FileTransferrer.STATUS_RECEIVING; - fileTransfer.progress = Math.min(100, Math.ceil(filePointer / fileTransfer.filesize * 100)); + fileTransfer.progress = Math.min(100, Math.ceil(fileChunk.offset + fileChunk.length / fileTransfer.filesize * 100)); } catch(e) { this.log("failed to get file chunk", e); @@ -129,7 +126,7 @@ class FileTransferrer { try { this.log(`rejectFileTransfer attempt ${attempt}`); await FileTransferAPI.rejectFileTransfer(fileTransfer.from, fileTransfer.id); - fileTransfer.status = this.STATUS_ACCEPTED; + fileTransfer.status = this.STATUS_REJECTED; return; } catch(e) { console.log(e);