virtual-keypad 5.14.2 → 5.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,170 +1,171 @@
1
- <!DOCTYPE html>
2
- <html style="background-color: #eee">
3
- <head>
4
- <meta charset="utf-8" />
5
- <title>Receiver</title>
6
- <meta name="description" content="" />
7
- <meta name="viewport" content="width=device-width, initial-scale=1" />
8
- <!-- TODO include JS and css from webpack bundle -->
9
- <!-- <script src="../dist/main.js"></script> -->
10
- <script src="./main.js"></script>
11
- <link
12
- rel="stylesheet"
13
- href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
14
- integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
15
- crossorigin="anonymous"
16
- />
17
- <!-- <script src="https://unpkg.com/virtual-keypad"></script> -->
18
- <style>
19
- * {
20
- outline: none;
21
- vertical-align: baseline;
22
- box-sizing: border-box;
23
- text-rendering: optimizeLegibility;
24
- -webkit-font-smoothing: auto;
25
- -moz-osx-font-smoothing: grayscale;
26
- font-kerning: normal;
27
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
28
- Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
29
- color: #333;
30
- }
31
-
32
- html,
33
- body {
34
- font-size: calc(1em + 1vw);
35
- margin: 0;
36
- padding: 0;
37
- overflow: hidden;
38
- }
39
- #container {
40
- height: 100vh;
41
- width: 100vw;
42
- display: grid;
43
- grid-template-rows: 1fr 3fr;
44
- grid-template-columns: auto;
45
- padding: 1em;
46
- }
47
- #display-and-buttons {
48
- display: flex;
49
- min-width: 50vh;
50
- overflow-y: auto;
51
- border: 3px solid black;
52
- border-radius: 10px;
53
- }
54
- #display {
55
- overflow-x: wrap;
56
- word-break: break-all;
57
- padding: 0;
58
- width: 70%;
59
- /* max-height: 100%; */
60
- overflow-y: auto;
61
- }
62
- #display-control-buttons {
63
- display: flex;
64
- flex-direction: column;
65
- width: 30%;
66
- padding: 2rem;
67
- }
68
- </style>
69
- </head>
70
- <body>
71
- <div id="container">
72
- <div id="info">
73
- <h1>Set up keypad</h1>
74
- <p>
75
- Scan the QR code from the device you'd like to use as a keypad. This
76
- receiver just echoes keypresses; provide a different on-data callback to
77
- customize how the receiver handles keypresses.
78
- </p>
79
- </div>
80
- <div id="display-and-buttons">
81
- <div id="display"></div>
82
- <div id="display-control-buttons">
83
- <button id="toggle-disable" style="display: none">Disable keys.</button>
84
- <button id="randomize-alphabet" style="display: none">
85
- Randomize character set.
86
- </button>
87
- </div>
88
- </div>
89
- </div>
90
- <script>
91
- if (window.location !== window.parent.location) {
92
- // The page is in an iframe, per https://tommcfarlin.com/check-if-a-page-is-in-an-iframe/
93
- document.getElementById("info").style.display = "none";
94
- }
95
- let starting_alphabet = [
96
- ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".split(""),
97
- ];
98
- const ctrl = ["RETURN", "SPACE"];
99
- let alphabet = [...starting_alphabet, ...ctrl];
100
-
101
- let keypad_options = {
102
- // Specify a 'keypadUrl' field to redirect to a keypad hosted elsewhere
103
- // FUTURE should be able to have a visual keypress or not from here
104
- alphabet: alphabet, // Set of symbols to display; array perfered
105
- font: "Arial", // Supported font, in which to display letters
106
- targetElementId: "display", // id of the the div where messages should be displayed
107
- visualResponseFeedback: false,
108
- onErrorReconnectMessage: "Custom error message",
109
- };
110
- let ondata_callback = (data) => {
111
- receiver.displayUpdate(`[data] ${data.response}`, true);
112
- console.log(data);
113
- };
114
- const disableSomeKeys = (ev) => {
115
- const keysToDisable = randomSelection(alphabet);
116
- if (ev.target.toggleAttribute("keys-disabled")) {
117
- receiver.disableKeys(keysToDisable);
118
- ev.target.innerText = "Enable keys.";
119
- } else {
120
- receiver.enableKeys();
121
- ev.target.innerText = "Disable keys.";
122
- }
123
- };
124
- const changeAlphabet = (ev) => {
125
- const sampledAlphabet = [
126
- ...randomSelection(starting_alphabet),
127
- ...ctrl,
128
- ];
129
- if (ev.target.toggleAttribute("keys-changed")) {
130
- // Reset disabled keys on alphabet change, easier than persisting disabled for this demo page
131
- ev.target.toggleAttribute("keys-disabled");
132
- ev.target.innerText = "Disable keys.";
133
-
134
- alphabet = sampledAlphabet;
135
- ev.target.innerText = "Reset alphabet.";
136
- } else {
137
- alphabet = [...starting_alphabet, ...ctrl];
138
- ev.target.innerText = "Randomize alphabet.";
139
- }
140
- receiver.update(alphabet);
141
- };
142
- var receiver = new virtualKeypad.Receiver(
143
- keypad_options,
144
- ondata_callback,
145
- () => {
146
- const disableButton = document.getElementById("toggle-disable");
147
- disableButton.style.display = "block";
148
- disableButton.onclick = disableSomeKeys;
149
- const changeAlphabetButton =
150
- document.getElementById("randomize-alphabet");
151
- changeAlphabetButton.style.display = "block";
152
- changeAlphabetButton.onclick = changeAlphabet;
153
-
154
- console.log("RECEIV Handshake complete");
155
- },
156
- () => console.log("RECEIV Connection connected"),
157
- () => console.log("RECEIV Connection closed"),
158
- () => console.log("RECEIV Connection error")
159
- );
160
- const randomSelection = (source) => {
161
- const maybe = () => Math.random() > 0.5;
162
- const selection = [];
163
- for (let i = 0; i < source.length; i++) {
164
- if (maybe()) selection.push(source[i]);
165
- }
166
- return selection;
167
- };
168
- </script>
169
- </body>
170
- </html>
1
+ <!DOCTYPE html>
2
+ <html style="background-color: #eee">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Receiver</title>
6
+ <meta name="description" content="" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+ <!-- TODO include JS and css from webpack bundle -->
9
+ <!-- <script src="../dist/main.js"></script> -->
10
+ <script src="./main.js"></script>
11
+ <link
12
+ rel="stylesheet"
13
+ href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
14
+ integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
15
+ crossorigin="anonymous"
16
+ />
17
+ <!-- <script src="https://unpkg.com/virtual-keypad"></script> -->
18
+ <style>
19
+ * {
20
+ outline: none;
21
+ vertical-align: baseline;
22
+ box-sizing: border-box;
23
+ text-rendering: optimizeLegibility;
24
+ -webkit-font-smoothing: auto;
25
+ -moz-osx-font-smoothing: grayscale;
26
+ font-kerning: normal;
27
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
28
+ Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
29
+ color: #333;
30
+ }
31
+
32
+ html,
33
+ body {
34
+ font-size: calc(1em + 1vw);
35
+ margin: 0;
36
+ padding: 0;
37
+ overflow: hidden;
38
+ }
39
+ #container {
40
+ height: 100vh;
41
+ width: 100vw;
42
+ display: grid;
43
+ grid-template-rows: 1fr 3fr;
44
+ grid-template-columns: auto;
45
+ padding: 1em;
46
+ }
47
+ #display-and-buttons {
48
+ display: flex;
49
+ min-width: 50vh;
50
+ overflow-y: auto;
51
+ border: 3px solid black;
52
+ border-radius: 10px;
53
+ }
54
+ #display {
55
+ overflow-x: wrap;
56
+ word-break: break-all;
57
+ padding: 0;
58
+ width: 70%;
59
+ /* max-height: 100%; */
60
+ overflow-y: auto;
61
+ }
62
+ #display-control-buttons {
63
+ display: flex;
64
+ flex-direction: column;
65
+ width: 30%;
66
+ padding: 2rem;
67
+ }
68
+ </style>
69
+ </head>
70
+ <body>
71
+ <div id="container">
72
+ <div id="info">
73
+ <h1>Set up keypad</h1>
74
+ <p>
75
+ Scan the QR code from the device you'd like to use as a keypad. This
76
+ receiver just echoes keypresses; provide a different on-data callback to
77
+ customize how the receiver handles keypresses.
78
+ </p>
79
+ </div>
80
+ <div id="display-and-buttons">
81
+ <div id="display"></div>
82
+ <div id="display-control-buttons">
83
+ <button id="toggle-disable" style="display: none">Disable keys.</button>
84
+ <button id="randomize-alphabet" style="display: none">
85
+ Randomize character set.
86
+ </button>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ <script>
91
+ if (window.location !== window.parent.location) {
92
+ // The page is in an iframe, per https://tommcfarlin.com/check-if-a-page-is-in-an-iframe/
93
+ document.getElementById("info").style.display = "none";
94
+ }
95
+ let starting_alphabet = [
96
+ ..."ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789".split(""),
97
+ ];
98
+ const ctrl = ["RETURN", "SPACE", "SKIP BLOCK"];
99
+ let alphabet = [...starting_alphabet, ...ctrl];
100
+
101
+ let keypad_options = {
102
+ // Specify a 'keypadUrl' field to redirect to a keypad hosted elsewhere
103
+ // FUTURE should be able to have a visual keypress or not from here
104
+ alphabet: alphabet, // Set of symbols to display; array perfered
105
+ font: "Arial", // Supported font, in which to display letters
106
+ targetElementId: "display", // id of the the div where messages should be displayed
107
+ visualResponseFeedback: false,
108
+ onErrorReconnectMessage: "Custom error message",
109
+ controlButtons: ctrl,
110
+ };
111
+ let ondata_callback = (data) => {
112
+ receiver.displayUpdate(`[data] ${data.response}`, true);
113
+ console.log(data);
114
+ };
115
+ const disableSomeKeys = (ev) => {
116
+ const keysToDisable = randomSelection(alphabet);
117
+ if (ev.target.toggleAttribute("keys-disabled")) {
118
+ receiver.disableKeys(keysToDisable);
119
+ ev.target.innerText = "Enable keys.";
120
+ } else {
121
+ receiver.enableKeys();
122
+ ev.target.innerText = "Disable keys.";
123
+ }
124
+ };
125
+ const changeAlphabet = (ev) => {
126
+ const sampledAlphabet = [
127
+ ...randomSelection(starting_alphabet),
128
+ ...ctrl,
129
+ ];
130
+ if (ev.target.toggleAttribute("keys-changed")) {
131
+ // Reset disabled keys on alphabet change, easier than persisting disabled for this demo page
132
+ ev.target.toggleAttribute("keys-disabled");
133
+ ev.target.innerText = "Disable keys.";
134
+
135
+ alphabet = sampledAlphabet;
136
+ ev.target.innerText = "Reset alphabet.";
137
+ } else {
138
+ alphabet = [...starting_alphabet, ...ctrl];
139
+ ev.target.innerText = "Randomize alphabet.";
140
+ }
141
+ receiver.update(alphabet);
142
+ };
143
+ var receiver = new virtualKeypad.Receiver(
144
+ keypad_options,
145
+ ondata_callback,
146
+ () => {
147
+ const disableButton = document.getElementById("toggle-disable");
148
+ disableButton.style.display = "block";
149
+ disableButton.onclick = disableSomeKeys;
150
+ const changeAlphabetButton =
151
+ document.getElementById("randomize-alphabet");
152
+ changeAlphabetButton.style.display = "block";
153
+ changeAlphabetButton.onclick = changeAlphabet;
154
+
155
+ console.log("RECEIV Handshake complete");
156
+ },
157
+ () => console.log("RECEIV Connection connected"),
158
+ () => console.log("RECEIV Connection closed"),
159
+ () => console.log("RECEIV Connection error")
160
+ );
161
+ const randomSelection = (source) => {
162
+ const maybe = () => Math.random() > 0.5;
163
+ const selection = [];
164
+ for (let i = 0; i < source.length; i++) {
165
+ if (maybe()) selection.push(source[i]);
166
+ }
167
+ return selection;
168
+ };
169
+ </script>
170
+ </body>
171
+ </html>
package/dist/server.js CHANGED
@@ -1,66 +1,66 @@
1
- const express = require("express");
2
- const path = require("path");
3
- const { v4: uuidv4 } = require("uuid");
4
-
5
- var app = (module.exports = express());
6
- var server = "http://localhost:3000";
7
-
8
- // I got an error with line below if I didnt' add the extended property
9
- // Don't actually know if this should be set to true or false.
10
- // app.use(express.urlencoded({ extended: true }));
11
- // app.use(express.json());
12
-
13
- // app.use(express.static(path.join(__dirname, 'dist')));
14
-
15
- // Middleware to check we have all the params we need
16
- const checkParams = (req, res, next) => {
17
- let noID = !req.query.hasOwnProperty('peerID');
18
- if (noID) {
19
- console.log('No peerID given.'); // TODO Breaking! Serve error
20
- throw "No peerID given -- unable to connect to peer."
21
- // req.query.peerID = uuidv4(); // TEMPorary and only usable to test keypadClient
22
- }
23
-
24
- // // TODO check that all characters can be input as query params
25
- // const noAlphabet = !req.query.hasOwnProperty('alphabet');
26
- // if (noAlphabet) {
27
- // console.log('No alphabet given.');
28
- // req.query.alphabet = 'ABCDEFG';
29
- // }
30
-
31
- // // TODO check for valid fonts here
32
- // let noFont = !req.query.hasOwnProperty('font');
33
- // if (noFont) {
34
- // console.log('No alphabet given.');
35
- // req.query.font = 'Sloan';
36
- // }
37
- next();
38
- };
39
-
40
- // Link to the actual keypad
41
- // ie this is where the user will be sent (from the QR code) on their phone
42
- app.get('/keypad', checkParams, function (req, res) {
43
- res.render(path.join(__dirname, 'keypad.html'));
44
- });
45
- app.get('/receiver', function (req, res) {
46
- res.render(path.join(__dirname, 'receiver.html'));
47
- });
48
-
49
- app.use(function (err, req, res, next) {
50
- res.status(err.status || 500);
51
- res.send({
52
- error: err.message
53
- });
54
- });
55
-
56
- app.use(function (req, res) {
57
- res.status(404);
58
- res.send({
59
- error: "404 not found"
60
- });
61
- });
62
-
63
- if (!module.parent) {
64
- app.listen(3000);
65
- console.log('Express started on port 3000');
66
- }
1
+ const express = require("express");
2
+ const path = require("path");
3
+ const { v4: uuidv4 } = require("uuid");
4
+
5
+ var app = (module.exports = express());
6
+ var server = "http://localhost:3000";
7
+
8
+ // I got an error with line below if I didnt' add the extended property
9
+ // Don't actually know if this should be set to true or false.
10
+ // app.use(express.urlencoded({ extended: true }));
11
+ // app.use(express.json());
12
+
13
+ // app.use(express.static(path.join(__dirname, 'dist')));
14
+
15
+ // Middleware to check we have all the params we need
16
+ const checkParams = (req, res, next) => {
17
+ let noID = !req.query.hasOwnProperty('peerID');
18
+ if (noID) {
19
+ console.log('No peerID given.'); // TODO Breaking! Serve error
20
+ throw "No peerID given -- unable to connect to peer."
21
+ // req.query.peerID = uuidv4(); // TEMPorary and only usable to test keypadClient
22
+ }
23
+
24
+ // // TODO check that all characters can be input as query params
25
+ // const noAlphabet = !req.query.hasOwnProperty('alphabet');
26
+ // if (noAlphabet) {
27
+ // console.log('No alphabet given.');
28
+ // req.query.alphabet = 'ABCDEFG';
29
+ // }
30
+
31
+ // // TODO check for valid fonts here
32
+ // let noFont = !req.query.hasOwnProperty('font');
33
+ // if (noFont) {
34
+ // console.log('No alphabet given.');
35
+ // req.query.font = 'Sloan';
36
+ // }
37
+ next();
38
+ };
39
+
40
+ // Link to the actual keypad
41
+ // ie this is where the user will be sent (from the QR code) on their phone
42
+ app.get('/keypad', checkParams, function (req, res) {
43
+ res.render(path.join(__dirname, 'keypad.html'));
44
+ });
45
+ app.get('/receiver', function (req, res) {
46
+ res.render(path.join(__dirname, 'receiver.html'));
47
+ });
48
+
49
+ app.use(function (err, req, res, next) {
50
+ res.status(err.status || 500);
51
+ res.send({
52
+ error: err.message
53
+ });
54
+ });
55
+
56
+ app.use(function (req, res) {
57
+ res.status(404);
58
+ res.send({
59
+ error: "404 not found"
60
+ });
61
+ });
62
+
63
+ if (!module.parent) {
64
+ app.listen(3000);
65
+ console.log('Express started on port 3000');
66
+ }
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "virtual-keypad",
3
- "version": "5.14.2",
4
- "description": "User response at a distance. Simple utility to summon forth a virtual keypad webapp.",
5
- "main": "dist/main.js",
6
- "directories": {
7
- "example": "example",
8
- "bin": "dist"
9
- },
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "start": "webpack serve --open --config webpack.dev.js",
13
- "build": "webpack --config webpack.prod.js"
14
- },
15
- "keywords": [],
16
- "author": "Augustin Burchell <augustin.burchell@gmail.com> (https://aburchell.github.io/)",
17
- "license": "ISC",
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/EasyEyes/virtual-keypad"
21
- },
22
- "dependencies": {
23
- "peerjs": "^1.5.2",
24
- "qrcode": "^1.4.4",
25
- "uuid": "^8.3.2"
26
- },
27
- "devDependencies": {
28
- "css-loader": "^5.2.6",
29
- "file-loader": "^6.2.0",
30
- "style-loader": "^2.0.0",
31
- "webpack": "^5.40.0",
32
- "webpack-cli": "^4.7.2",
33
- "webpack-dev-server": "^4.13.2",
34
- "webpack-merge": "^5.8.0"
35
- }
36
- }
1
+ {
2
+ "name": "virtual-keypad",
3
+ "version": "5.15.0",
4
+ "description": "User response at a distance. Simple utility to summon forth a virtual keypad webapp.",
5
+ "main": "dist/main.js",
6
+ "directories": {
7
+ "example": "example",
8
+ "bin": "dist"
9
+ },
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "start": "webpack serve --open --config webpack.dev.js",
13
+ "build": "webpack --config webpack.prod.js"
14
+ },
15
+ "keywords": [],
16
+ "author": "Augustin Burchell <augustin.burchell@gmail.com> (https://aburchell.github.io/)",
17
+ "license": "ISC",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/EasyEyes/virtual-keypad"
21
+ },
22
+ "dependencies": {
23
+ "peerjs": "^1.5.2",
24
+ "qrcode": "^1.4.4",
25
+ "uuid": "^8.3.2"
26
+ },
27
+ "devDependencies": {
28
+ "css-loader": "^5.2.6",
29
+ "file-loader": "^6.2.0",
30
+ "style-loader": "^2.0.0",
31
+ "webpack": "^5.40.0",
32
+ "webpack-cli": "^4.7.2",
33
+ "webpack-dev-server": "^4.13.2",
34
+ "webpack-merge": "^5.8.0"
35
+ }
36
+ }