45 خطوط
1.2 KiB
PHP
45 خطوط
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\VoIP;
|
|
|
|
use App\Models\Setting;
|
|
|
|
class VoIPManager
|
|
{
|
|
private ?VoIPProviderInterface $provider = null;
|
|
|
|
public function provider(): VoIPProviderInterface
|
|
{
|
|
if ($this->provider === null) {
|
|
$providerName = Setting::where('key', 'voip_provider')->value('value') ?? 'mock';
|
|
$this->provider = match ($providerName) {
|
|
'ami' => new AmiProvider(),
|
|
'api' => new ApiProvider(),
|
|
'socket' => new SocketProvider(),
|
|
default => new MockProvider(),
|
|
};
|
|
}
|
|
return $this->provider;
|
|
}
|
|
|
|
public function initiateCall(string $phone, string $callerId = null): array
|
|
{
|
|
return $this->provider()->initiateCall($phone, $callerId);
|
|
}
|
|
|
|
public function getCallStatus(string $providerCallId): array
|
|
{
|
|
return $this->provider()->getCallStatus($providerCallId);
|
|
}
|
|
|
|
public function getRecordingUrl(string $providerCallId): ?string
|
|
{
|
|
return $this->provider()->getRecordingUrl($providerCallId);
|
|
}
|
|
|
|
public function testConnection(): array
|
|
{
|
|
return $this->provider()->testConnection();
|
|
}
|
|
}
|