- Add Metered and ConvexSol (CoTURN) provider drivers with response validation and caching - Add IceCandidateManager with automatic failover and structured logging - Add IceCandidateProviderInterface and DTOs conforming to RTCIceServer format
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use JsonSerializable;
|
|
|
|
class IceCandidateDto implements Arrayable, JsonSerializable
|
|
{
|
|
/**
|
|
* @param string|array<string> $urls
|
|
*/
|
|
public function __construct(
|
|
public readonly string|array $urls,
|
|
public readonly ?string $username = null,
|
|
public readonly ?string $credential = null,
|
|
public readonly ?string $credentialType = null,
|
|
) {}
|
|
|
|
public static function fromArray(array $data): self
|
|
{
|
|
$rawUrls = $data['urls'] ?? $data['url'] ?? '';
|
|
|
|
return new self(
|
|
urls: is_array($rawUrls) ? array_values($rawUrls) : (string) $rawUrls,
|
|
username: isset($data['username']) ? (string) $data['username'] : null,
|
|
credential: isset($data['credential']) ? (string) $data['credential'] : (isset($data['password']) ? (string) $data['password'] : null),
|
|
credentialType: isset($data['credentialType']) ? (string) $data['credentialType'] : null,
|
|
);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return array_filter([
|
|
'urls' => $this->urls,
|
|
'username' => $this->username,
|
|
'credential' => $this->credential,
|
|
'credentialType' => $this->credentialType,
|
|
], fn ($value) => $value !== null);
|
|
}
|
|
|
|
public function jsonSerialize(): array
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
}
|