feat: patient view, media player, and rich editor enhancements
This commit is contained in:
@@ -36,6 +36,38 @@ public static function fromConfig(): static
|
||||
);
|
||||
}
|
||||
|
||||
public function ping(): array
|
||||
{
|
||||
if (! $this->isConfigured()) {
|
||||
return ['connected' => false, 'path' => null];
|
||||
}
|
||||
|
||||
$ip = escapeshellarg($this->peerIp);
|
||||
$cmd = PHP_OS_FAMILY === 'Windows'
|
||||
? "ping -n 1 -w 1000 {$ip}"
|
||||
: "ping -c 1 -W 1 {$ip}";
|
||||
|
||||
exec($cmd . ' 2>&1', $output, $exitCode);
|
||||
|
||||
if ($exitCode !== 0) {
|
||||
return ['connected' => false, 'path' => null];
|
||||
}
|
||||
|
||||
$path = null;
|
||||
try {
|
||||
$response = Http::timeout(3)
|
||||
->withHeader('X-Sync-Token', $this->token)
|
||||
->get("http://{$this->peerIp}:{$this->peerPort}/api/sync/ping");
|
||||
|
||||
if ($response->successful() && $response->json('status') === 'ok') {
|
||||
$path = $response->json('path');
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
}
|
||||
|
||||
return ['connected' => true, 'path' => $path];
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return $this->peerIp !== '' && $this->token !== '';
|
||||
|
||||
Reference in New Issue
Block a user