| 1 | // presenting_talk.go serves the whole talk as one payload, so the |
| 2 | // presenter and slide windows hold every slide in memory before the |
| 3 | // first press and a press needs no network. |
| 4 | package slides |
| 5 | |
| 6 | import ( |
| 7 | "encoding/json" |
| 8 | "net/http" |
| 9 | "net/url" |
| 10 | "strconv" |
| 11 | |
| 12 | "amadan.net/oficina/slides/internal/slides/deck" |
| 13 | slidehtml "amadan.net/oficina/slides/internal/slides/render" |
| 14 | ) |
| 15 | |
| 16 | type talkSlide struct { |
| 17 | ID string `json:"id"` |
| 18 | Number int `json:"number"` |
| 19 | Title string `json:"title"` |
| 20 | Full bool `json:"full"` |
| 21 | Presses int `json:"presses"` |
| 22 | HTML string `json:"html"` // rendered with Reveal at 0 |
| 23 | Assets []string `json:"assets"` |
| 24 | // Clips is the video of each clip on the slide (render.ClipPaths), |
| 25 | // fetched with the talk; absent when it has none. |
| 26 | Clips []string `json:"clips,omitempty"` |
| 27 | Thumb string `json:"thumb"` |
| 28 | Notes []string `json:"notes,omitempty"` // one HTML part per press section |
| 29 | } |
| 30 | |
| 31 | type talkPayload struct { |
| 32 | DeckSeq int64 `json:"deckSeq"` |
| 33 | Arrive string `json:"arrive"` |
| 34 | Slides []talkSlide `json:"slides"` |
| 35 | // Uploaded is the deck's own fonts as the font manifest carries them |
| 36 | // (fontgate.go), under this session: a window holding the talk |
| 37 | // learns them before it makes a slide ready, so a font the deck took |
| 38 | // on after the window opened is loaded, not fallen back from. |
| 39 | Uploaded map[string]gateFamily `json:"uploaded,omitempty"` |
| 40 | // Scenes is every scene the talk's slides show, as the presenting |
| 41 | // windows run them (scene_pages.go); absent when they show none. |
| 42 | Scenes map[string]pageScene `json:"scenes,omitempty"` |
| 43 | } |
| 44 | |
| 45 | // presentTalk is GET /p/{session}/talk. Anyone the session lets in gets |
| 46 | // the slides; the notes go only to who may drive (mayDrive), so the |
| 47 | // slide window never holds them. |
| 48 | func (a *app) presentTalk(w http.ResponseWriter, r *http.Request) { |
| 49 | p, ok := a.presentationFor(w, r) |
| 50 | if !ok { |
| 51 | return |
| 52 | } |
| 53 | d, ok := a.deckOf(w, r, p) |
| 54 | if !ok { |
| 55 | return |
| 56 | } |
| 57 | withNotes, _, answered := a.mayDrive(w, r, p, r.URL.Query().Get("t")) |
| 58 | if answered { |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | // The tag is the deck's seq, and says whether notes are in the body: |
| 63 | // a body without them must not satisfy a request that may have them. |
| 64 | // And the deck's share links, which decide the follow-along |
| 65 | // codes drawn (followCodes): revoking one changes no seq. |
| 66 | links := a.linksStamp(r.Context(), d) |
| 67 | etag := strconv.Quote(strconv.FormatInt(d.Seq, 10) + links) |
| 68 | if withNotes { |
| 69 | etag = strconv.Quote(strconv.FormatInt(d.Seq, 10) + links + "-n") |
| 70 | } |
| 71 | w.Header().Set("Cache-Control", "no-store") |
| 72 | w.Header().Set("ETag", etag) |
| 73 | if matchesETag(r.Header.Get("If-None-Match"), etag) { |
| 74 | w.WriteHeader(http.StatusNotModified) |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | h, view, err := a.openDeck(r.Context(), d) |
| 79 | if err != nil { |
| 80 | a.fail(w, r, "open a deck for the talk", err) |
| 81 | return |
| 82 | } |
| 83 | defer h.Close(r.Context()) |
| 84 | view = view.ForReaders() |
| 85 | |
| 86 | base := "/p/" + p.Sqid |
| 87 | codes := a.followCodes(r.Context(), d, view, base) |
| 88 | zero := 0 |
| 89 | arrive := view.Meta.Arrive |
| 90 | if arrive == "" { |
| 91 | arrive = "appear" |
| 92 | } |
| 93 | out := talkPayload{DeckSeq: d.Seq, Arrive: arrive, Slides: []talkSlide{}} |
| 94 | out.Uploaded, _ = uploadedFamilies(view.Meta.FontFiles, base) |
| 95 | order := deck.TalkOrder(view, deck.ModeFull) |
| 96 | out.Scenes = scenesShown(view, base, order...) |
| 97 | for n, i := range order { |
| 98 | s := view.Slides[i] |
| 99 | html, err := slidehtml.SlideWith(view, i, slidehtml.Desktop, |
| 100 | slidehtml.Options{AssetBase: base + "/assets", Reveal: &zero, QRAlt: qrAlt(r), QR: codes}) |
| 101 | if err != nil { |
| 102 | a.fail(w, r, "render a slide for the talk", err) |
| 103 | return |
| 104 | } |
| 105 | ts := talkSlide{ |
| 106 | ID: s.ID, |
| 107 | Number: n + 1, |
| 108 | Title: slideLabel(r, s, i+1), |
| 109 | Full: s.Talk == "full", |
| 110 | Presses: len(deck.Presses(s, view.Scenes)), |
| 111 | HTML: string(html), |
| 112 | Assets: slidehtml.AssetPaths(view, i, base+"/assets"), |
| 113 | Clips: slidehtml.ClipPaths(view, i, base+"/assets"), |
| 114 | Thumb: base + "/slides/" + url.PathEscape(s.ID) + ".svg", |
| 115 | } |
| 116 | if withNotes && len(s.Notes) > 0 { |
| 117 | for _, part := range deck.NoteParts(s.Notes) { |
| 118 | ts.Notes = append(ts.Notes, string(slidehtml.Notes(part))) |
| 119 | } |
| 120 | } |
| 121 | out.Slides = append(out.Slides, ts) |
| 122 | } |
| 123 | |
| 124 | w.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 125 | json.NewEncoder(w).Encode(out) |
| 126 | } |
| 127 | |