. */ namespace App\Libraries; use Illuminate\Support\Facades\Log; class FlexisipPusherConnector { private ?string $pusherPath = null; private ?string $pnProvider = null; private ?string $pnParam = null; private ?string $pnPrid = null; private ?string $pusherFirebaseKey = null; public function __construct(string $pnProvider, string $pnParam, string $pnPrid) { $this->pusherPath = config('app.flexisip_pusher_path'); $this->pnProvider = $pnProvider; $this->pnParam = $pnParam; $this->pnPrid = $pnPrid; if ($this->pnProvider == 'fcm' && config('app.flexisip_pusher_firebase_keysmap') == null) { Log::error('Firebase pusher keysmap not configured'); } $firebaseKeysmap = explode(' ', config('app.flexisip_pusher_firebase_keysmap')); if (count($firebaseKeysmap) > 0) { $pusherFirebaseKeysmap = []; foreach ($firebaseKeysmap as $map) { if (str_contains($map, ':')) { list($id, $value) = explode(':', $map); $pusherFirebaseKeysmap[$id] = $value; } } if (array_key_exists($pnParam, $pusherFirebaseKeysmap)) { $this->pusherFirebaseKey = $pusherFirebaseKeysmap[$pnParam]; } } } public function sendToken(string $token) { $payload = json_encode(['token' => $token]); if (!empty($this->pusherPath)) { $command = $this->pusherPath . " --pn-provider '" . $this->pnProvider . "'" . " --pn-param '" . $this->pnParam . "'" . " --pn-prid " . $this->pnPrid . " --customPayload '" . $payload . "'"; if (in_array($this->pnProvider, ['apns', 'apns.dev'])) { $command .= " --apple-push-type Background"; } if ($this->pusherFirebaseKey) { $command .= " --key " . $this->pusherFirebaseKey; } $output = null; $retval = null; return exec($command, $output, $retval); } Log::error('Pusher path not configured'); } }