diff --git a/client/scripts/network.js b/client/scripts/network.js index ed992ed..6d951aa 100644 --- a/client/scripts/network.js +++ b/client/scripts/network.js @@ -167,8 +167,11 @@ class Peer { case 'progress': this._onDownloadProgress(message.progress); break; - case 'transfer-complete': - this._onTransferCompleted(); + case 'file-transfer-complete': + this._onFileTransferCompleted(); + break; + case 'message-transfer-complete': + this._onMessageTransferCompleted(); break; case 'text': this._onTextReceived(message); @@ -204,10 +207,10 @@ class Peer { _onFileReceived(proxyFile) { Events.fire('file-received', proxyFile); - this.sendJSON({ type: 'transfer-complete' }); + this.sendJSON({ type: 'file-transfer-complete' }); } - _onTransferCompleted() { + _onFileTransferCompleted() { this._onDownloadProgress(1); this._reader = null; this._busy = false; @@ -215,6 +218,10 @@ class Peer { Events.fire('notify-user', 'File transfer completed.'); } + _onMessageTransferCompleted() { + Events.fire('notify-user', 'Message transfer completed.'); + } + sendText(text) { const unescaped = btoa(unescape(encodeURIComponent(text))); this.sendJSON({ type: 'text', text: unescaped }); @@ -223,6 +230,7 @@ class Peer { _onTextReceived(message) { const escaped = decodeURIComponent(escape(atob(message.text))); Events.fire('text-received', { text: escaped, sender: this._peerId }); + this.sendJSON({ type: 'message-transfer-complete' }); } }