Combined script and html into single request (problems with iOS safari).

Can get script loaded but still cannot connect to websocket server without SSL.

ALSO: Now can pre-empt opening new display if an active client is connected to server.
Otherwise will open a local link.
This commit is contained in:
Matt McWilliams 2023-02-25 13:11:40 -05:00
parent f296488bc2
commit 47fb673b78
15 changed files with 56 additions and 37 deletions

View File

@ -1,5 +1,5 @@
{
"version": "1.7.13",
"version": "1.7.14",
"ext_port": 1111,
"profiles": {
"mcopy": {

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>;

View File

@ -425,9 +425,11 @@ class FilmOut {
async focus(evt, arg) {
this.log.info(`Showing focus screen`);
try {
if (await this.server.cmdAll('focus')) {
return;
}
await this.display.open();
await this.display.focus();
await this.server.cmdAll('focus');
}
catch (err) {
this.log.error(err, 'FILMOUT', true, true);
@ -440,9 +442,11 @@ class FilmOut {
const ratio = arg.ratio;
this.log.info(`Showing field guide screen`);
try {
if (await this.server.cmdAll('field', { ratio })) {
return;
}
await this.display.open();
await this.display.field(ratio);
await this.server.cmdAll('field', { ratio });
}
catch (err) {
this.log.error(err, 'FILMOUT', true, true);
@ -454,9 +458,11 @@ class FilmOut {
async meter(evt, arg) {
this.log.info(`Showing meter screen`);
try {
if (await this.server.cmdAll('meter')) {
return;
}
await this.display.open();
await this.display.meter();
await this.server.cmdAll('meter');
}
catch (err) {
this.log.error(err, 'FILMOUT', true, true);
@ -467,9 +473,11 @@ class FilmOut {
**/
async close(evt, arg) {
try {
if (await this.server.cmdAll('blank')) {
return;
}
await this.display.hide();
await this.display.close();
await this.server.cmdAll('blank');
}
catch (err) {
this.log.error(err, 'FILMOUT', true, true);

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,6 @@ class Server {
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.http.get('/image/:key', this.image.bind(this));
this.log.info("Server assets loaded");
}
@ -110,16 +109,11 @@ class Server {
this.isActive = false;
}
index(req, res, next) {
const html = this.template('index', { PORT: `${this.port}` });
const SCRIPT = this.template('script', { PORT: `${this.wsPort}` });
const html = this.template('index', { SCRIPT });
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);
}
async image(req, res, next) {
let filePath;
if (req.params && req.params.key) {
@ -158,7 +152,8 @@ class Server {
this.wss.clients.forEach(function (ws) {
cmds.push(this.cmd(ws, action, options));
}.bind(this));
return await Promise.all(cmds);
await Promise.all(cmds);
return true;
}
return false;
}

File diff suppressed because one or more lines are too long

2
app/package-lock.json generated
View File

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

View File

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

View File

@ -34,6 +34,8 @@
</div>
<canvas id="can">
</canvas>
<script src="http://localhost:{{PORT}}/client.js"></script>
<script>
{{SCRIPT}}
</script>
</body>
</html>

View File

@ -1,5 +1,5 @@
{
"version": "1.7.13",
"version": "1.7.14",
"ext_port": 1111,
"profiles": {
"mcopy": {

4
package-lock.json generated
View File

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

View File

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

View File

@ -1,5 +1,5 @@
{
"version": "1.7.13",
"version": "1.7.14",
"ext_port": 1111,
"profiles": {
"mcopy": {

View File

@ -444,9 +444,11 @@ class FilmOut {
async focus (evt : any, arg : any) {
this.log.info(`Showing focus screen`);
try {
if (await this.server.cmdAll('focus')) {
return
}
await this.display.open();
await this.display.focus();
await this.server.cmdAll('focus')
} catch (err) {
this.log.error(err, 'FILMOUT', true, true);
}
@ -458,9 +460,12 @@ class FilmOut {
const ratio : number = arg.ratio;
this.log.info(`Showing field guide screen`);
try {
if (await this.server.cmdAll('field', { ratio })) {
return
}
await this.display.open();
await this.display.field(ratio);
await this.server.cmdAll('field', { ratio });
} catch (err) {
this.log.error(err, 'FILMOUT', true, true);
}
@ -471,9 +476,11 @@ class FilmOut {
async meter (evt : any, arg : any) {
this.log.info(`Showing meter screen`);
try {
if (await this.server.cmdAll('meter')) {
return
}
await this.display.open();
await this.display.meter();
await this.server.cmdAll('meter');
} catch (err) {
this.log.error(err, 'FILMOUT', true, true);
}
@ -483,9 +490,12 @@ class FilmOut {
**/
async close (evt : any, arg : any) {
try {
if (await this.server.cmdAll('blank')) {
return
}
await this.display.hide();
await this.display.close();
await this.server.cmdAll('blank');
} catch (err) {
this.log.error(err, 'FILMOUT', true, true);
}

View File

@ -9,6 +9,7 @@ import { delay } from 'delay';
interface ServerData {
[key: string]: string;
PORT? : string;
SCRIPT? : string;
}
interface ServerTemplate {
@ -71,7 +72,6 @@ class Server {
}
this.http.get('/', this.index.bind(this))
this.http.get('/client.js', this.script.bind(this))
this.http.get('/image/:key', this.image.bind(this))
this.log.info("Server assets loaded")
@ -150,16 +150,11 @@ class Server {
}
index (req : Request, res : Response, next : Function) {
const html : string = this.template('index', { PORT : `${this.port}` })
const SCRIPT = this.template('script', { PORT : `${this.wsPort}` })
const html : string = this.template('index', { SCRIPT })
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)
}
async image (req : Request, res : Response, next : Function) {
let filePath : string
@ -199,7 +194,8 @@ class Server {
this.wss.clients.forEach(function (ws : WebSocket) {
cmds.push(this.cmd(ws, action, options))
}.bind(this))
return await Promise.all(cmds)
await Promise.all(cmds)
return true
}
return false
}