Server work

This commit is contained in:
Matt McWilliams 2023-02-25 00:24:07 -05:00
parent 7222952eba
commit 42db1f81b8
15 changed files with 1461 additions and 126 deletions

6
app/lib/client/index.js Normal file
View File

@ -0,0 +1,6 @@
const webSocket = new WebSocket('ws://localhost:{{PORT}}/');
webSocket.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data);
};
//# sourceMappingURL=index.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lib/client/index.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,0BAA0B,CAAC,CAAC;AAC5D,SAAS,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;IAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAA"}

View File

@ -50,7 +50,7 @@ async function logFile() {
*
* @returns {object} Logger transport
**/
module.exports = async function (arg) {
module.exports = async function Log(arg) {
let consoleFormat = {
colorize: true
};

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/log/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,qCAA2D;AAC3D,+BAAuC;AACvC,uCAAyC;AACzC,2BAA6B;AAE7B,MAAM,OAAO,GAAG,mBAAmB,CAAA;AACnC,IAAI,SAAe,CAAA;AAEnB;;;;;IAKI;AACJ,KAAK,UAAU,OAAO;IACrB,MAAM,OAAO,GAAY,YAAO,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAY,UAAU,CAAC;IACrC,MAAM,MAAM,GAAY,sBAAsB,CAAC;IAC/C,MAAM,MAAM,GAAY,yBAAyB,CAAC;IAClD,IAAI,OAAO,GAAY,gBAAS,CAAC,WAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC1D,IAAI,SAAmB,CAAC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G,cAAc,OAAO,KAAK,CAAA,CAAC,CAAC;YACnC,KAAK,EAAG,cAAc,OAAO,KAAK,CAAA,CAAC,CAAC;SACpC,CAAA;KACD;SAAM;QACN,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE;YACrB,aAAa,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;YAChC,UAAU,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;SAC7B;QACD,SAAS,GAAG,sBAAY,CAAC;YACxB,MAAM,EAAG,gBAAM,CAAC,OAAO,CACnB,gBAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAG,GAAG,CAAC,KAAK,IAAI,OAAO,EAAE,CAAC,EACjD,gBAAM,CAAC,SAAS,CAAC;gBAChB,MAAM,EAAE,qBAAqB;aAC7B,CAAC,EACF,gBAAM,CAAC,MAAM,CAAC,CAAC,IAAU,EAAG,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,EAAE,GAAC,CAAC,IAAI,CAAC,KAAK,KAAG,SAAS,CAAA,CAAC,CAAA,GAAG,IAAI,CAAC,KAAK,EAAE,CAAA,CAAC,CAAA,GAAG,CAAC,CAAC,CAC7I;YACH,UAAU,EAAE;gBACX,IAAI,CAAC,oBAAU,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC;gBACvC,IAAI,CAAC,oBAAU,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC;aACjC;SACD,CAAC,CAAA;KACF;IACD,OAAO,SAAS,CAAA;AACjB,CAAC,CAAA"}

1
app/lib/server/index.d.ts vendored Normal file
View File

@ -0,0 +1 @@
export {};

View File

@ -1,90 +1,59 @@
'use script'
let os
let restify
let app
let cam
let proj
let light
const PACKAGE = require('../../package.json')
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const promises_1 = require("fs/promises");
const Log = require("log");
class Server {
constructor (camera, projector, light) {
restify = require('restify')
os = require('os')
app = restify.createServer({
name: 'mcopy-server',
version: PACKAGE.version
})
this.ip = this.getIp()
/*app.get('/', function (req, res) {
mcopy.mobile.log('Device connected');
res.send(fs.readFileSync('tmpl/mcopy_index.html', 'utf8'));
})
app.get('/js/mcopy_mobile.js', function (req, res) {
res.send(fs.readFileSync('js/mcopy_mobile.js', 'utf8'));
});
app.get('/js/jquery.js', function (req, res) {
res.send(fs.readFileSync('js/jquery.js', 'utf8'));
});
app.get('/cmd/:cmd', function (req, res) {
var cmd,
success = function (res) {
var obj = {
success: true,
cmd : cmd,
cam: {
dir : cam.dir,
pos : cam.pos
},
proj: {
dir : proj.dir,
pos : proj.pos
}
}
res.json(obj);
};
if (typeof req.params.cmd !== 'undefined') {
mcopy.log('Receiving command from mobile: ' + req.params.cmd);
cmd = req.params.cmd;
if (cmd === 'CF'){
mcopy.cmd.camera_forward(success);
} else if (cmd === 'CB') {
mcopy.cmd.camera_backward(success);
} else if (cmd === 'PF') {
mcopy.cmd.projector_forward(success);
} else if (cmd === 'PB') {
mcopy.cmd.projector_backward(success);
} else {
mcopy.mobile.fail(res, 'Command ' + cmd + ' not found');
}
} else {
mcopy.mobile.fail(res, 'No command provided');
}
});
app.get('/state', function (req, res) {
res.json({
cam: {
dir : cam.dir,
pos : cam.pos
},
proj: {
dir : proj.dir,
pos : proj.pos
}
});
});*/
}
end () {
app.close()
app = null
}
constructor() {
this.id = 'server';
this.isActive = false;
this.templates = [
{
name: 'index',
path: 'server.html'
},
{
name: 'script',
path: 'lib/client/index.js'
}
];
this.port = 9900;
this.wsPort = 9901;
this.init();
}
async init() {
this.log = await Log({ label: this.id });
}
async load() {
for (let tmpl of this.templates) {
tmpl.data = await promises_1.readFile(tmpl.path, 'utf8');
}
this.log.info("Server assets loaded");
}
template(name, data) {
let html = this.templates.find(el => el.name === name).data;
for (let key of Object.keys(data)) {
html = html.replace(`{{${key}}}`, data[key]);
}
return html;
}
start() {
this.http.listen(function () {
this.isActive = true;
this.log.inf(`Server started!`);
this.log.info(`URL [ http://localhost:${this.port} ]`);
}.bind(this));
}
stop() {
this.http.close();
this.isActive = false;
this.log.info(`Server stopped :(`);
}
index(req, res, next) {
const html = this.template('index', { PORT: `${this.port}` });
return res.send(html);
}
script(req, res, next) {
const js = this.template('script', { PORT: `${this.wsPort}` });
}
}
module.exports = Server
//# sourceMappingURL=index.js.map

View File

@ -0,0 +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,KAAK,CAAC,IAAI;QACT,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,SAAS,EAAE;YAChC,IAAI,CAAC,IAAI,GAAG,MAAM,mBAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;SAC7C;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAA;IACtC,CAAC;IAED,QAAQ,CAAE,IAAY,EAAE,IAAiB;QACxC,IAAI,IAAI,GAAY,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,KAA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"display": "file:lib/display",
"exec": "file:lib/exec",
"exit": "file:lib/exit",
"express": "^4.18.2",
"ffmpeg": "file:lib/ffmpeg",
"ffmpeg-static": "^5.0.0",
"ffprobe": "file:lib/ffprobe",
@ -89,7 +90,8 @@
"spawn": "file:lib/spawn",
"system": "file:lib/system",
"uuid": "^8.3.2",
"winston": "^3.7.2"
"winston": "^3.7.2",
"ws": "^8.12.1"
},
"optionalDependencies": {
"electron-installer-debian": "^3.1.0"

10
app/server.html Normal file
View File

@ -0,0 +1,10 @@
<html>
<head>
<style>
html, body{
background: rgb(0, 0, 0);
}
</style>
<script src="http://localhost:{{PORT}}/client.js"></script>
</body>
</html>

View File

@ -0,0 +1,5 @@
const webSocket = new WebSocket('ws://localhost:{{PORT}}/');
webSocket.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log(data);
}

160
package-lock.json generated
View File

@ -28,12 +28,14 @@
},
"devDependencies": {
"@types/electron": "^1.6.10",
"@types/express": "^4.17.17",
"@types/fs-extra": "^9.0.7",
"@types/jimp": "^0.2.28",
"@types/node": "^14.14.31",
"@types/request": "^2.48.5",
"@types/sharp": "^0.27.1",
"@types/uuid": "^8.3.0",
"@types/ws": "^8.5.4",
"jsdoc-to-markdown": "^6.0.1",
"typescript": "^4.1.5"
}
@ -596,12 +598,31 @@
"node": ">=6"
}
},
"node_modules/@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
"integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==",
"dev": true,
"dependencies": {
"@types/connect": "*",
"@types/node": "*"
}
},
"node_modules/@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
"dev": true
},
"node_modules/@types/connect": {
"version": "3.4.35",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
"integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/electron": {
"version": "1.6.10",
"resolved": "https://registry.npmjs.org/@types/electron/-/electron-1.6.10.tgz",
@ -611,6 +632,29 @@
"electron": "*"
}
},
"node_modules/@types/express": {
"version": "4.17.17",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz",
"integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==",
"dev": true,
"dependencies": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "^4.17.33",
"@types/qs": "*",
"@types/serve-static": "*"
}
},
"node_modules/@types/express-serve-static-core": {
"version": "4.17.33",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz",
"integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==",
"dev": true,
"dependencies": {
"@types/node": "*",
"@types/qs": "*",
"@types/range-parser": "*"
}
},
"node_modules/@types/fs-extra": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.7.tgz",
@ -629,12 +673,30 @@
"jimp": "*"
}
},
"node_modules/@types/mime": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
"dev": true
},
"node_modules/@types/node": {
"version": "14.14.31",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.31.tgz",
"integrity": "sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==",
"dev": true
},
"node_modules/@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
"integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==",
"dev": true
},
"node_modules/@types/range-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==",
"dev": true
},
"node_modules/@types/request": {
"version": "2.48.5",
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.5.tgz",
@ -647,6 +709,16 @@
"form-data": "^2.5.0"
}
},
"node_modules/@types/serve-static": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz",
"integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==",
"dev": true,
"dependencies": {
"@types/mime": "*",
"@types/node": "*"
}
},
"node_modules/@types/sharp": {
"version": "0.27.1",
"resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.27.1.tgz",
@ -668,6 +740,15 @@
"integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==",
"dev": true
},
"node_modules/@types/ws": {
"version": "8.5.4",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz",
"integrity": "sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/ansi-escape-sequences": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-escape-sequences/-/ansi-escape-sequences-4.1.0.tgz",
@ -3284,12 +3365,31 @@
"defer-to-connect": "^1.0.1"
}
},
"@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
"integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==",
"dev": true,
"requires": {
"@types/connect": "*",
"@types/node": "*"
}
},
"@types/caseless": {
"version": "0.12.2",
"resolved": "https://registry.npmjs.org/@types/caseless/-/caseless-0.12.2.tgz",
"integrity": "sha512-6ckxMjBBD8URvjB6J3NcnuAn5Pkl7t3TizAg+xdlzzQGSPSmBcXf8KoIH0ua/i+tio+ZRUHEXp0HEmvaR4kt0w==",
"dev": true
},
"@types/connect": {
"version": "3.4.35",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
"integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/electron": {
"version": "1.6.10",
"resolved": "https://registry.npmjs.org/@types/electron/-/electron-1.6.10.tgz",
@ -3299,6 +3399,29 @@
"electron": "*"
}
},
"@types/express": {
"version": "4.17.17",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz",
"integrity": "sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==",
"dev": true,
"requires": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "^4.17.33",
"@types/qs": "*",
"@types/serve-static": "*"
}
},
"@types/express-serve-static-core": {
"version": "4.17.33",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.33.tgz",
"integrity": "sha512-TPBqmR/HRYI3eC2E5hmiivIzv+bidAfXofM+sbonAGvyDhySGw9/PQZFt2BLOrjUUR++4eJVpx6KnLQK1Fk9tA==",
"dev": true,
"requires": {
"@types/node": "*",
"@types/qs": "*",
"@types/range-parser": "*"
}
},
"@types/fs-extra": {
"version": "9.0.7",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.7.tgz",
@ -3317,12 +3440,30 @@
"jimp": "*"
}
},
"@types/mime": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-3.0.1.tgz",
"integrity": "sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==",
"dev": true
},
"@types/node": {
"version": "14.14.31",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.31.tgz",
"integrity": "sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==",
"dev": true
},
"@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
"integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==",
"dev": true
},
"@types/range-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==",
"dev": true
},
"@types/request": {
"version": "2.48.5",
"resolved": "https://registry.npmjs.org/@types/request/-/request-2.48.5.tgz",
@ -3335,6 +3476,16 @@
"form-data": "^2.5.0"
}
},
"@types/serve-static": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.1.tgz",
"integrity": "sha512-NUo5XNiAdULrJENtJXZZ3fHtfMolzZwczzBbnAeBbqBwG+LaG6YaJtuwzwGSQZ2wsCrxjEhNNjAkKigy3n8teQ==",
"dev": true,
"requires": {
"@types/mime": "*",
"@types/node": "*"
}
},
"@types/sharp": {
"version": "0.27.1",
"resolved": "https://registry.npmjs.org/@types/sharp/-/sharp-0.27.1.tgz",
@ -3356,6 +3507,15 @@
"integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==",
"dev": true
},
"@types/ws": {
"version": "8.5.4",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.4.tgz",
"integrity": "sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"ansi-escape-sequences": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-escape-sequences/-/ansi-escape-sequences-4.1.0.tgz",

View File

@ -26,12 +26,14 @@
"homepage": "https://github.com/sixteenmillimeter/mcopy#readme",
"devDependencies": {
"@types/electron": "^1.6.10",
"@types/express": "^4.17.17",
"@types/fs-extra": "^9.0.7",
"@types/jimp": "^0.2.28",
"@types/node": "^14.14.31",
"@types/request": "^2.48.5",
"@types/sharp": "^0.27.1",
"@types/uuid": "^8.3.0",
"@types/ws": "^8.5.4",
"jsdoc-to-markdown": "^6.0.1",
"typescript": "^4.1.5"
},
@ -47,8 +49,8 @@
"light": "file:app/lib/light",
"log": "file:app/lib/log",
"mscript": "file:app/lib/mscript",
"proj": "file:app/lib/proj",
"processing": "file:app/lib/processing",
"proj": "file:app/lib/proj",
"sequencer": "file:app/lib/sequencer",
"settings": "file:app/lib/settings",
"system": "file:app/lib/system"

View File

@ -53,7 +53,7 @@ async function logFile () {
*
* @returns {object} Logger transport
**/
module.exports = async function (arg : any) {
module.exports = async function Log (arg : any) {
let consoleFormat : any = {
colorize : true
}

79
src/server/index.ts Normal file
View File

@ -0,0 +1,79 @@
import * as WebSocket from 'ws'
import express from 'express'
import type { Request, Response } from 'express'
import { readFile } from 'fs/promises'
import Log = require('log');
interface ServerData {
[key: string]: string;
PORT? : string;
}
interface ServerTemplate {
name : string;
path : string;
data? : string
}
class Server {
private id : string = 'server'
public isActive : boolean = false
private log : any
private templates : ServerTemplate[] = [
{
name :'index',
path : 'server.html'
},
{
name : 'script',
path : 'lib/client/index.js'
}
]
private http : any
private port : number = 9900
private wsPort : number = 9901
constructor () {
this.init()
}
async init () {
this.log = await Log({ label : this.id });
}
async load () {
for (let tmpl of this.templates) {
tmpl.data = await readFile(tmpl.path, 'utf8')
}
this.log.info("Server assets loaded")
}
template (name: string, data : ServerData) {
let html : string = this.templates.find(el => el.name === name).data
for (let key of Object.keys(data)) {
html = html.replace(`{{${key}}}`, data[key])
}
return html
}
start () {
this.http.listen(function () {
this.isActive = true
this.log.inf(`Server started!`)
this.log.info(`URL [ http://localhost:${this.port} ]`)
}.bind(this))
}
stop() {
this.http.close()
this.isActive = false
this.log.info(`Server stopped :(`)
}
index (req : Request, res : Response, next : Function) {
const html : string = this.template('index', { PORT : `${this.port}` })
return res.send(html)
}
script (req : Request, res : Response, next : Function) {
const js : string = this.template('script', { PORT : `${this.wsPort}` })
}
}