34 lines
820 B
PHP
34 lines
820 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Blax\WebRtc\Tests\Fixtures;
|
||
|
|
|
||
|
|
use Blax\WebRtc\Contracts\RecordingStore;
|
||
|
|
|
||
|
|
final class MemoryRecordingStore implements RecordingStore
|
||
|
|
{
|
||
|
|
/** @var array<string,string> "room|peer" => concatenated bytes */
|
||
|
|
public array $data = [];
|
||
|
|
|
||
|
|
/** @var array<int,string> finalized keys */
|
||
|
|
public array $finalized = [];
|
||
|
|
|
||
|
|
public function append(string $roomId, string $peerId, string $chunk): void
|
||
|
|
{
|
||
|
|
$key = "{$roomId}|{$peerId}";
|
||
|
|
$this->data[$key] = ($this->data[$key] ?? '').$chunk;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function finalize(string $roomId, string $peerId): ?string
|
||
|
|
{
|
||
|
|
$key = "{$roomId}|{$peerId}";
|
||
|
|
if (! isset($this->data[$key])) {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
$this->finalized[] = $key;
|
||
|
|
|
||
|
|
return "mem://{$key}";
|
||
|
|
}
|
||
|
|
}
|