-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolls.js
More file actions
81 lines (74 loc) · 2.43 KB
/
Copy pathpolls.js
File metadata and controls
81 lines (74 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
/*
* Shared configuration for the live polls — loaded by both pages:
*
* index.html The presentation = the presenter. Counts votes and
* publishes the active question whenever a poll slide
* (data-poll="<id>") is shown.
* poll.html The audience page. Shows the active question, casts votes.
*
* The channel is stable, so the audience link never changes and can be
* clicked straight from the slides. Only decks opened with the presenter
* key publish control messages — the key gates publishing, not reading,
* and is an accident guard, not a security boundary (the broker and this
* file are public anyway).
*
* Votes travel as retained MQTT messages through a free public broker:
* <prefix>/control retained id of the active question
* <prefix>/vote/<qid>/<clientId> retained latest vote per device
*/
// EMQ's free public broker (official EMQX showcase, documented WSS
// endpoint, public status dashboard). If it's ever down on the day, the
// fix is to change this one line and redeploy.
const BROKER_URL = "wss://broker.emqx.io:8084/mqtt";
// Random suffix = our own little namespace on the shared public broker.
const TOPIC_PREFIX = "wikimania2026/ep-poll/k7x2q9";
// The speaker opens index.html?key=<this>. Only keyed decks publish
// control messages; the shared slides link has no key, so followers'
// tabs can never take over the audience page by accident.
const PRESENTER_KEY = "h6t9x2q8";
const YES_NO = [
["yes", "Yes"],
["no", "No"],
];
const POLLS = [
// Trick question — every number is wrong, nobody actually knows.
{
id: "count",
q: "How many politicians are there in the world?",
options: [
["100k", "~100,000"],
["1m", "~1 million"],
["10m", "~10 million"],
],
},
// The definition problem: the same question, harder and harder to answer.
{
id: "president",
q: "Is the President of Uganda a politician?",
options: YES_NO,
},
{
id: "mayor",
q: "Is the mayor of a small village a politician?",
options: YES_NO,
},
{
id: "centralbanker",
q: "Is a central bank governor a politician?",
options: YES_NO,
},
{
id: "judge",
q: "Is a Supreme Court judge a politician?",
options: YES_NO,
},
{
id: "spouse",
q: "Is a head of state's spouse a politician?",
options: YES_NO,
},
];
function pollById(qid) {
return POLLS.find((p) => p.id === qid);
}