Merge all work on server with filmout features #77

Merged
mattmcw merged 12 commits from server into main 2023-02-26 02:16:29 +00:00
16 changed files with 127 additions and 33 deletions
Showing only changes of commit c9bcb74a9f - Show all commits

View File

@ -145,7 +145,7 @@
can.style.width = `${window.innerHeight * arg.ratio}px` can.style.width = `${window.innerHeight * arg.ratio}px`
can.style.height = `${window.innerHeight}px` can.style.height = `${window.innerHeight}px`
} else { } else {
can.style.width = `${window.inneWidth}px` can.style.width = `${window.innerWidth}px`
can.style.height = `${window.innerWidth / arg.ratio}px` can.style.height = `${window.innerWidth / arg.ratio}px`
} }
} else { } else {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
/**
* Delay in an async/await function
*
* @param {integer} ms Milliseconds to delay for
*
* @returns {Promise} Promise to resolve after timeout
**/
declare function delay(ms: number): Promise<unknown>;

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,9 @@
"use strict"; "use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const promises_1 = require("fs/promises"); const promises_1 = require("fs/promises");
const Log = require("log"); const Log = require("log");
class Server { class Server {
@ -22,11 +26,16 @@ class Server {
} }
async init() { async init() {
this.log = await Log({ label: this.id }); this.log = await Log({ label: this.id });
await this.load();
await this.start();
} }
async load() { async load() {
this.http = express_1.default();
for (let tmpl of this.templates) { for (let tmpl of this.templates) {
tmpl.data = await promises_1.readFile(tmpl.path, 'utf8'); tmpl.data = await promises_1.readFile(tmpl.path, 'utf8');
} }
this.http.get('/', this.index.bind(this));
this.http.get('/client.js', this.script.bind(this));
this.log.info("Server assets loaded"); this.log.info("Server assets loaded");
} }
template(name, data) { template(name, data) {
@ -36,24 +45,37 @@ class Server {
} }
return html; return html;
} }
start() { async start() {
this.http.listen(function () { return new Promise(function (resolve, reject) {
this.httpd = this.http.listen(this.port, function () {
this.isActive = true; this.isActive = true;
this.log.inf(`Server started!`); this.log.info(`Server started!`);
this.log.info(`URL [ http://localhost:${this.port} ]`); this.log.info(`URL [ http://localhost:${this.port} ]`);
return resolve(true);
}.bind(this));
}.bind(this)); }.bind(this));
} }
stop() { stop() {
this.http.close(); return new Promise(function (resolve, reject) {
return this.httpd.close(function () {
this.isActive = false; this.isActive = false;
this.log.info(`Server stopped :(`); this.log.info(`Server stopped :(`);
}.bind(this));
}.bind(this));
} }
index(req, res, next) { index(req, res, next) {
const html = this.template('index', { PORT: `${this.port}` }); const html = this.template('index', { PORT: `${this.port}` });
this.log.info('GET /');
return res.send(html); return res.send(html);
} }
script(req, res, next) { script(req, res, next) {
const js = this.template('script', { PORT: `${this.wsPort}` }); const js = this.template('script', { PORT: `${this.wsPort}` });
res.contentType('text/javascript');
this.log.info('GET /script.js');
return res.send(js);
} }
} }
module.exports = function () {
return new Server();
};
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":";;AAGA,0CAAsC;AACtC,2BAA4B;AAa5B,MAAM,MAAM;IAiBX;QAhBQ,OAAE,GAAY,QAAQ,CAAA;QACvB,aAAQ,GAAa,KAAK,CAAA;QAEzB,cAAS,GAAsB;YACtC;gBACC,IAAI,EAAE,OAAO;gBACb,IAAI,EAAG,aAAa;aACpB;YACD;gBACC,IAAI,EAAG,QAAQ;gBACf,IAAI,EAAG,qBAAqB;aAC5B;SACD,CAAA;QAEO,SAAI,GAAY,IAAI,CAAA;QACpB,WAAM,GAAY,IAAI,CAAA;QAE7B,IAAI,CAAC,IAAI,EAAE,CAAA;IACZ,CAAC;IAED,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,KAAK,EAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED,KA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AI;QACH,OAAO,IAAI,OAAO,CAAC,UAAU,OAAkB,EAAE,MAAiB;YACjE,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;gBACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;gBACrB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;YACnC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACd,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAEd,CAAC;IAED,KAAK,CAAE,GAAa,EAAE,GAAc,EAAE,IAAe;QACpD,MAAM,IAAI,GAAY,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,IAAI,EAAG,GAAG,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACvE,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACtB,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACtB,CAAC;IACD,MAAM,CAAE,GAAa,EAAE,GAAc,EAAE,IAAe;QACrD,MAAM,EAAE,GAAY,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAG,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QACxE,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAA;QAClC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC/B,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACpB,CAAC;CACD;AAED,MAAM,CAAC,OAAO,GAAG;IAChB,OAAO,IAAI,MAAM,EAAE,CAAA;AACpB,CAAC,CAAA"}

View File

