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,
"profiles": {
"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);
throw err;
}
if (this.server.displayImage(path)) {
await delay_1.delay(20);
return;
}
await this.display.show(path);
await delay_1.delay(20);
}
@ -412,6 +416,9 @@ class FilmOut {
throw err;
}
try {
if (await this.server.displayImage(path)) {
return;
}
await this.display.open();
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 express_1 = __importDefault(require("express"));
const promises_1 = require("fs/promises");
const mime_1 = __importDefault(require("mime"));
const path_1 = require("path");
const uuid_1 = require("uuid");
const Log = require("log");
class Server {
@ -141,8 +141,7 @@ class Server {
//wipe every time
this.proxy = {};
this.proxy[key] = {
path: filePath,
mime: mime_1.default.getType(filePath)
path: filePath
};
this.log.info(`Added proxy image [${key}]`);
}
@ -157,6 +156,16 @@ class Server {
}
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
**/

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.14",
"version": "1.7.15",
"lockfileVersion": 2,
"requires": true,
"packages": {

View File

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

View File

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

4
package-lock.json generated
View File

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

View File

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

View File

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

View File

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

View File

@ -1,10 +1,10 @@
import WebSocket, { WebSocketServer } from 'ws'
import express, { Express, Request, Response, Application } from 'express'
import { readFile } from 'fs/promises'
import mime from 'mime'
import { basename } from 'path'
import { v4 as uuidv4 } from 'uuid'
import Log = require('log')
import { delay } from 'delay';
import { delay } from 'delay'
interface ServerData {
[key: string]: string;
@ -20,7 +20,6 @@ interface ServerTemplate {
interface ServerProxy {
path : string;
mime : string;
}
interface ServerProxyList {
@ -182,8 +181,7 @@ class Server {
//wipe every time
this.proxy = {}
this.proxy[key] = {
path : filePath,
mime : mime.getType(filePath)
path : filePath
}
this.log.info(`Added proxy image [${key}]`)
}
@ -200,6 +198,17 @@ class Server {
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
**/