Skip to content
Merged
Show file tree
Hide file tree
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 Oct 31, 2026
c5ced9f
feat(integration-slido): worker slido:listen que leva as perguntas pa…
danielhe4rt Oct 31, 2026
4b35645
feat(panel-overlays): cena He4rt Pub com câmera, chat, perguntas do S…
danielhe4rt Oct 31, 2026
e622f18
feat(panel-overlays): direção de arte da He4rt Pub sobre a câmera 4K
danielhe4rt Oct 31, 2026
7985961
feat(integration-slido): slido:serve conecta sozinho nos eventos com …
danielhe4rt Oct 31, 2026
6cc80e0
feat(panel-overlays): tira a resposta da moderação da pergunta no ar
danielhe4rt Oct 31, 2026
53d4596
fix(panel-overlays): a He4rt Pub encosta nas bordas em qualquer taman…
danielhe4rt Oct 31, 2026
9ac6c71
feat(panel-overlays): doca da He4rt Pub em degrau, com a pergunta em …
danielhe4rt Oct 31, 2026
de82953
fix(panel-overlays): tira o pixel de sobra na borda esquerda da He4rt…
danielhe4rt Oct 31, 2026
c00b58f
feat(panel-overlays): logo original da He4rt Pub na overlay
danielhe4rt Oct 31, 2026
ffd9eec
fix(panel-app): reconectar outra conta da Twitch escolhendo a conta c…
danielhe4rt Oct 31, 2026
f34ca07
feat(streaming): cada cena escolhe de quais fontes recebe chat e alertas
danielhe4rt Oct 31, 2026
4652804
feat(panel-app): botão Fontes em cada cena da página de Overlays
danielhe4rt Oct 31, 2026
5cd0de4
fix(integration-slido): ajustes da review do slido:serve e da cena Pub
danielhe4rt Oct 31, 2026
14f37ef
fix(integration-slido): backoff da reconexão só zera com a assinatura…
danielhe4rt Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ai/guidelines/workflow/02-triage-labels.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
| `mod:identity` | `identity` | Auth & user identity |
| `mod:integration-devto` | `integration-devto` | Dev.to integration |
| `mod:integration-discord`| `integration-discord` | Discord OAuth/API |
| `mod:integration-slido` | `integration-slido` | Slido Q&A integration |
| `mod:integration-twitch` | `integration-twitch` | Twitch integration |
| `mod:marketing` | `marketing` | Encurtador, campanhas |
| `mod:moderation` | `moderation` | Moderation pipeline |
Expand Down
32 changes: 32 additions & 0 deletions app-modules/integration-slido/composer.json
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 app-modules/integration-slido/config/integration-slido.php
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.
2 changes: 2 additions & 0 deletions app-modules/integration-slido/phpstan.ignore.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
parameters:
ignoreErrors: []
6 changes: 6 additions & 0 deletions app-modules/integration-slido/phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- phpstan.ignore.neon

parameters:
paths:
- src/
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();
}
}
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();
}
}
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 app-modules/integration-slido/src/Console/ServeSlidoEventsCommand.php
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();
Comment thread
danielhe4rt marked this conversation as resolved.
Resolved
}

/**
* 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));
}
}
51 changes: 51 additions & 0 deletions app-modules/integration-slido/src/Data/SlidoEvent.php
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,
];
}
}
23 changes: 23 additions & 0 deletions app-modules/integration-slido/src/Data/SlidoEventHash.php
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;
}
}
Loading
Loading