aboutsummaryrefslogtreecommitdiff
path: root/pointless/viewer/stage.js
blob: fa984fe4e40cf229ba4e648156c75fe75a721f80 (plain)
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
/*
 * stage.js
 * Part of Pointless Viewer, a Beamer presentation viewer
 * Copyright 2018 Pacien TRAN-GIRARD
 * License: GNU GPL v3
 */

"use strict";

class Stage {
  constructor(onReady, onNext, onPrevious) {
    this.onNext = onNext;
    this.onPrevious = onPrevious;
    this.projector = window.open(window.location.href);
    this.audienceScreen = null;
    this.presenterScreen = null;

    var self = this;
    this.projector.addEventListener("load", function() {
      self.audienceScreen = new Screen(self.projector, false);
      self.presenterScreen = new Screen(window, true);
      onReady();
    });

    this._registerEventHandler(window);
    this._registerEventHandler(this.projector);
  }

  setPage(page) {
    this.audienceScreen.setPage(page);
    this.presenterScreen.setPage(page);
  }

  _registerEventHandler(window) {
    var self = this;
    window.addEventListener("keypress", function(event) {
      self._onCommand(event);
    })
  }

  _onCommand(keyboardEvent) {
    switch (keyboardEvent.key) {
      case "Enter":
      case " ":
      case "ArrowRight":
      case "n":
        return this.onNext();

      case "ArrowLeft":
      case "p":
        return this.onPrevious();
    }
  }
}