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

+51 -50
View File
@@ -9,6 +9,7 @@ use App\Model\Table\ResponsesTable;
use App\Model\Table\SlidesTable;
use App\Service\PollStateService;
use App\Service\QaService;
use App\Service\SlideControlService;
use App\Service\VoteService;
use Cake\Core\Configure;
use Cake\Http\Exception\BadRequestException;
@@ -55,8 +56,10 @@ class AdminController extends AdminAppController
$typeLabels = Slide::typeLabels();
$typeDescriptions = Slide::typeDescriptions();
$joinUrl = Router::url(['_name' => 'participate', 'code' => $this->poll->join_code], true);
// Created on first visit, so every slide has its embed URL ready to copy.
$embedKey = $this->Polls->ensureEmbedKey($this->poll);
$this->set(compact('slides', 'responseCounts', 'typeLabels', 'typeDescriptions', 'joinUrl'));
$this->set(compact('slides', 'responseCounts', 'typeLabels', 'typeDescriptions', 'joinUrl', 'embedKey'));
}
/**
@@ -102,6 +105,20 @@ class AdminController extends AdminAppController
return $this->redirect($this->adminUrl());
}
/**
* New embed key: all embed URLs (e.g. in Canva) stop working and must be inserted again.
*
* @return \Cake\Http\Response|null
*/
public function rotateEmbedKey(): ?Response
{
$this->request->allowMethod(['post']);
$this->Polls->rotateEmbedKey($this->poll);
$this->Flash->success(__('Neue Einbett-Links erstellt. Die bisherigen Links funktionieren nicht mehr – füge die neuen in deine Präsentation ein.'));
return $this->redirect($this->adminUrl() + ['#' => 'embed']);
}
/**
* Deletes the whole poll incl. slides and responses.
*
@@ -130,13 +147,13 @@ class AdminController extends AdminAppController
*/
public function present(): void
{
if ($this->poll->current_slide_id === null) {
if ($this->poll->current_slide_id === null && !$this->poll->isPaused()) {
$first = $this->Slides->find()
->where(['poll_id' => $this->poll->id])
->orderBy(['position' => 'ASC', 'id' => 'ASC'])
->first();
if ($first !== null) {
$this->poll->current_slide_id = $first->id;
$this->poll->showSlide($first->id);
$this->Polls->saveOrFail($this->poll);
}
}
@@ -159,11 +176,12 @@ class AdminController extends AdminAppController
/**
* Presenter controls. Field `action`:
* goto (+ slide_id), next, prev, open, close, toggle, stop,
* Q&A: stage (+ stage: collect|vote|discuss), question (+ step: 1|-1)
* goto (+ slide_id), next, prev, stop (pause), and the slide actions of
* SlideControlService (open, close, toggle, stage, question).
*
* On a Q&A slide that is being discussed, next/prev step through the questions
* first (like builds in presentation software), toggle switches to the next stage.
* first (like builds in presentation software). While paused, next/prev resume
* the slide that was live before.
*
* Answers with the new state as JSON for XHR requests, otherwise redirects back.
*
@@ -177,68 +195,51 @@ class AdminController extends AdminAppController
$ids = array_map(fn(Slide $s) => $s->id, $slides);
$index = array_search($this->poll->current_slide_id, $ids, true);
$current = $index === false ? null : $slides[$index];
$qa = new QaService();
if ($current !== null && $current->isQa()) {
if ($action === 'toggle') {
// No-op while discussing (last stage).
$qa->advance($current);
$action = 'none';
} elseif (in_array($action, ['next', 'prev'], true) && $qa->moveFocus($current, $action === 'next' ? 1 : -1)) {
$action = 'none';
}
if (
$current !== null
&& $current->isQa()
&& in_array($action, ['next', 'prev'], true)
&& (new QaService())->moveFocus($current, $action === 'next' ? 1 : -1)
) {
$action = 'none';
}
switch ($action) {
case 'none':
break;
case 'stage':
case 'question':
if ($current === null || !$current->isQa()) {
throw new BadRequestException('Not a Q&A slide');
}
if ($action === 'question') {
$qa->moveFocus($current, (int)$this->request->getData('step') < 0 ? -1 : 1);
break;
}
$stage = (string)$this->request->getData('stage');
if (!in_array($stage, Slide::QA_STAGES, true)) {
throw new BadRequestException('Unknown stage');
}
$qa->setStage($current, $stage);
break;
case 'goto':
$target = (int)$this->request->getData('slide_id');
if (!in_array($target, $ids, true)) {
throw new BadRequestException('Unknown slide');
}
$this->poll->current_slide_id = $target;
$this->poll->showSlide($target);
break;
case 'next':
case 'prev':
if ($ids !== []) {
$index = $index === false ? 0 : $index + ($action === 'next' ? 1 : -1);
$this->poll->current_slide_id = $ids[max(0, min(count($ids) - 1, $index))];
if ($ids === []) {
break;
}
if ($index === false && in_array($this->poll->paused_slide_id, $ids, true)) {
$this->poll->showSlide((int)$this->poll->paused_slide_id);
break;
}
$index = $index === false ? 0 : $index + ($action === 'next' ? 1 : -1);
$this->poll->showSlide($ids[max(0, min(count($ids) - 1, $index))]);
break;
case 'stop':
$this->poll->current_slide_id = null;
break;
case 'open':
case 'close':
case 'toggle':
if ($index !== false) {
// Opening a quiz (re)starts its timer, see Slide::setVotingOpen().
$slide = $slides[$index];
$slide->setVotingOpen(match ($action) {
'open' => true,
'close' => false,
default => !$slide->isVotingOpen(),
});
$this->Slides->saveOrFail($slide);
}
$this->poll->pause();
break;
default:
throw new BadRequestException('Unknown action');
if (!in_array($action, SlideControlService::ACTIONS, true)) {
throw new BadRequestException('Unknown action');
}
if ($current === null) {
if (in_array($action, ['stage', 'question'], true)) {
throw new BadRequestException('Not a Q&A slide');
}
break;
}
(new SlideControlService())->apply($current, $action, (array)$this->request->getData());
}
$this->Polls->saveOrFail($this->poll);