Skip to content

Commit

Permalink
Track last ping and package time
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadyita committed Mar 2, 2024
1 parent 4d66b13 commit 156bc09
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Client/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Basic {
/** @var array<string,Group> */
private array $publicGroups = [];

private float $lastPackage = 0;
private float $lastPing = 0;

/**
* True when the bot has finished receiving the initial
* buddylist updates which don't correspond to state changes.
Expand Down Expand Up @@ -63,6 +66,16 @@ public function isReady(): bool {
return $this->isReady;
}

/** Get the UNIX timestamp when the last package was received */
public function getLastPackageReceived(): float {
return $this->lastPackage;
}

/** Get the UNIX timestamp when the last ping package was received */
public function getLastPingReceived(): float {
return $this->lastPing;
}

/**
* Request a callback when the connection is ready to
* process packages and has finished receiving the
Expand Down Expand Up @@ -196,7 +209,11 @@ public function read(): ?Package\In {
$this->logger?->info("Stream has closed the connection");
return null;
}
$this->lastPackage = microtime(true);
$package = $this->parser->parseBinaryPackage($binPackage);
if ($package instanceof Package\In\Ping) {
$this->lastPing = microtime(true);
}
$this->handleIncomingPackage($package);
return $package;
}
Expand Down

0 comments on commit 156bc09

Please sign in to comment.