diff --git a/public/scripts/network.js b/public/scripts/network.js index 456fbe4..0046231 100644 --- a/public/scripts/network.js +++ b/public/scripts/network.js @@ -359,6 +359,9 @@ class Peer { this._totalBytesReceived = 0; this._digester = null; this._filesReceived = []; + + // disable NoSleep if idle + Events.fire('evaluate-no-sleep'); } _refresh() {} @@ -1484,6 +1487,8 @@ class PeersManager { Events.on('ws-disconnected', _ => this._onWsDisconnected()); Events.on('ws-relay', e => this._onWsRelay(e.detail.peerId, e.detail.message)); Events.on('ws-config', e => this._onWsConfig(e.detail)); + + Events.on('evaluate-no-sleep', _ => this._onEvaluateNoSleep()); } _onWsConfig(wsConfig) { @@ -1495,6 +1500,15 @@ class PeersManager { 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) { const peer = this.peers[peerId]; const roomTypesDiffer = Object.keys(peer._roomIds)[0] !== roomType; diff --git a/public/scripts/ui.js b/public/scripts/ui.js index 2d6180f..0ef241c 100644 --- a/public/scripts/ui.js +++ b/public/scripts/ui.js @@ -791,7 +791,6 @@ class PeerUI { this.$el.removeAttribute('status'); this.$el.querySelector('.status').innerHTML = ''; this._currentStatus = null; - NoSleepUI.disableIfIdle(); return; } @@ -2968,9 +2967,7 @@ class NoSleepUI { NoSleepUI._active = true; } - static disableIfIdle() { - if ($$('x-peer[status]')) return; - + static disable() { NoSleepUI._nosleep.disable(); NoSleepUI._active = false; }