Make your HTML deck work with Laser Pointer
An HTML presentation (a deck you open in a browser) can show its slides, animation steps and speaker notes on the Laser Pointer phone app, and the phone can change its slides, the same way it does for PowerPoint. The deck adds one line: a small script that talks to the Laser Pointer app on the same computer.
What the phone gets:
- the slide list with each slide's title, and the speaker notes of the slide you are on;
- the current slide, and how many animation steps are left on it;
- Next and Previous (they step through a slide's steps first, then change slide), and a tap in the slide list goes to that slide. Guests allowed to change slides can do the same.
- the deck's own controls, when it declares them (play or pause an animation, show the notes, open a presenter view): a row of buttons under the slideshow control. See Your deck's own controls.
With the guests' Screen pictures switch on, pictures come from capture of the presentation monitor after navigation from this app. The phone shows the current picture and the next only after that position has been reached; guests can zoom and look back at captured positions. Each build step is a position. Back then Next reuses its picture. Capture waits for the page's position update, or a short settle delay when no position signal is available. Pictures are kept within a memory budget, oldest first, and cleared for a new deck or when the show ends. Turn the switch off to stop capture. Other windows and notifications on that monitor can appear in the picture: use Focus / Do Not Disturb and keep other windows off the presentation monitor. With programs other than PowerPoint and Impress, change slides only from this app: PC keys, a clicker, mouse clicks and links can desynchronize the pictures until Start. Windows supports capture today; an unsupported desktop platform supplies no picture.
No script needed for notes and keys alone: a deck can declare them in a linked file instead, see The presentation standard.
Add the script
- Copy
web-deck/laser-pointer-deck.jsnext to your deck. Add this line at the end of the deck's
<body>, after the deck's own scripts (for reveal.js, afterReveal.initialize(...)):<script src="laser-pointer-deck.js"></script>- Open the deck from a web address, not as a file. For example, in the deck's folder run
python -m http.server 8000and openhttp://localhost:8000/your-deck.html. A deck opened as a file (file://...) cannot connect: every file page has the same "null" origin, so a yes to one would be a yes to all of them, and the app refuses it. A deck on a website (https://...) works too, as long as it is open in a browser on the computer that runs Laser Pointer. - Start the Laser Pointer app on the computer. The first time, its window asks "A web presentation wants to connect" and shows the deck's address. Choose Allow if you opened that deck. The app remembers the address; the window lists allowed addresses and can forget one. Don't allow blocks that address until the app restarts.
The script waits quietly while the app is closed and connects when it starts. It changes nothing in the deck and loads nothing else.
What the script reads
| How the script finds it | |
|---|---|
| Slides | every <section> that is not inside another <section>; or the elements matching data-slides on the script tag, e.g. <script src="laser-pointer-deck.js" data-slides=".slide"></script> |
| Title | the slide's data-title, else its first <h1>, <h2> or <h3>, else its aria-label, else its first picture's alt text |
| Speaker notes | the slide's data-notes, else the text of its <aside class="notes"> (paragraphs and list items become lines) |
| Step notes | the slide's data-step-notes: a JSON list of strings, entry k the note for step k + 1, e.g. data-step-notes='["Show the first chart", "Show the second"]'; the phone shows the note of the step the deck is on, with the slide's notes. Anything that is not a JSON list is no step notes |
| Animation steps | data-steps="N" on the slide: it shows in N steps, its first view counted, so N - 1 presses of next stay on it; else the highest data-step="k" inside it |
| Current slide | the slide with aria-current, or with the class on, active, current or present; else an address ending in #3, #s3 or #slide-3; else the first visible slide |
| Current step | counted from the keys: next and Page Down take a step, previous and Page Up go back one; a new slide starts at its first step, and going back to the previous slide lands on its last step |
The phone's commands press the deck's own keys: Right arrow (next), Left arrow (previous), Home (first slide) and End (last slide). A slide from the phone's list is reached by Home and then Right arrow until it shows. Keys you press on the computer, or a clicker that sends Page Up and Page Down, are followed too.
Notes and step notes that change while the deck runs (a deck that writes each step's notes) are sent again.
reveal.js
When the page has a ready reveal.js deck, the script uses its API instead: the slides are Reveal.getSlides() (vertical slides included, in order), the steps are the fragments (one step per fragment index), the position comes from reveal.js's own events, and the phone's commands call Reveal.next(), Reveal.prev() and Reveal.slide(). Notes are reveal.js's own <aside class="notes"> or data-notes.
Your deck's own controls
A deck often has keys of its own besides the slide keys: Space to play or pause an animation, N for the notes, P for a presenter window. List them on the script tag, and the phone shows each as a button; a tap presses that key in the deck, as if you pressed it on the computer:
<script src="laser-pointer-deck.js" data-actions='[
{"name": "Play/pause", "icon": "play_pause", "key": "space"},
{"name": "Notes", "icon": "notes", "key": "n"},
{"name": "Presenter", "icon": "presenter", "key": "p"}
]'></script>name: the button's label, up to 24 characters.icon: one ofplay_pause,play,pause,stop,restart,loop,slow,notes,presenter,full_screen,zoom,sound,help,action(a plain button).key: one key, no Ctrl, Alt or Shift: a lower-case letter or a digit,f1tof12, orenter,backspace,delete,tab,escape,space,up,down,left,right,home,end,page_up,page_down,insert,print_screen.- Up to 8 actions. One the app does not take (an unknown icon or key, an empty name, one too many) is left out and named in the browser's console.
Steps need no action: Next and Previous already step through them. A deck that adapts through LaserDeck.use can give the same list as actions.
The key is pressed inside the deck's page only, never on the computer's keyboard, so it reaches the deck even when another window is in front, and no other program. Browsers do not let a page open a window or go full screen from such a key: a Presenter or Full screen action works only after you let the deck's address open pop-ups (the browser offers this the first time it blocks one); Full screen does not work at all.
Adapting a custom deck
A deck that does not follow these conventions, or knows its own position better than the keys do, uses window.LaserDeck:
LaserDeck.use({
// The slides, when they are not <section> elements (a canvas deck, a deck built from JSON).
slides: () => myDeck.slides.map((s) => ({ title: s.title, notes: s.notes, steps: s.steps.length })),
// The phone's commands, when the deck's keys are not the arrows, Home and End.
next: () => myDeck.next(),
previous: () => myDeck.previous(),
first: () => myDeck.goTo(1),
last: () => myDeck.goTo(myDeck.slides.length),
goto: (slide) => myDeck.goTo(slide), // 1-based
});
// Each time the deck moves: the slide (1-based) and the steps taken on it (0 = first view).
myDeck.onChange((slide, step) => LaserDeck.report(slide, step));
// After the deck changed its slides, titles or notes.
LaserDeck.refresh();
// connecting, waiting (for the yes on the computer), connected, offline or "refused: <code>".
console.log(LaserDeck.status);Every part of use is optional. Once a deck calls report, the script stops counting steps from keys and trusts the deck. A deck that gives slides must call report.
Another port: data-port="47802" on the script tag (the app listens on 47801).
Limits
The app refuses a page that sends more, so the script trims to the limits the app sends it:
- 500 slides; titles up to 200 characters; notes up to 8000 characters per slide (shortened further when the whole deck would not fit in 1 MB); 100 steps per slide, with at most one step note each and the step notes of a slide together up to 8000 characters (cut to fit, from the first); 8 actions, names up to 24 characters;
- up to 20 messages a second (the script sends at most 10 positions a second) and a new slide list at most every 2 seconds. These are counted for the address of the page, so closing and reopening the connection does not give it more.
Who wins
- A deck open in PowerPoint or Impress that the app is following wins: while it is there, a web deck cannot connect, and one that is connected is disconnected.
- One web deck at a time: a page from another address waits until the connected one closes. A reload or a second tab of the same deck takes over.
Safety
The script connects only to 127.0.0.1 (this computer); the app's web deck port does not listen on the network. The app accepts a page only after your yes, shown with the page's address, and before that uses nothing the page sends. A page can send its slide titles, notes, position and its own controls (buttons with a name, an icon from a fixed list and one key from a fixed list), and receive slide commands and those keys; it never sees the phone's pairing, the guests, their questions or polls. What a page could still do once allowed: show any titles, notes and button names it likes on your phone, within the limits above; a button only presses a key inside that page. Allow only decks you opened yourself, and forget an address you no longer use.