mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
NoSleep: Move evaluation if any peer is still busy to the PeerManager
This commit is contained in:
parent
74bd7dd406
commit
0d17ada58b
2 changed files with 15 additions and 4 deletions
|
@ -359,6 +359,9 @@ class Peer {
|
||||||
this._totalBytesReceived = 0;
|
this._totalBytesReceived = 0;
|
||||||
this._digester = null;
|
this._digester = null;
|
||||||
this._filesReceived = [];
|
this._filesReceived = [];
|
||||||
|
|
||||||
|
// disable NoSleep if idle
|
||||||
|
Events.fire('evaluate-no-sleep');
|
||||||
}
|
}
|
||||||
|
|
||||||
_refresh() {}
|
_refresh() {}
|
||||||
|
@ -1484,6 +1487,8 @@ class PeersManager {
|
||||||
Events.on('ws-disconnected', _ => this._onWsDisconnected());
|
Events.on('ws-disconnected', _ => this._onWsDisconnected());
|
||||||
Events.on('ws-relay', e => this._onWsRelay(e.detail.peerId, e.detail.message));
|
Events.on('ws-relay', e => this._onWsRelay(e.detail.peerId, e.detail.message));
|
||||||
Events.on('ws-config', e => this._onWsConfig(e.detail));
|
Events.on('ws-config', e => this._onWsConfig(e.detail));
|
||||||
|
|
||||||
|
Events.on('evaluate-no-sleep', _ => this._onEvaluateNoSleep());
|
||||||
}
|
}
|
||||||
|
|
||||||
_onWsConfig(wsConfig) {
|
_onWsConfig(wsConfig) {
|
||||||
|
@ -1495,6 +1500,15 @@ class PeersManager {
|
||||||
this.peers[peerId]._onServerSignalMessage(message);
|
this.peers[peerId]._onServerSignalMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onEvaluateNoSleep() {
|
||||||
|
// Evaluate if NoSleep should be disabled
|
||||||
|
for (let i = 0; i < this.peers.length; i++) {
|
||||||
|
if (this.peers[i]._busy) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NoSleepUI.disable();
|
||||||
|
}
|
||||||
|
|
||||||
_refreshPeer(isCaller, peerId, roomType, roomId) {
|
_refreshPeer(isCaller, peerId, roomType, roomId) {
|
||||||
const peer = this.peers[peerId];
|
const peer = this.peers[peerId];
|
||||||
const roomTypesDiffer = Object.keys(peer._roomIds)[0] !== roomType;
|
const roomTypesDiffer = Object.keys(peer._roomIds)[0] !== roomType;
|
||||||
|
|
|
@ -791,7 +791,6 @@ class PeerUI {
|
||||||
this.$el.removeAttribute('status');
|
this.$el.removeAttribute('status');
|
||||||
this.$el.querySelector('.status').innerHTML = '';
|
this.$el.querySelector('.status').innerHTML = '';
|
||||||
this._currentStatus = null;
|
this._currentStatus = null;
|
||||||
NoSleepUI.disableIfIdle();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2968,9 +2967,7 @@ class NoSleepUI {
|
||||||
NoSleepUI._active = true;
|
NoSleepUI._active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static disableIfIdle() {
|
static disable() {
|
||||||
if ($$('x-peer[status]')) return;
|
|
||||||
|
|
||||||
NoSleepUI._nosleep.disable();
|
NoSleepUI._nosleep.disable();
|
||||||
NoSleepUI._active = false;
|
NoSleepUI._active = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue