Server can now display images and will completely preempt local display when done

This commit is contained in:
Matt McWilliams 2023-02-25 13:22:20 -05:00
parent 47fb673b78
commit 0162d012c5
14 changed files with 51 additions and 26 deletions

View File

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

View File

@ -1,8 +0,0 @@
/**
* 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

@ -124,6 +124,10 @@ class FilmOut {
this.log.error(err, 'FILMOUT', true, true); this.log.error(err, 'FILMOUT', true, true);
throw err; throw err;
} }
if (this.server.displayImage(path)) {
await delay_1.delay(20);
return;
}
await this.display.show(path); await this.display.show(path);
await delay_1.delay(20); await delay_1.delay(20);
} }
@ -412,6 +416,9 @@ class FilmOut {
throw err; throw err;
} }
try { try {
if (await this.server.displayImage(path)) {
return;
}
await this.display.open(); await this.display.open();
await this.display.show(path); await this.display.show(path);
} }

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
const ws_1 = require("ws"); const ws_1 = require("ws");
const express_1 = __importDefault(require("express")); const express_1 = __importDefault(require("express"));
const promises_1 = require("fs/promises"); const promises_1 = require("fs/promises");
const mime_1 = __importDefault(require("mime")); const path_1 = require("path");
const uuid_1 = require("uuid"); const uuid_1 = require("uuid");
const Log = require("log"); const Log = require("log");
class Server { class Server {
@ -141,8 +141,7 @@ class Server {
//wipe every time //wipe every time
this.proxy = {}; this.proxy = {};
this.proxy[key] = { this.proxy[key] = {
path: filePath, path: filePath
mime: mime_1.default.getType(filePath)
}; };
this.log.info(`Added proxy image [${key}]`); this.log.info(`Added proxy image [${key}]`);
} }
@ -157,6 +156,16 @@ class Server {
} }
return false; return false;
} }
async displayImage(src) {
let key;
if (this.isActive && this.wss.clients.size > 0) {
key = path_1.basename(src);
this.addProxy(key, src);
await this.cmdAll('image', { image: `/image/${key}` });
return true;
}
return false;
}
/** /**
* WSS * WSS
**/ **/

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", "name": "mcopy-app",
"version": "1.7.14", "version": "1.7.15",
"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.14", "version": "1.7.15",
"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.14", "version": "1.7.15",
"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.14", "version": "1.7.15",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "mcopy", "name": "mcopy",
"version": "1.7.14", "version": "1.7.15",
"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.14", "version": "1.7.15",
"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.14", "version": "1.7.15",
"ext_port": 1111, "ext_port": 1111,
"profiles": { "profiles": {
"mcopy": { "mcopy": {

View File

@ -135,6 +135,11 @@ class FilmOut {
throw err; throw err;
} }
if (this.server.displayImage(path)) {
await delay(20)
return
}
await this.display.show(path); await this.display.show(path);
await delay(20); await delay(20);
} }
@ -432,6 +437,9 @@ class FilmOut {
} }
try { try {
if (await this.server.displayImage(path)) {
return
}
await this.display.open(); await this.display.open();
await this.display.show(path); await this.display.show(path);
} catch (err) { } catch (err) {

View File

@ -1,10 +1,10 @@
import WebSocket, { WebSocketServer } from 'ws' import WebSocket, { WebSocketServer } from 'ws'
import express, { Express, Request, Response, Application } from 'express' import express, { Express, Request, Response, Application } from 'express'
import { readFile } from 'fs/promises' import { readFile } from 'fs/promises'
import mime from 'mime' import { basename } from 'path'
import { v4 as uuidv4 } from 'uuid' import { v4 as uuidv4 } from 'uuid'
import Log = require('log') import Log = require('log')
import { delay } from 'delay'; import { delay } from 'delay'
interface ServerData { interface ServerData {
[key: string]: string; [key: string]: string;
@ -20,7 +20,6 @@ interface ServerTemplate {
interface ServerProxy { interface ServerProxy {
path : string; path : string;
mime : string;
} }
interface ServerProxyList { interface ServerProxyList {
@ -182,8 +181,7 @@ class Server {
//wipe every time //wipe every time
this.proxy = {} this.proxy = {}
this.proxy[key] = { this.proxy[key] = {
path : filePath, path : filePath
mime : mime.getType(filePath)
} }
this.log.info(`Added proxy image [${key}]`) this.log.info(`Added proxy image [${key}]`)
} }
@ -200,6 +198,17 @@ class Server {
return false return false
} }
public async displayImage (src : string) {
let key
if (this.isActive && this.wss.clients.size > 0) {
key = basename(src)
this.addProxy(key, src)
await this.cmdAll('image', { image : `/image/${key}` })
return true
}
return false
}
/** /**
* WSS * WSS
**/ **/