@ -39,6 +39,7 @@ let cmd;
let seq; let seq;
let capper; let capper;
let alert; let alert;
let server;
const cfg = require('./data/cfg.json') const cfg = require('./data/cfg.json')
@ -136,6 +137,7 @@ var init = async function () {
cmd = require('cmd')(cfg, proj, cam, light, alert, cam2, proj2, capper) cmd = require('cmd')(cfg, proj, cam, light, alert, cam2, proj2, capper)
seq = require('sequencer')(cfg, cmd, mainWindow.webContents) seq = require('sequencer')(cfg, cmd, mainWindow.webContents)
server = require('server')()
} }
app.on('ready', init) app.on('ready', init)

2
app/package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.7.7", "version": "1.7.8",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy-app", "name": "mcopy-app",
"version": "1.7.7", "version": "1.7.8",
"description": "GUI for the mcopy small gauge film optical printer platform", "description": "GUI for the mcopy small gauge film optical printer platform",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.7.7", "version": "1.7.8",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.7.7", "version": "1.7.8",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.7.7", "version": "1.7.8",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"arduino": "file:app/lib/arduino", "arduino": "file:app/lib/arduino",

View File

@ -1,6 +1,6 @@
{ {
"name": "mcopy", "name": "mcopy",
"version": "1.7.7", "version": "1.7.8",
"description": "Small gauge film optical printer platform", "description": "Small gauge film optical printer platform",
"main": "build.js", "main": "build.js",
"directories": { "directories": {

View File

@ -1,5 +1,5 @@
{ {
"version": "1.7.7", "version": "1.7.8",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -155,7 +155,7 @@ class Projector {
} }
message += ' 1 frame' message += ' 1 frame'
} else if (cmd === this.cfg.arduino.cmd.projectors) { } else if (cmd === this.cfg.arduino.cmd.projectors) {
message += 'Projectors both MOVED 1 frame each'; message += 'Projectors both MOVED 1 frame each'
} }
message += ` ${ms}ms` message += ` ${ms}ms`
this.log.info(message, 'PROJECTOR') this.log.info(message, 'PROJECTOR')
@ -164,5 +164,5 @@ class Projector {
} }
module.exports = function (arduino : Arduino, cfg : any, ui : any, filmout : any, second : boolean) { module.exports = function (arduino : Arduino, cfg : any, ui : any, filmout : any, second : boolean) {
return new Projector(arduino, cfg, ui, filmout, second); return new Projector(arduino, cfg, ui, filmout, second)
} }

View File

@ -1,6 +1,5 @@
import * as WebSocket from 'ws' import * as WebSocket from 'ws'
import express from 'express' import express, { Express, Request, Response, Application } from 'express'
import type { Request, Response } from 'express'
import { readFile } from 'fs/promises' import { readFile } from 'fs/promises'
import Log = require('log'); import Log = require('log');
@ -29,21 +28,31 @@ class Server {
path : 'lib/client/index.js' path : 'lib/client/index.js'
} }
] ]
private http : any private http : Application
private httpd : Server
private port : number = 9900 private port : number = 9900
private wsPort : number = 9901 private wsPort : number = 9901
constructor () { constructor () {
this.init() this.init()
} }
async init () { async init () {
this.log = await Log({ label : this.id }); this.log = await Log({ label : this.id });
await this.load()
await this.start()
} }
async load () { async load () {
this.http = express()
for (let tmpl of this.templates) { for (let tmpl of this.templates) {
tmpl.data = await readFile(tmpl.path, 'utf8') tmpl.data = await readFile(tmpl.path, 'utf8')
} }
this.http.get('/', this.index.bind(this))
this.http.get('/client.js', this.script.bind(this))
this.log.info("Server assets loaded") this.log.info("Server assets loaded")
} }
@ -55,25 +64,40 @@ class Server {
return html return html
} }
start () { async start () {
this.http.listen(function () { return new Promise(function (resolve : Function, reject : Function) {
this.httpd = this.http.listen(this.port, function () {
this.isActive = true this.isActive = true
this.log.inf(`Server started!`) this.log.info(`Server started!`)
this.log.info(`URL [ http://localhost:${this.port} ]`) this.log.info(`URL [ http://localhost:${this.port} ]`)
return resolve(true)
}.bind(this))
}.bind(this)) }.bind(this))
} }
stop() { stop() {
this.http.close() return new Promise(function (resolve : Function, reject : Function) {
return this.httpd.close(function () {
this.isActive = false this.isActive = false
this.log.info(`Server stopped :(`) this.log.info(`Server stopped :(`)
}.bind(this))
}.bind(this))
} }
index (req : Request, res : Response, next : Function) { index (req : Request, res : Response, next : Function) {
const html : string = this.template('index', { PORT : `${this.port}` }) const html : string = this.template('index', { PORT : `${this.port}` })
this.log.info('GET /')
return res.send(html) return res.send(html)
} }
script (req : Request, res : Response, next : Function) { script (req : Request, res : Response, next : Function) {
const js : string = this.template('script', { PORT : `${this.wsPort}` }) const js : string = this.template('script', { PORT : `${this.wsPort}` })
res.contentType('text/javascript')
this.log.info('GET /script.js')
return res.send(js)
} }
} }
module.exports = function () {
return new Server()
}