diff --git a/session.inc.php b/session.inc.php index 94f0fc9..18509d7 100644 --- a/session.inc.php +++ b/session.inc.php @@ -51,6 +51,7 @@ class SessionConfig class Session { const RUN_SLEEP = 3; + const IGNORE_DEVICE_TTL = 300; public string $name; public SessionConfig $conf; @@ -111,18 +112,30 @@ class Session function getDevices() : array { - $devices = array_diff( - $this->device_pool->get(), - $this->ignored_devices - ); - return $devices; + $this->_checkIgnoredDevices(); + + $connected_devices = $this->device_pool->get(); + $actual_devices = array_diff($connected_devices, array_keys($this->ignored_devices)); + + return $actual_devices; + } + + function _checkIgnoredDevices() + { + //let's remove from ignored devices devices which were ignored for some time + $devices = array_keys($this->ignored_devices); + foreach($devices as $device) + { + if(time() - $this->ignored_devices[$device] > self::IGNORE_DEVICE_TTL) + unset($this->ignored_devices[$device]); + } } function ignoreDevice(string $device, string $reason) { err("Ignoring device *$device*: $reason"); - $this->ignored_devices[] = $device; + $this->ignored_devices[$device] = time(); } function incBogusDevice(string $device)