diff options
author | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-08-10 17:28:37 +0200 |
commit | e7bf5952d0729b37e677168b6e8fbd1ce58ed1a2 (patch) | |
tree | 189988e3e272b806262d1df6b87f1da089ef4af8 /point/binding | |
parent | a32e898c8d7ad3774f5654e88bb24d5c26482137 (diff) | |
download | whatsthepoint-master.tar.gz |
Diffstat (limited to 'point/binding')
-rw-r--r-- | point/binding/keyboard.js | 70 | ||||
-rw-r--r-- | point/binding/network.js | 40 | ||||
-rw-r--r-- | point/binding/speech.js | 89 | ||||
-rw-r--r-- | point/binding/touch.js | 93 |
4 files changed, 292 insertions, 0 deletions
diff --git a/point/binding/keyboard.js b/point/binding/keyboard.js new file mode 100644 index 0000000..14eabc2 --- /dev/null +++ b/point/binding/keyboard.js | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" 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 | * "What's The Point" 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 <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["control/control"], function (control) { | ||
20 | |||
21 | var keyboard = { | ||
22 | |||
23 | KEYCODE: { | ||
24 | BACKSPACE: 8, | ||
25 | ENTER: 13, | ||
26 | SPACE: 32, | ||
27 | END: 35, | ||
28 | HOME: 36, | ||
29 | LEFT: 37, | ||
30 | UP: 38, | ||
31 | RIGHT: 39, | ||
32 | DOWN: 40, | ||
33 | }, | ||
34 | |||
35 | init: function (settings) { | ||
36 | this.bindEvent(); | ||
37 | }, | ||
38 | |||
39 | translate: function (keyCode) { | ||
40 | var gotoEvent; | ||
41 | switch (keyCode) { | ||
42 | case this.KEYCODE.LEFT: | ||
43 | case this.KEYCODE.BACKSPACE: | ||
44 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.PREVIOUS_SLIDE); | ||
45 | |||
46 | case this.KEYCODE.RIGHT: | ||
47 | case this.KEYCODE.ENTER: | ||
48 | case this.KEYCODE.SPACE: | ||
49 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.NEXT_SLIDE); | ||
50 | |||
51 | case this.KEYCODE.HOME: | ||
52 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.FIRST_SLIDE); | ||
53 | |||
54 | case this.KEYCODE.END: | ||
55 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.LAST_SLIDE); | ||
56 | } | ||
57 | |||
58 | }, | ||
59 | |||
60 | bindEvent: function () { | ||
61 | document.addEventListener("keydown", function (keydownEvent) { | ||
62 | // TODO: ignore if focus in form | ||
63 | keyboard.translate(keydownEvent.keyCode); | ||
64 | }); | ||
65 | }, | ||
66 | }; | ||
67 | |||
68 | return keyboard; | ||
69 | |||
70 | }); | ||
diff --git a/point/binding/network.js b/point/binding/network.js new file mode 100644 index 0000000..11cf58a --- /dev/null +++ b/point/binding/network.js | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" 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 | * "What's The Point" 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 <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["control/control", "libs/webcastor/webcastor"], function (control, webcastor) { | ||
20 | |||
21 | var network = { | ||
22 | |||
23 | init: function (settings) { | ||
24 | webcastor.init(settings, function (socket) { | ||
25 | network.bindEvents(); | ||
26 | }); | ||
27 | }, | ||
28 | |||
29 | /* network -> local */ | ||
30 | bindEvents: function () { | ||
31 | webcastor.on("message", function (message) { | ||
32 | var event = JSON.parse(message); | ||
33 | control.dispatchEvent(event.event, event.eventDetail, false); | ||
34 | }); | ||
35 | }, | ||
36 | }; | ||
37 | |||
38 | return network; | ||
39 | |||
40 | }); | ||
diff --git a/point/binding/speech.js b/point/binding/speech.js new file mode 100644 index 0000000..41f5914 --- /dev/null +++ b/point/binding/speech.js | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" 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 | * "What's The Point" 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 <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["control/control"], function (control) { | ||
20 | |||
21 | var speech = { | ||
22 | |||
23 | init: function (settings) { | ||
24 | if ("speechRecognition" in window || "webkitSpeechRecognition" in window) { | ||
25 | var recognition = new webkitSpeechRecognition(); | ||
26 | |||
27 | recognition.continuous = true; | ||
28 | recognition.interimResults = true; | ||
29 | recognition.lang = settings.speechSettings.lang; | ||
30 | |||
31 | recognition.onresult = this.onResult; | ||
32 | |||
33 | recognition.onend = function () { | ||
34 | recognition.start(); | ||
35 | }; | ||
36 | |||
37 | recognition.start(); | ||
38 | } | ||
39 | |||
40 | this.sleepDelay = 1500; | ||
41 | this.wakeupTime = 0; | ||
42 | |||
43 | this.command = { | ||
44 | NEXT_SLIDE: settings.speechSettings.keywords.NEXT_SLIDE, | ||
45 | PREVIOUS_SLIDE: settings.speechSettings.keywords.PREVIOUS_SLIDE, | ||
46 | }; | ||
47 | }, | ||
48 | |||
49 | onResult: function (speechEvent) { | ||
50 | var result = event.results[event.resultIndex]; | ||
51 | |||
52 | if (result.isFinal) { | ||
53 | return; | ||
54 | } | ||
55 | |||
56 | var sentence = result[0].transcript.split(" "); | ||
57 | var command = sentence[sentence.length - 1]; | ||
58 | speech.processCommand(command); | ||
59 | }, | ||
60 | |||
61 | processCommand: function (speechCommand) { | ||
62 | if (Date.now() < speech.wakeupTime) { | ||
63 | return; | ||
64 | } | ||
65 | |||
66 | var command = speech.translateCommand(speechCommand); | ||
67 | |||
68 | if (command === undefined) { | ||
69 | return; | ||
70 | } | ||
71 | |||
72 | speech.wakeupTime = Date.now() + speech.sleepDelay; | ||
73 | control.dispatchEvent(control.EVENT.GOTO, control.GOTO[command]); | ||
74 | }, | ||
75 | |||
76 | translateCommand: function (speechCommand) { | ||
77 | for (var command in speech.command) { | ||
78 | for (var index in speech.command[command]) { | ||
79 | if (speechCommand.indexOf(speech.command[command][index]) > -1) { | ||
80 | return command; | ||
81 | } | ||
82 | } | ||
83 | } | ||
84 | }, | ||
85 | }; | ||
86 | |||
87 | return speech; | ||
88 | |||
89 | }); | ||
diff --git a/point/binding/touch.js b/point/binding/touch.js new file mode 100644 index 0000000..a09d5fd --- /dev/null +++ b/point/binding/touch.js | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" 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 | * "What's The Point" 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 <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["libs/hammerjs/hammer.min", "control/control"], function (hammer, control) { | ||
20 | |||
21 | var touch = { | ||
22 | |||
23 | ACTION: { | ||
24 | SWIPE: "swipe", | ||