Repository navigation
feat(panel-overlays): overlay da He4rt Pub com o Slido #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0353511
feat(integration-slido): cliente do Slido com token anônimo de partic…
danielhe4rt c5ced9f
feat(integration-slido): worker slido:listen que leva as perguntas pa…
danielhe4rt 4b35645
feat(panel-overlays): cena He4rt Pub com câmera, chat, perguntas do S…
danielhe4rt e622f18
feat(panel-overlays): direção de arte da He4rt Pub sobre a câmera 4K
danielhe4rt 7985961
feat(integration-slido): slido:serve conecta sozinho nos eventos com …
danielhe4rt 6cc80e0
feat(panel-overlays): tira a resposta da moderação da pergunta no ar
danielhe4rt 53d4596
fix(panel-overlays): a He4rt Pub encosta nas bordas em qualquer taman…
danielhe4rt 9ac6c71
feat(panel-overlays): doca da He4rt Pub em degrau, com a pergunta em …
danielhe4rt de82953
fix(panel-overlays): tira o pixel de sobra na borda esquerda da He4rt…
danielhe4rt c00b58f
feat(panel-overlays): logo original da He4rt Pub na overlay
danielhe4rt ffd9eec
fix(panel-app): reconectar outra conta da Twitch escolhendo a conta c…
danielhe4rt f34ca07
feat(streaming): cada cena escolhe de quais fontes recebe chat e alertas
danielhe4rt 4652804
feat(panel-app): botão Fontes em cada cena da página de Overlays
danielhe4rt 5cd0de4
fix(integration-slido): ajustes da review do slido:serve e da cena Pub
danielhe4rt 14f37ef
fix(integration-slido): backoff da reconexão só zera com a assinatura…
danielhe4rt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| { | ||
| "name": "he4rt/integration-slido", | ||
| "description": "", | ||
| "type": "library", | ||
| "version": "1.0.0", | ||
| "license": "proprietary", | ||
| "require": { | ||
| "ratchet/pawl": "^0.4.3", | ||
| "react/event-loop": "^1.6.0", | ||
| "saloonphp/saloon": "^4.5.0" | ||
| }, | ||
| "autoload": { | ||
| "psr-4": { | ||
| "He4rt\\IntegrationSlido\\": "src/", | ||
| "He4rt\\IntegrationSlido\\Database\\Factories\\": "database/factories/", | ||
| "He4rt\\IntegrationSlido\\Database\\Seeders\\": "database/seeders/" | ||
| } | ||
| }, | ||
| "autoload-dev": { | ||
| "psr-4": { | ||
| "He4rt\\IntegrationSlido\\Tests\\": "tests/" | ||
| } | ||
| }, | ||
| "minimum-stability": "stable", | ||
| "extra": { | ||
| "laravel": { | ||
| "providers": [ | ||
| "He4rt\\IntegrationSlido\\IntegrationSlidoServiceProvider" | ||
| ] | ||
| } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
app-modules/integration-slido/config/integration-slido.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| return [ | ||
| 'client_id' => env('SLIDO_CLIENT_ID', '8d10c777-8ac6-4eb9-9d78-1e66cfc93b24'), | ||
| 'auth_url' => env('SLIDO_AUTH_URL', 'https://auth.slido.com'), | ||
| 'lookup_url' => env('SLIDO_LOOKUP_URL', 'https://app.sli.do/global/api'), | ||
| 'wall_url' => env('SLIDO_WALL_URL', 'https://wall.sli.do'), | ||
| 'stream_url' => env('SLIDO_STREAM_URL', 'wss://wall.sli.do'), | ||
| ]; |
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| parameters: | ||
| ignoreErrors: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| includes: | ||
| - phpstan.ignore.neon | ||
|
|
||
| parameters: | ||
| paths: | ||
| - src/ |
46 changes: 46 additions & 0 deletions
46
app-modules/integration-slido/src/Broadcasting/SlidoQuestionChanged.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Broadcasting; | ||
|
|
||
| use He4rt\IntegrationSlido\Data\SlidoQuestion; | ||
| use He4rt\Streaming\Streamer\Models\Streamer; | ||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||
| use Illuminate\Broadcasting\PrivateChannel; | ||
| use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; | ||
| use Illuminate\Contracts\Broadcasting\ShouldRescue; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| final class SlidoQuestionChanged implements ShouldBroadcastNow, ShouldRescue | ||
| { | ||
| use Dispatchable; | ||
| use InteractsWithSockets; | ||
|
|
||
| /** | ||
| * @param list<Streamer> $streamers | ||
| */ | ||
| public function __construct( | ||
| public array $streamers, | ||
| public SlidoQuestion $question, | ||
| ) {} | ||
|
|
||
| /** @return array<int, PrivateChannel> */ | ||
| public function broadcastOn(): array | ||
| { | ||
| return array_map(fn (Streamer $streamer): PrivateChannel => new PrivateChannel($streamer->overlayChannel()), $this->streamers); | ||
| } | ||
|
|
||
| public function broadcastAs(): string | ||
| { | ||
| return 'pub.question'; | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, mixed> | ||
| */ | ||
| public function broadcastWith(): array | ||
| { | ||
| return $this->question->toArray(); | ||
| } | ||
| } |
46 changes: 46 additions & 0 deletions
46
app-modules/integration-slido/src/Broadcasting/SlidoQuestionPatched.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Broadcasting; | ||
|
|
||
| use He4rt\IntegrationSlido\Data\SlidoQuestionPatch; | ||
| use He4rt\Streaming\Streamer\Models\Streamer; | ||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||
| use Illuminate\Broadcasting\PrivateChannel; | ||
| use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; | ||
| use Illuminate\Contracts\Broadcasting\ShouldRescue; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| final class SlidoQuestionPatched implements ShouldBroadcastNow, ShouldRescue | ||
| { | ||
| use Dispatchable; | ||
| use InteractsWithSockets; | ||
|
|
||
| /** | ||
| * @param list<Streamer> $streamers | ||
| */ | ||
| public function __construct( | ||
| public array $streamers, | ||
| public SlidoQuestionPatch $patch, | ||
| ) {} | ||
|
|
||
| /** @return array<int, PrivateChannel> */ | ||
| public function broadcastOn(): array | ||
| { | ||
| return array_map(fn (Streamer $streamer): PrivateChannel => new PrivateChannel($streamer->overlayChannel()), $this->streamers); | ||
| } | ||
|
|
||
| public function broadcastAs(): string | ||
| { | ||
| return 'pub.question-patch'; | ||
| } | ||
|
|
||
| /** | ||
| * @return array{id: int, changes: array<string, int|bool>} | ||
| */ | ||
| public function broadcastWith(): array | ||
| { | ||
| return $this->patch->toArray(); | ||
| } | ||
| } |
47 changes: 47 additions & 0 deletions
47
app-modules/integration-slido/src/Broadcasting/SlidoQuestionsSynced.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Broadcasting; | ||
|
|
||
| use He4rt\IntegrationSlido\Data\SlidoQuestion; | ||
| use He4rt\Streaming\Streamer\Models\Streamer; | ||
| use Illuminate\Broadcasting\InteractsWithSockets; | ||
| use Illuminate\Broadcasting\PrivateChannel; | ||
| use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; | ||
| use Illuminate\Contracts\Broadcasting\ShouldRescue; | ||
| use Illuminate\Foundation\Events\Dispatchable; | ||
|
|
||
| final class SlidoQuestionsSynced implements ShouldBroadcastNow, ShouldRescue | ||
| { | ||
| use Dispatchable; | ||
| use InteractsWithSockets; | ||
|
|
||
| /** | ||
| * @param list<Streamer> $streamers | ||
| * @param list<SlidoQuestion> $questions | ||
| */ | ||
| public function __construct( | ||
| public array $streamers, | ||
| public array $questions, | ||
| ) {} | ||
|
|
||
| /** @return array<int, PrivateChannel> */ | ||
| public function broadcastOn(): array | ||
| { | ||
| return array_map(fn (Streamer $streamer): PrivateChannel => new PrivateChannel($streamer->overlayChannel()), $this->streamers); | ||
| } | ||
|
|
||
| public function broadcastAs(): string | ||
| { | ||
| return 'pub.questions'; | ||
| } | ||
|
|
||
| /** | ||
| * @return array{questions: list<array<string, mixed>>} | ||
| */ | ||
| public function broadcastWith(): array | ||
| { | ||
| return ['questions' => array_map(fn (SlidoQuestion $question): array => $question->toArray(), $this->questions)]; | ||
| } | ||
| } |
113 changes: 113 additions & 0 deletions
113
app-modules/integration-slido/src/Console/ServeSlidoEventsCommand.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Console; | ||
|
|
||
| use He4rt\IntegrationSlido\Data\SlidoEventLocation; | ||
| use He4rt\IntegrationSlido\Stream\QuestionFeed; | ||
| use He4rt\IntegrationSlido\Stream\SlidoAudience; | ||
| use He4rt\IntegrationSlido\Stream\SlidoConnection; | ||
| use He4rt\IntegrationSlido\Stream\SlidoStreamSession; | ||
| use He4rt\IntegrationSlido\Stream\SlidoSubscriptionPlan; | ||
| use He4rt\IntegrationSlido\Transport\SlidoClient; | ||
| use He4rt\Streaming\Streamer\Models\Streamer; | ||
| use Illuminate\Console\Attributes\Description; | ||
| use Illuminate\Console\Attributes\Signature; | ||
| use Illuminate\Console\Command; | ||
| use React\EventLoop\Loop; | ||
| use React\EventLoop\LoopInterface; | ||
| use Throwable; | ||
|
|
||
| #[Description(description: 'Mantém uma conexão com cada evento do Slido que tem uma overlay He4rt Pub aberta')] | ||
| #[Signature(signature: 'slido:serve {--interval=15 : segundos entre cada conferência das overlays abertas}')] | ||
| final class ServeSlidoEventsCommand extends Command | ||
| { | ||
| /** @var array<string, SlidoConnection> */ | ||
| private array $connections = []; | ||
|
|
||
| /** @var array<string, SlidoEventLocation> */ | ||
| private array $locations = []; | ||
|
|
||
| public function handle(SlidoClient $client, QuestionFeed $feed, SlidoAudience $audience): int | ||
| { | ||
| $loop = Loop::get(); | ||
| $interval = max(5, (int) $this->option('interval')); | ||
|
|
||
| $this->log(sprintf('Conferindo as overlays He4rt Pub a cada %ds.', $interval)); | ||
|
|
||
| $reconcile = function () use ($client, $feed, $audience, $loop): void { | ||
| try { | ||
| $this->reconcile($client, $feed, $audience->current(), $loop); | ||
| } catch (Throwable $throwable) { | ||
| $this->log('Falhou ao conferir as overlays: '.$throwable->getMessage()); | ||
| } | ||
| }; | ||
|
|
||
| $reconcile(); | ||
| $loop->addPeriodicTimer($interval, $reconcile); | ||
| $loop->run(); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| /** | ||
| * @param array<string, list<Streamer>> $audience | ||
| */ | ||
| private function reconcile(SlidoClient $client, QuestionFeed $feed, array $audience, LoopInterface $loop): void | ||
| { | ||
| $plan = SlidoSubscriptionPlan::between($this->hashesOf($audience), $this->hashesOf($this->connections)); | ||
|
|
||
| foreach ($plan->closing as $eventHash) { | ||
| $this->connections[$eventHash]->close(); | ||
| unset($this->connections[$eventHash]); | ||
| $this->log(sprintf('[%s] Nenhuma overlay aberta: desconectou.', $eventHash)); | ||
| } | ||
|
|
||
| foreach ($plan->keeping as $eventHash) { | ||
| $this->connections[$eventHash]->session->retarget($audience[$eventHash]); | ||
| } | ||
|
|
||
| foreach ($plan->opening as $eventHash) { | ||
| $this->open($client, $feed, $eventHash, $audience[$eventHash], $loop); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param list<Streamer> $streamers | ||
| */ | ||
| private function open(SlidoClient $client, QuestionFeed $feed, string $eventHash, array $streamers, LoopInterface $loop): void | ||
| { | ||
| try { | ||
| $location = $this->locations[$eventHash] ??= $client->locate($eventHash); | ||
| } catch (Throwable $throwable) { | ||
| $this->log(sprintf('[%s] Não achou o evento no Slido: %s', $eventHash, $throwable->getMessage())); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| $log = fn (string $line) => $this->log(sprintf('[%s] %s', $eventHash, $line)); | ||
| $session = new SlidoStreamSession($client, $feed, $location, $streamers, $log); | ||
| $connection = new SlidoConnection($session, $loop, $log); | ||
|
|
||
| $this->connections[$eventHash] = $connection; | ||
| $log(sprintf('Conectando para %d overlay(s).', count($streamers))); | ||
| $connection->open(); | ||
| } | ||
|
|
||
| /** | ||
| * PHP turns a digit-only event hash into an integer array key. | ||
| * | ||
| * @param array<array-key, mixed> $keyedByHash | ||
| * @return list<string> | ||
| */ | ||
| private function hashesOf(array $keyedByHash): array | ||
| { | ||
| return array_map(strval(...), array_keys($keyedByHash)); | ||
| } | ||
|
|
||
| private function log(string $line): void | ||
| { | ||
| $this->line(sprintf('[%s] %s', now()->format('H:i:s'), $line)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Data; | ||
|
|
||
| use He4rt\IntegrationSlido\Exceptions\SlidoResponseInvalid; | ||
|
|
||
| final readonly class SlidoEvent | ||
| { | ||
| public function __construct( | ||
| public SlidoEventLocation $location, | ||
| public string $name, | ||
| public string $code, | ||
| public bool $isActive, | ||
| public string $participantUrl, | ||
| ) {} | ||
|
|
||
| /** | ||
| * @param array<array-key, mixed> $payload | ||
| */ | ||
| public static function fromPayload(SlidoEventLocation $location, array $payload): self | ||
| { | ||
| $name = $payload['name'] ?? null; | ||
| $participantUrl = is_array($payload['url'] ?? null) ? ($payload['url']['app'] ?? null) : null; | ||
|
|
||
| throw_unless(is_string($name) && is_string($participantUrl), SlidoResponseInvalid::missing('event', 'name, url.app')); | ||
|
|
||
| return new self( | ||
| location: $location, | ||
| name: $name, | ||
| code: is_scalar($payload['code'] ?? null) ? (string) $payload['code'] : '', | ||
| isActive: ($payload['is_active'] ?? false) === true, | ||
| participantUrl: $participantUrl, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @return array{hash: string, name: string, code: string, isActive: bool, participantUrl: string} | ||
| */ | ||
| public function toArray(): array | ||
| { | ||
| return [ | ||
| 'hash' => $this->location->hash, | ||
| 'name' => $this->name, | ||
| 'code' => $this->code, | ||
| 'isActive' => $this->isActive, | ||
| 'participantUrl' => $this->participantUrl, | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace He4rt\IntegrationSlido\Data; | ||
|
|
||
| final class SlidoEventHash | ||
| { | ||
| private const string HASH_PATTERN = '[A-Za-z0-9]{6,64}'; | ||
|
|
||
| public static function fromInput(string $input): ?string | ||
| { | ||
| $input = mb_trim($input); | ||
|
|
||
| if (preg_match('#^'.self::HASH_PATTERN.'$#', $input) === 1) { | ||
| return $input; | ||
| } | ||
|
|
||
| $isSlidoEventUrl = preg_match('#^https://(?:app|wall|admin)\.sli\.do/event/('.self::HASH_PATTERN.')(?:[/?\#]|$)#', $input, $matches) === 1; | ||
|
|
||
| return $isSlidoEventUrl ? $matches[1] : null; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.