@@ -21,8 +21,13 @@ case object Handout extends Plugin with Websockets {
21
21
var active = - 1
22
22
var max = 0
23
23
24
+ // block requests to a certain slide if it was not yet seen
24
25
deck.on(" slide" , (e : BespokeEvent ) ⇒ e.index <= max)
26
+
27
+ // block requests to the next slide if it was not yet seen
25
28
deck.on(" next" , (e : BespokeEvent ) ⇒ e.index < max)
29
+
30
+ // block requests to a certain slide if it was not yet seen
26
31
deck.on(" activate" , (e : BespokeEvent ) ⇒ (e.index <= max) && {
27
32
Toastr .clear()
28
33
active = e.index
@@ -33,16 +38,26 @@ case object Handout extends Plugin with Websockets {
33
38
val data = TypedArrayBuffer .wrap(wsMsg.data.asInstanceOf [ArrayBuffer ])
34
39
val message = unpickler.fromBytes(data)
35
40
message match {
41
+
42
+ // next is only processed if the handout is on the correct slide
36
43
case BespokeMessage .Next (n) if n == active ⇒
37
44
max = js.Math .max(n, max)
38
45
deck.next()
46
+
47
+ // prev is only processed if the handout is on the correct slide
39
48
case BespokeMessage .Prev (n) if n == active ⇒
40
49
max = js.Math .max(n, max)
41
50
deck.prev()
42
- case BespokeMessage .Slide (n) if n != active ⇒
51
+
52
+ // slide is always processed, as it signals a forced jump by the presenter
53
+ case BespokeMessage .Slide (n) if n != active ⇒
43
54
max = js.Math .max(n, max)
44
55
Toastr .remove()
45
56
deck.slide(n)
57
+
58
+ // activate happens when the presenter proceeds to the next slide.
59
+ // it is only processed when the target is not already the current slide
60
+ // and it only applies automatically if the slide would be the next one
46
61
case BespokeMessage .Activate (n) if n != active ⇒
47
62
max = js.Math .max(n, max)
48
63
val delta = n - previousPresenter
@@ -52,13 +67,20 @@ case object Handout extends Plugin with Websockets {
52
67
} else toast(active, n) {
53
68
deck.slide(n)
54
69
}
70
+
71
+ // save which page the presenter moved away from to determine the
72
+ // direction they are going
55
73
case BespokeMessage .Deactivate (n) ⇒
56
74
previousPresenter = n
75
+
76
+ // connect signals a new presenter, so reset everything to zero
57
77
case BespokeMessage .Connect ⇒
58
78
max = 0
59
79
active = 0
60
80
deck.slide(0 )
61
81
Toastr .clear()
82
+
83
+ // don't handle other events (and don't fail when they arrive)
62
84
case otherwise ⇒
63
85
}
64
86
}
0 commit comments