. */ 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 static array $apnsTypes = [ 'background' => 'Background', 'message' => 'RemoteWithMutableContent', 'call' => 'PushKit' ]; 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, ':')) { //We put the explode limit to 2 to also support legacy firebase keys format (number:alphanum:alphanumsymb) list($id, $value) = explode(':', $map, 2); $pusherFirebaseKeysmap[$id] = $value; } } if (array_key_exists($pnParam, $pusherFirebaseKeysmap)) { $this->pusherFirebaseKey = $pusherFirebaseKeysmap[$pnParam]; } } } public function sendToken(string $token): bool { $payload = json_encode(['token' => $token]); return $this->send(payload: $payload); } public function send(?string $payload = null, ?string $callId = null, ?string $type = 'background'): bool { if (!empty($this->pusherPath)) { $command = $this->pusherPath . " --pn-provider '" . $this->pnProvider . "'" . " --pn-param '" . $this->pnParam . "'" . " --pn-prid '" . $this->pnPrid . "'"; if ($payload != null) { $command .= " --customPayload '" . $payload . "'"; } if ($callId != null) { $command .= " --call-id '" . $callId . "'"; } if (in_array($this->pnProvider, ['apns', 'apns.dev']) && in_array($type, array_keys(self::$apnsTypes))) { $command .= " --apple-push-type " . self::$apnsTypes[$type]; } if ($this->pusherFirebaseKey) { $command .= " --key " . $this->pusherFirebaseKey; } $output = null; $result = null; exec($command . ' 2>&1', $output, $result); if ($result > 0) { Log::error('Flexisip Pusher error', [ 'command' => $command, 'output' => $output ]); return false; } return true; } Log::error('Flexisip Pusher path not configured'); return false; } }