Something went wrong. Try again.
Build Reactive Signals for Bluesky's AT Protocol Firehose in Laravel
Something went wrong. Try again.
1.2 kB · 52 lines
PHP
at dev
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<?php
namespace SocialDept\AtpSignals\Services;
use InvalidArgumentException;
class SignalManager{ public function __construct( protected FirehoseConsumer $firehoseConsumer, protected JetstreamConsumer $jetstreamConsumer, ) { }
/** * Start consuming events from the AT Protocol. */ public function start(?int $cursor = null): void { $this->resolveConsumer()->start($cursor); }
/** * Stop consuming events. */ public function stop(): void { $this->resolveConsumer()->stop(); }
/** * Get the current consumer mode. */ public function getMode(): string { return config('signal.mode', 'jetstream'); }
/** * Resolve the appropriate consumer based on configuration. */ protected function resolveConsumer(): FirehoseConsumer|JetstreamConsumer { $mode = $this->getMode();
return match ($mode) { 'firehose' => $this->firehoseConsumer, 'jetstream' => $this->jetstreamConsumer, default => throw new InvalidArgumentException("Invalid signal mode: {$mode}. Must be 'jetstream' or 'firehose'."), }; }}