diff options
Diffstat (limited to 'beamer/viewer/stage/stage.js')
-rw-r--r-- | beamer/viewer/stage/stage.js | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/beamer/viewer/stage/stage.js b/beamer/viewer/stage/stage.js index 201f7b4..763f3b2 100644 --- a/beamer/viewer/stage/stage.js +++ b/beamer/viewer/stage/stage.js | |||
@@ -1,19 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * Beamer Viewer, a web-based PDF presentation viewer | 2 | * Beamer Viewer, a web-based PDF presentation viewer |
3 | * Copyright (C) 2018 Pacien TRAN-GIRARD | 3 | * Copyright 2018-2024 Pacien TRAN-GIRARD |
4 | * | 4 | * SPDX-License-Identifier: EUPL-1.2 |
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
17 | */ | 5 | */ |
18 | 6 | ||
19 | "use strict"; | 7 | "use strict"; |
@@ -23,23 +11,25 @@ class Stage { | |||
23 | this.audienceScreen = null; | 11 | this.audienceScreen = null; |
24 | this.presenterScreen = null; | 12 | this.presenterScreen = null; |
25 | 13 | ||
26 | this.projector = window.open(window.location.href, "_blank", "toolbar=0,location=0,menubar=0"); | 14 | this.onReady = onReady; |
27 | if (this.projector == null) | ||
28 | alert("Please allow pop-ups, then refresh this page."); | ||
29 | |||
30 | const self = this; | ||
31 | this.projector.addEventListener("load", function() { | ||
32 | self.audienceScreen = new Screen(self.projector, false, false); | ||
33 | self.presenterScreen = new Screen(window, true, true); | ||
34 | self._watchDetach(); | ||
35 | onReady(); | ||
36 | }); | ||
37 | |||
38 | this.eventHandlers = [ | 15 | this.eventHandlers = [ |
39 | new KeyboardEventHandler(onNext, onPrevious), | 16 | new KeyboardEventHandler(onNext, onPrevious), |
40 | new MouseClickEventHandler(onNext, onPrevious), | 17 | new MouseClickEventHandler(onNext, onPrevious), |
41 | new TouchSwipeEventHandler(onNext, onPrevious) | 18 | new TouchSwipeEventHandler(onNext, onPrevious) |
42 | ]; | 19 | ]; |
20 | } | ||
21 | |||
22 | start() { | ||
23 | this.projector = window.open(window.location.href, "_blank", "toolbar=0,location=0,menubar=0"); | ||
24 | if (this.projector == null) | ||
25 | alert("Please allow pop-ups, then refresh this page."); | ||
26 | |||
27 | this.projector.addEventListener("load", () => { | ||
28 | this.audienceScreen = new Screen(this.projector, false, false); | ||
29 | this.presenterScreen = new Screen(window, true, true); | ||
30 | this._watchDetach(); | ||
31 | this.onReady(); | ||
32 | }); | ||
43 | 33 | ||
44 | this._registerEventHandler(window); | 34 | this._registerEventHandler(window); |
45 | this._registerEventHandler(this.projector); | 35 | this._registerEventHandler(this.projector); |
@@ -53,20 +43,18 @@ class Stage { | |||
53 | _registerEventHandler(window) { | 43 | _registerEventHandler(window) { |
54 | if (window == null) return; | 44 | if (window == null) return; |
55 | 45 | ||
56 | this.eventHandlers.forEach(function(eventHandler) { | 46 | this.eventHandlers |
57 | eventHandler.register(window); | 47 | .forEach(eventHandler => eventHandler.register(window)); |
58 | }); | ||
59 | } | 48 | } |
60 | 49 | ||
61 | _watchDetach() { | 50 | _watchDetach() { |
62 | const self = this; | 51 | window.addEventListener("beforeunload", () => |
63 | window.addEventListener("beforeunload", function() { | 52 | this._setMessage(this.projector, "Controller detached") |
64 | self._setMessage(self.projector, "Controller detached"); | 53 | ); |
65 | }); | ||
66 | 54 | ||
67 | this.projector.addEventListener("beforeunload", function() { | 55 | this.projector.addEventListener("beforeunload", () => |
68 | self._setMessage(window, "Viewer detached"); | 56 | this._setMessage(window, "Viewer detached") |
69 | }); | 57 | ); |
70 | } | 58 | } |
71 | 59 | ||
72 | _setMessage(window, message) { | 60 | _setMessage(window, message) { |