Merge all work on server with filmout features #77
|
@ -145,7 +145,7 @@
|
|||
can.style.width = `${window.innerHeight * arg.ratio}px`
|
||||
can.style.height = `${window.innerHeight}px`
|
||||
} else {
|
||||
can.style.width = `${window.inneWidth}px`
|
||||
can.style.width = `${window.innerWidth}px`
|
||||
can.style.height = `${window.innerWidth / arg.ratio}px`
|
||||
}
|
||||
} else {
|
||||
|
@ -209,7 +209,7 @@
|
|||
async function onDigital (event, arg) {
|
||||
if (arg.src) {
|
||||
try {
|
||||
await setImage(arg.src)
|
||||
await setImage(arg.src)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -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
|
@ -1,5 +1,9 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const promises_1 = require("fs/promises");
|
||||
const Log = require("log");
|
||||
class Server {
|
||||
|
@ -22,11 +26,16 @@ class Server {
|
|||
}
|
||||
async init() {
|
||||
this.log = await Log({ label: this.id });
|
||||
await this.load();
|
||||
await this.start();
|
||||
}
|
||||
async load() {
|
||||
this.http = express_1.default();
|
||||
for (let tmpl of this.templates) {
|
||||
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");
|
||||
}
|
||||
template(name, data) {
|
||||
|
@ -36,24 +45,37 @@ class Server {
|
|||
}
|
||||
return html;
|
||||
}
|
||||
start() {
|
||||
this.http.listen(function () {
|
||||
this.isActive = true;
|
||||
this.log.inf(`Server started!`);
|
||||
this.log.info(`URL [ http://localhost:${this.port} ]`);
|
||||
async start() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
this.httpd = this.http.listen(this.port, function () {
|
||||
this.isActive = true;
|
||||
this.log.info(`Server started!`);
|
||||
this.log.info(`URL [ http://localhost:${this.port} ]`);
|
||||
return resolve(true);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
stop() {
|
||||
this.http.close();
|
||||
this.isActive = false;
|
||||
this.log.info(`Server stopped :(`);
|
||||
return new Promise(function (resolve, reject) {
|
||||
return this.httpd.close(function () {
|
||||
this.isActive = false;
|
||||
this.log.info(`Server stopped :(`);
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
index(req, res, next) {
|
||||
const html = this.template('index', { PORT: `${this.port}` });
|
||||
this.log.info('GET /');
|
||||
return res.send(html);
|
||||
}
|
||||
script(req, res, next) {
|
||||
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
|
|
@ -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,IA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AG;IAChB,OAAO,IAAI,MAAM,EAAE,CAAA;AACpB,CAAC,CAAA"}
|
|
@ -39,6 +39,7 @@ let cmd;
|
|||
let seq;
|
||||
let capper;
|
||||
let alert;
|
||||
let server;
|
||||
|
||||
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)
|
||||
seq = require('sequencer')(cfg, cmd, mainWindow.webContents)
|
||||
|
||||
server = require('server')()
|
||||
}
|
||||
|
||||
app.on('ready', init)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mcopy-app",
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mcopy-app",
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"description": "GUI for the mcopy small gauge film optical printer platform",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"ext_port": 1111,
|
||||
"profiles": {
|
||||
"mcopy": {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "mcopy",
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "mcopy",
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"arduino": "file:app/lib/arduino",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mcopy",
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"description": "Small gauge film optical printer platform",
|
||||
"main": "build.js",
|
||||
"directories": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "1.7.7",
|
||||
"version": "1.7.8",
|
||||
"ext_port": 1111,
|
||||
"profiles": {
|
||||
"mcopy": {
|
||||
|
|
|
@ -155,7 +155,7 @@ class Projector {
|
|||
}
|
||||
message += ' 1 frame'
|
||||
} 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`
|
||||
this.log.info(message, 'PROJECTOR')
|
||||
|
@ -164,5 +164,5 @@ class Projector {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
import * as WebSocket from 'ws'
|
||||
import express from 'express'
|
||||
import type { Request, Response } from 'express'
|
||||
import express, { Express, Request, Response, Application } from 'express'
|
||||
import { readFile } from 'fs/promises'
|
||||
import Log = require('log');
|
||||
|
||||
|
@ -29,21 +28,31 @@ class Server {
|
|||
path : 'lib/client/index.js'
|
||||
}
|
||||
]
|
||||
private http : any
|
||||
private http : Application
|
||||
private httpd : Server
|
||||
private port : number = 9900
|
||||
private wsPort : number = 9901
|
||||
|
||||
constructor () {
|
||||
this.init()
|
||||
|
||||
}
|
||||
|
||||
async init () {
|
||||
this.log = await Log({ label : this.id });
|
||||
await this.load()
|
||||
await this.start()
|
||||
}
|
||||
|
||||
async load () {
|
||||
this.http = express()
|
||||
for (let tmpl of this.templates) {
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -55,25 +64,40 @@ class Server {
|
|||
return html
|
||||
}
|
||||
|
||||
start () {
|
||||
this.http.listen(function () {
|
||||
this.isActive = true
|
||||
this.log.inf(`Server started!`)
|
||||
this.log.info(`URL [ http://localhost:${this.port} ]`)
|
||||
async start () {
|
||||
return new Promise(function (resolve : Function, reject : Function) {
|
||||
this.httpd = this.http.listen(this.port, function () {
|
||||
this.isActive = true
|
||||
this.log.info(`Server started!`)
|
||||
this.log.info(`URL [ http://localhost:${this.port} ]`)
|
||||
return resolve(true)
|
||||
}.bind(this))
|
||||
}.bind(this))
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.http.close()
|
||||
this.isActive = false
|
||||
this.log.info(`Server stopped :(`)
|
||||
return new Promise(function (resolve : Function, reject : Function) {
|
||||
return this.httpd.close(function () {
|
||||
this.isActive = false
|
||||
this.log.info(`Server stopped :(`)
|
||||
}.bind(this))
|
||||
}.bind(this))
|
||||
|
||||
}
|
||||
|
||||
index (req : Request, res : Response, next : Function) {
|
||||
const html : string = this.template('index', { PORT : `${this.port}` })
|
||||
this.log.info('GET /')
|
||||
return res.send(html)
|
||||
}
|
||||
script (req : Request, res : Response, next : Function) {
|
||||
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()
|
||||
}
|
Loading…
Reference in New Issue