Skip to content

Commit ed1e586

Browse files
committed
websocket frontend
1 parent 086f537 commit ed1e586

24 files changed

+1676
-419
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.idea
12
.pio
23
.vscode
34

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ This thing is to connect a LED-Lamp (with up to 16 channels and 4096 steps resol
9191
- [ ] Add new Images.
9292
- 'Homepage' and logo for embedded server, Diode and Poti or something like that.
9393
- [ ] Logo.
94-
- [ ] Webapp backend.
95-
- [ ] Webapp frontend.
94+
- [X] Webapp backend.
95+
- [X] Webapp frontend.
96+
- [ ] Connection indicator.
97+
- [ ] Documentation (screenshots).
9698
- Smart Config [Expressiv doc](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/network/esp_smartconfig.html), [Google](https://lmgtfy.com/?q=esp32+smartconfig), [Other](https://www.switchdoc.com/2018/06/tutorial-esp32-bc24-provisioning-for-wifi/)
9799
- Art-Net (<https://en.wikipedia.org/wiki/Art-Net>).
98100
- [X] Implementation.
@@ -102,13 +104,13 @@ This thing is to connect a LED-Lamp (with up to 16 channels and 4096 steps resol
102104
- [ ] Port configuration.
103105
- [ ] Send username, password and port on mqtt connection.
104106
- Timer.
105-
- [X] Implement
107+
- [X] Implementation.
106108
- [X] for periodic status updates.
107109
- [ ] Configuration of Status Update period.
108110
- [X] ~~~SSL Connections~~~ (possible?) Not possible.
109111
- Dimming between different light-values with given time.
110112
- [ ] Linear (simple).
111-
- [ ] S-curve or log or something like that what looks nice and smooth.
113+
- [ ] S-curve or log or something like that - what looks nice and smooth.
112114
113115
#### 1.5.1.2. Bugs
114116
@@ -120,7 +122,7 @@ This thing is to connect a LED-Lamp (with up to 16 channels and 4096 steps resol
120122
- [X] Analyze.
121123
- [X] Fix. Hack -> see https://github.com/espressif/arduino-esp32/issues/2501
122124
- [X] ~~~CSS tuning~~~. No access to the page generators CSS.
123-
- [ ] Image from an undestroyed ESP Node....
125+
- [ ] Picture from an undestroyed ESP Node....
124126
125127
### 1.5.2. Hardware
126128

frontend/gulpfile.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const {src, dest, series, parallel, watch} = require('gulp');
22

33
const fs = require('fs');
44
const path = require('path');
5+
const httpProxy = require('http-proxy');
56

67
const g = {
78
gzip: require('gulp-gzip'),
@@ -14,7 +15,8 @@ const g = {
1415
clean: require('gulp-clean'),
1516
concat: require('gulp-concat'),
1617
mergeStream: require('merge-stream'),
17-
manifest: require('gulp-manifest3')
18+
manifest: require('gulp-manifest3'),
19+
plumber: require('gulp-plumber')
1820
// const htmlreplace = require('gulp-html-replace');
1921
};
2022
g.sass.compiler = require('node-sass');
@@ -45,6 +47,7 @@ const config = {
4547
function jsTask() {
4648
return g.pipeline(
4749
src(path.posix.join(config.srcDir, '*.js')),
50+
g.plumber(),
4851
g.concat('app.js'),
4952
dest(config.distDir),
5053
g.sourcemaps.init(),
@@ -57,6 +60,7 @@ function jsTask() {
5760
function cssTask() {
5861
return g.pipeline(
5962
src(path.posix.join(config.srcDir, '*.scss')),
63+
g.plumber(),
6064
g.sourcemaps.init(),
6165
g.sass().on('error', g.sass.logError),
6266
g.concat('app.css'),
@@ -70,6 +74,7 @@ function cssTask() {
7074
function htmlTask() {
7175
return g.pipeline(
7276
src(path.posix.join(config.srcDir, '*.html')),
77+
g.plumber(),
7378
dest(config.distDir),
7479
g.htmlmin({collapseWhitespace: true}),
7580
g.gzip({gzipOptions: {level: 9}}),
@@ -80,6 +85,7 @@ function htmlTask() {
8085
function vendorJsTask() {
8186
return g.pipeline(
8287
src(path.posix.join(config.vendorDir, '*.js')),
88+
g.plumber(),
8389
g.sourcemaps.init(),
8490
g.concat('vendor.js'),
8591
dest(config.distDir),
@@ -93,6 +99,7 @@ function vendorJsTask() {
9399
function vendorCssTask() {
94100
return g.pipeline(
95101
src(path.posix.join(config.vendorDir, '*.css')),
102+
g.plumber(),
96103
g.sourcemaps.init(),
97104
g.concat('vendor.css'),
98105
dest(config.distDir),
@@ -109,18 +116,21 @@ function copyTask() {
109116
path.posix.join(config.distDir, '*.js.gz'),
110117
path.posix.join(config.distDir, 'appcache.manifest')
111118
]),
119+
g.plumber(),
112120
dest(config.targetDir));
113121
}
114122

115123
function cleanDistTask() {
116124
return g.pipeline(
117125
src(path.posix.join(config.distDir, '**/*'), {read: false, allowEmpty: true}),
126+
g.plumber(),
118127
g.clean());
119128
}
120129

121130
function cleanTargetTask() {
122131
return g.pipeline(
123132
src(config.targetDir, {read: false, allowEmpty: true}),
133+
g.plumber(),
124134
g.clean({force: true}));
125135
}
126136

@@ -157,7 +167,7 @@ function fileListTask(cb) {
157167
const symbol = relativePath.replace(/\.|\/|\\|-/g, '_');
158168
const startSymbol = symbol + '_start';
159169
const endSymbol = symbol + '_end';
160-
const mime = util.mimeTypes.lookup(ext);
170+
const mime = util.mimeTypes.lookup(rawName);
161171

162172
// file.h
163173
fileHContent += '// ' + relativePath + '\n';
@@ -167,7 +177,7 @@ function fileListTask(cb) {
167177
// webserver.h
168178
webserverHContent += 'webServer_.on("/' + (rawName === 'index.html' ? '' : rawName) + '", [this]() {\n';
169179
webserverHContent += ' webServer_.sendHeader("Content-Encoding", "gzip");\n';
170-
webserverHContent += ' webServer_.send_P(200, "' + mime + '", ' + startSymbol + ', ' + endSymbol + ' - ' + startSymbol + ' - 1);\n';
180+
webserverHContent += ' webServer_.send_P(200, "' + mime + '", ' + startSymbol + ', ' + endSymbol + ' - ' + startSymbol + ');\n';
171181
webserverHContent += '});\n\n';
172182

173183
// plaformio.ini
@@ -195,11 +205,24 @@ function reloadTask(cb) {
195205
}
196206

197207
function watchTask() {
198-
server.init({
208+
let options = {
199209
server: {
200210
baseDir: config.distDir,
201211
}
202-
});
212+
};
213+
214+
let arguments = require('commander').option('-p --proxy <target>', 'backend').parse(process.argv);
215+
console.log("args", arguments.opts());
216+
217+
if (arguments.proxy) {
218+
console.log("Start WS proxy @ ", arguments.proxy);
219+
httpProxy.createServer({
220+
target: arguments.proxy,
221+
ws: true
222+
}).listen(81);
223+
}
224+
225+
server.init(options);
203226
watch(path.posix.join(config.srcDir, '*.html'), series(htmlTask, pwaTask, copyTask, reloadTask));
204227
watch(path.posix.join(config.srcDir, '*.js'), series(jsTask, pwaTask, copyTask, reloadTask));
205228
watch(path.posix.join(config.srcDir, '*.scss'), series(cssTask, pwaTask, copyTask, reloadTask));
@@ -219,6 +242,7 @@ exports.vjsc = vendorJsTask;
219242
exports.copy = copyTask;
220243
exports.files = fileListTask;
221244
exports.pwa = pwaTask;
245+
exports.watch = watchTask;
222246
exports.build = series(parallel(cleanDistTask, cleanTargetTask), parallel(jsTask, htmlTask, cssTask, vendorCssTask, vendorJsTask), pwaTask, copyTask, fileListTask);
223247

224248
exports.default = exports.build;

frontend/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
"main": "index.js",
66
"scripts": {
77
"build": "gulp",
8-
"start": "gulp develop"
8+
"develop": "gulp develop"
99
},
1010
"author": "Lars Brandt",
1111
"license": "LGPL-3.0-or-later",
1212
"dependencies": {
13-
"jquery.rsSliderLens": "^1.0.5"
1413
},
1514
"devDependencies": {
1615
"browser-sync": "^2.26.7",
16+
"commander": "^4.0.1",
1717
"del": "^5.1.0",
1818
"gulp": "4.0.2",
1919
"gulp-clean": "^0.4.0",
@@ -24,9 +24,11 @@
2424
"gulp-htmlmin": "^5.0.1",
2525
"gulp-livereload": "^4.0.2",
2626
"gulp-manifest3": "^0.1.2",
27+
"gulp-plumber": "^1.2.1",
2728
"gulp-sass": "^4.0.2",
2829
"gulp-sourcemaps": "^2.6.5",
2930
"gulp-terser": "^1.2.0",
31+
"http-proxy": "^1.18.0",
3032
"merge-stream": "^2.0.0",
3133
"mime-types": "^2.1.25",
3234
"node-sass": "^4.13.0",

frontend/src/0050_utils.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const utils = {};
2+
3+
utils.init = () => {
4+
// nothing to do
5+
};
6+
7+
// thx to https://gist.github.com/jed/982883
8+
utils.hex = function () {
9+
let hex = [];
10+
11+
for (let i = 0; i < 256; i++) {
12+
hex[i] = (i < 16 ? '0' : '') + (i).toString(16);
13+
}
14+
return hex;
15+
}();
16+
17+
utils.uuid = () => {
18+
let r = crypto.getRandomValues(new Uint8Array(16));
19+
20+
r[6] = r[6] & 0x0f | 0x40;
21+
r[8] = r[8] & 0x3f | 0x80;
22+
23+
return (
24+
utils.hex[r[0]] +
25+
utils.hex[r[1]] +
26+
utils.hex[r[2]] +
27+
utils.hex[r[3]] +
28+
"-" +
29+
utils.hex[r[4]] +
30+
utils.hex[r[5]] +
31+
"-" +
32+
utils.hex[r[6]] +
33+
utils.hex[r[7]] +
34+
"-" +
35+
utils.hex[r[8]] +
36+
utils.hex[r[9]] +
37+
"-" +
38+
utils.hex[r[10]] +
39+
utils.hex[r[11]] +
40+
utils.hex[r[12]] +
41+
utils.hex[r[13]] +
42+
utils.hex[r[14]] +
43+
utils.hex[r[15]]
44+
);
45+
};

0 commit comments

Comments
 (0)