- 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
70 lines
1.5 KiB
PHP
70 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\DTOs;
|
|
|
|
use ArrayIterator;
|
|
use Countable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use IteratorAggregate;
|
|
use JsonSerializable;
|
|
use Traversable;
|
|
|
|
class IceCandidatesDto implements Arrayable, Countable, IteratorAggregate, JsonSerializable
|
|
{
|
|
/**
|
|
* @param array<IceCandidateDto> $servers
|
|
*/
|
|
public function __construct(
|
|
public readonly array $servers = []
|
|
) {}
|
|
|
|
public static function fromArray(array $items): self
|
|
{
|
|
$servers = [];
|
|
foreach ($items as $item) {
|
|
if ($item instanceof IceCandidateDto) {
|
|
$servers[] = $item;
|
|
} elseif (is_array($item)) {
|
|
$servers[] = IceCandidateDto::fromArray($item);
|
|
}
|
|
}
|
|
|
|
return new self($servers);
|
|
}
|
|
|
|
public static function defaultStun(): self
|
|
{
|
|
return new self([
|
|
new IceCandidateDto(urls: [
|
|
'stun:stun.l.google.com:19302',
|
|
'stun:stun.cloudflare.com:3478',
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return array_map(fn (IceCandidateDto $server) => $server->toArray(), $this->servers);
|
|
}
|
|
|
|
public function jsonSerialize(): array
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
|
|
public function count(): int
|
|
{
|
|
return count($this->servers);
|
|
}
|
|
|
|
public function isEmpty(): bool
|
|
{
|
|
return empty($this->servers);
|
|
}
|
|
|
|
public function getIterator(): Traversable
|
|
{
|
|
return new ArrayIterator($this->servers);
|
|
}
|
|
}
|