Add embeddable slides and pause mode
CI / Deploy / test (push) Successful in 1m4s
CI / Deploy / deploy (push) Skipped

Every slide gets an embed URL /e/{key}/{id} for presentation software
like Canva. The page goes live while it is visible, keeps itself live
with heartbeats and pauses when it disappears; stale embeds are paused
lazily. The embed key is separate from the admin token and only allows
showing, activating, pausing and voting controls of that slide.

Participants see a pause page while no slide is live. The presenter
can pause (P) and resume the paused slide with the arrow keys; the
dashboard has a pause button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:26:05 +01:00
1 parent 58145e9753
commit 07a292d109
19 files changed
+1116 -68

No files matched your search

+39
View File
@@ -5,6 +5,7 @@ namespace App\Service;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\PollsTable;
use App\Model\Table\ResponsesTable;
use App\Model\Table\SlidesTable;
use Cake\ORM\Locator\LocatorAwareTrait;
@@ -33,6 +34,8 @@ class PollStateService
protected ResponsesTable $Responses;
protected PollsTable $Polls;
protected ResultsService $results;
/**
@@ -46,6 +49,9 @@ class PollStateService
/** @var \App\Model\Table\ResponsesTable $responses */
$responses = $this->fetchTable('Responses');
$this->Responses = $responses;
/** @var \App\Model\Table\PollsTable $polls */
$polls = $this->fetchTable('Polls');
$this->Polls = $polls;
$this->results = new ResultsService();
}
@@ -55,6 +61,7 @@ class PollStateService
*/
public function currentSlide(Poll $poll): ?Slide
{
$this->Polls->pauseIfEmbedStale($poll);
if ($poll->current_slide_id === null) {
return null;
}
@@ -74,6 +81,7 @@ class PollStateService
*/
public function forPresenter(Poll $poll): array
{
$this->Polls->pauseIfEmbedStale($poll);
$slides = $this->Slides->listForPoll($poll->id);
$current = null;
$index = null;
@@ -90,6 +98,7 @@ class PollStateService
'joinCode' => $poll->join_code,
'joinCodeFormatted' => $poll->formattedJoinCode(),
'isActive' => $poll->is_active,
'isPaused' => $poll->isPaused(),
],
'slides' => array_map(fn(Slide $s) => [
'id' => $s->id,
@@ -103,6 +112,35 @@ class PollStateService
];
}
/**
* State of one embedded slide (/e/{key}/{slide}/state). Same shape as forPresenter(),
* but always for this slide, live or not, plus `isLive`. Never contains the slide list.
*
* @param \App\Model\Entity\Poll $poll Poll
* @param \App\Model\Entity\Slide $slide Slide of this poll incl. slide_options
* @return array<string, mixed>
*/
public function forEmbed(Poll $poll, Slide $slide): array
{
$this->Polls->pauseIfEmbedStale($poll);
$slide = $this->Slides->closeIfExpired($slide);
return [
'poll' => [
'title' => $poll->title,
'joinCode' => $poll->join_code,
'joinCodeFormatted' => $poll->formattedJoinCode(),
'isActive' => $poll->is_active,
'isPaused' => $poll->isPaused(),
],
'isLive' => $poll->current_slide_id === $slide->id,
'index' => null,
'count' => null,
'slide' => $this->slidePayload($slide),
'results' => $this->results->forSlide($slide),
];
}
/**
* @param \App\Model\Entity\Poll $poll Poll
* @param string $participantHash Participant hash
@@ -131,6 +169,7 @@ class PollStateService
return [
'isActive' => $poll->is_active,
'isPaused' => $slide === null && $poll->isPaused(),
'slideId' => $slide?->id,
'isVotingOpen' => $isVotingOpen,
'hasResponded' => $hasResponded,