mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-21 15:26:17 -04:00
Add STATE_TRANSFER_REQUEST_RECEIVED and close transfer request dialog if requesting peer reloads
This commit is contained in:
parent
0d17ada58b
commit
3c8848d406
2 changed files with 55 additions and 11 deletions
|
@ -321,6 +321,7 @@ class Peer {
|
||||||
static STATE_IDLE = 'idle';
|
static STATE_IDLE = 'idle';
|
||||||
static STATE_PREPARE = 'prepare';
|
static STATE_PREPARE = 'prepare';
|
||||||
static STATE_TRANSFER_REQUEST_SENT = 'transfer-request-sent';
|
static STATE_TRANSFER_REQUEST_SENT = 'transfer-request-sent';
|
||||||
|
static STATE_TRANSFER_REQUEST_RECEIVED = 'transfer-request-received';
|
||||||
static STATE_RECEIVE_PROCEEDING = 'receive-proceeding';
|
static STATE_RECEIVE_PROCEEDING = 'receive-proceeding';
|
||||||
static STATE_TRANSFER_PROCEEDING = 'transfer-proceeding';
|
static STATE_TRANSFER_PROCEEDING = 'transfer-proceeding';
|
||||||
static STATE_TEXT_SENT = 'text-sent';
|
static STATE_TEXT_SENT = 'text-sent';
|
||||||
|
@ -493,7 +494,7 @@ class Peer {
|
||||||
this._onDisplayNameChanged(message);
|
this._onDisplayNameChanged(message);
|
||||||
break;
|
break;
|
||||||
case 'state':
|
case 'state':
|
||||||
this._onState(message.state);
|
await this._onState(message.state);
|
||||||
break;
|
break;
|
||||||
case 'transfer-request':
|
case 'transfer-request':
|
||||||
await this._onTransferRequest(message);
|
await this._onTransferRequest(message);
|
||||||
|
@ -556,23 +557,29 @@ class Peer {
|
||||||
this._sendMessage({type: 'state', state: this._state})
|
this._sendMessage({type: 'state', state: this._state})
|
||||||
}
|
}
|
||||||
|
|
||||||
_onState(peerState) {
|
async _onState(peerState) {
|
||||||
if (this._state === Peer.STATE_RECEIVE_PROCEEDING) {
|
if (this._state === Peer.STATE_TRANSFER_PROCEEDING) {
|
||||||
this._onStateReceiver(peerState);
|
this._onStateIfSender(peerState);
|
||||||
}
|
}
|
||||||
else if (this._state === Peer.STATE_TRANSFER_PROCEEDING) {
|
else if (this._state === Peer.STATE_RECEIVE_PROCEEDING) {
|
||||||
this._onStateSender(peerState);
|
this._onStateIfReceiver(peerState);
|
||||||
|
}
|
||||||
|
else if (this._state === Peer.STATE_TRANSFER_REQUEST_SENT) {
|
||||||
|
await this._onStateIfTransferRequestSent(peerState);
|
||||||
|
}
|
||||||
|
else if (this._state === Peer.STATE_TRANSFER_REQUEST_RECEIVED) {
|
||||||
|
this._onStateIfTransferRequestReceived(peerState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onStateSender(peerState) {
|
_onStateIfSender(peerState) {
|
||||||
// this peer is sender
|
// this peer is sender
|
||||||
if (peerState !== Peer.STATE_RECEIVE_PROCEEDING) {
|
if (peerState !== Peer.STATE_RECEIVE_PROCEEDING) {
|
||||||
this._abortTransfer();
|
this._abortTransfer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onStateReceiver(peerState) {
|
_onStateIfReceiver(peerState) {
|
||||||
// this peer is receiver
|
// this peer is receiver
|
||||||
switch (peerState) {
|
switch (peerState) {
|
||||||
case Peer.STATE_TRANSFER_REQUEST_SENT:
|
case Peer.STATE_TRANSFER_REQUEST_SENT:
|
||||||
|
@ -592,6 +599,25 @@ class Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _onStateIfTransferRequestSent(peerState) {
|
||||||
|
// This peer has sent a transfer request
|
||||||
|
// If other peer is still idle -> send request again
|
||||||
|
if (peerState === Peer.STATE_IDLE) {
|
||||||
|
await this._sendFileTransferRequest(this._filesRequested);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onStateIfTransferRequestReceived(peerState) {
|
||||||
|
// This peer has received a transfer request
|
||||||
|
// If other peer is not in "STATE_TRANSFER_REQUEST_SENT" anymore -> reset and hide request from user
|
||||||
|
if (peerState !== Peer.STATE_TRANSFER_REQUEST_SENT) {
|
||||||
|
this._reset();
|
||||||
|
Events.fire('files-transfer-request-abort', {
|
||||||
|
peerId: this._peerId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_abortTransfer() {
|
_abortTransfer() {
|
||||||
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'error'});
|
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'error'});
|
||||||
this._reset();
|
this._reset();
|
||||||
|
@ -625,7 +651,8 @@ class Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Events.fire('set-progress', {peerId: this._peerId, progress: 1, status: 'prepare'})
|
this._state = Peer.STATE_TRANSFER_REQUEST_SENT;
|
||||||
|
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'wait'});
|
||||||
|
|
||||||
this._filesRequested = files;
|
this._filesRequested = files;
|
||||||
|
|
||||||
|
@ -636,8 +663,6 @@ class Peer {
|
||||||
thumbnailDataUrl: dataUrl
|
thumbnailDataUrl: dataUrl
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'wait'})
|
|
||||||
this._state = Peer.STATE_TRANSFER_REQUEST_SENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTransferRequestResponse(message) {
|
_onTransferRequestResponse(message) {
|
||||||
|
@ -764,6 +789,7 @@ class Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._state = Peer.STATE_TRANSFER_REQUEST_RECEIVED;
|
||||||
this._pendingRequest = request;
|
this._pendingRequest = request;
|
||||||
|
|
||||||
// Automatically accept request if auto-accept is set to true via the Edit Paired Devices Dialog
|
// Automatically accept request if auto-accept is set to true via the Edit Paired Devices Dialog
|
||||||
|
|
|
@ -1444,6 +1444,7 @@ class ReceiveRequestDialog extends ReceiveDialog {
|
||||||
this._currentRequest = null;
|
this._currentRequest = null;
|
||||||
|
|
||||||
Events.on('files-transfer-request', e => this._onRequestFileTransfer(e.detail.request, e.detail.peerId))
|
Events.on('files-transfer-request', e => this._onRequestFileTransfer(e.detail.request, e.detail.peerId))
|
||||||
|
Events.on('files-transfer-request-abort', e => this._onRequestFileTransferAbort(e.detail.peerId));
|
||||||
Events.on('keydown', e => this._onKeyDown(e));
|
Events.on('keydown', e => this._onKeyDown(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1461,6 +1462,22 @@ class ReceiveRequestDialog extends ReceiveDialog {
|
||||||
this._dequeueRequests();
|
this._dequeueRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onRequestFileTransferAbort(peerId) {
|
||||||
|
// Remove file transfer request from this peer from queue
|
||||||
|
for (let i = 0; i < this._filesTransferRequestQueue.length; i++) {
|
||||||
|
if (this._filesTransferRequestQueue[i].peerId === peerId) {
|
||||||
|
this._filesTransferRequestQueue.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hide dialog if the currently open transfer request is from this peer
|
||||||
|
if (this.isShown() && this.correspondingPeerId === peerId) {
|
||||||
|
this.hide();
|
||||||
|
Events.fire('notify-user', Localization.getTranslation("notifications.selected-peer-left"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_dequeueRequests() {
|
_dequeueRequests() {
|
||||||
if (!this._filesTransferRequestQueue.length) {
|
if (!this._filesTransferRequestQueue.length) {
|
||||||
this._currentRequest = null;
|
this._currentRequest = null;
|
||||||
|
@ -2724,6 +2741,7 @@ class Notifications {
|
||||||
Events.on('text-received', e => this._messageNotification(e.detail.text, e.detail.peerId));
|
Events.on('text-received', e => this._messageNotification(e.detail.text, e.detail.peerId));
|
||||||
Events.on('files-received', e => this._downloadNotification(e.detail.files, e.detail.imagesOnly));
|
Events.on('files-received', e => this._downloadNotification(e.detail.files, e.detail.imagesOnly));
|
||||||
Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId));
|
Events.on('files-transfer-request', e => this._requestNotification(e.detail.request, e.detail.peerId));
|
||||||
|
// Todo on 'files-transfer-request-abort' remove notification
|
||||||
}
|
}
|
||||||
|
|
||||||
async _requestPermission() {
|
async _requestPermission() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue