Compare commits
3 Commits
f0b49874f6
...
7632245332
Author | SHA1 | Date |
---|---|---|
|
7632245332 | |
|
917c46d876 | |
|
4f8b05e9bd |
|
@ -7,4 +7,5 @@ HEIGHT=1600
|
||||||
FD=../filmout_display/build/bin/fd
|
FD=../filmout_display/build/bin/fd
|
||||||
FD_HOST=localhost
|
FD_HOST=localhost
|
||||||
FD_PORT=8081
|
FD_PORT=8081
|
||||||
|
VIDEOS=/home/users/VIDEOS
|
||||||
SEQUENCES=/home/user/SEQUENCES
|
SEQUENCES=/home/user/SEQUENCES
|
|
@ -25,6 +25,12 @@ export interface fdOutgoingMessage {
|
||||||
export interface fdIncomingMessage {
|
export interface fdIncomingMessage {
|
||||||
action: Action;
|
action: Action;
|
||||||
success: boolean;
|
success: boolean;
|
||||||
|
error?: string;
|
||||||
|
}
|
||||||
|
export interface fdResult {
|
||||||
|
action: Action;
|
||||||
|
image: string;
|
||||||
|
time: number;
|
||||||
}
|
}
|
||||||
export declare class FD {
|
export declare class FD {
|
||||||
private bin;
|
private bin;
|
||||||
|
@ -37,16 +43,17 @@ export declare class FD {
|
||||||
private client;
|
private client;
|
||||||
private socketAvailable;
|
private socketAvailable;
|
||||||
private socketConnected;
|
private socketConnected;
|
||||||
|
private waiting;
|
||||||
constructor(bin: string, width: number, height: number, host: string, port: number);
|
constructor(bin: string, width: number, height: number, host: string, port: number);
|
||||||
private startDisplay;
|
private startDisplay;
|
||||||
private startClient;
|
private startClient;
|
||||||
private logstd;
|
private logstd;
|
||||||
private logsterr;
|
private logsterr;
|
||||||
private test;
|
|
||||||
private send;
|
private send;
|
||||||
private receive;
|
private receive;
|
||||||
load(image: string, x: number, y: number, w: number, h: number): Promise<boolean>;
|
load(image: string, x: number, y: number, w: number, h: number): Promise<fdResult>;
|
||||||
display(image: string, exposure: number[]): Promise<boolean>;
|
display(image: string, exposure: number[]): Promise<fdResult>;
|
||||||
stop(image: string): Promise<boolean>;
|
stop(image: string): Promise<fdResult>;
|
||||||
|
isConnected(): boolean;
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|
|
@ -28,6 +28,7 @@ class FD {
|
||||||
constructor(bin, width, height, host, port) {
|
constructor(bin, width, height, host, port) {
|
||||||
this.socketAvailable = false;
|
this.socketAvailable = false;
|
||||||
this.socketConnected = false;
|
this.socketConnected = false;
|
||||||
|
this.waiting = null;
|
||||||
this.bin = bin;
|
this.bin = bin;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
@ -37,7 +38,6 @@ class FD {
|
||||||
this.shell = new shell_1.Shell([this.bin, `${this.width}`, `${this.height}`, `${this.port}`], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
this.shell = new shell_1.Shell([this.bin, `${this.width}`, `${this.height}`, `${this.port}`], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
||||||
this.startDisplay();
|
this.startDisplay();
|
||||||
this.startClient();
|
this.startClient();
|
||||||
this.test();
|
|
||||||
}
|
}
|
||||||
async startDisplay() {
|
async startDisplay() {
|
||||||
this.log.info(`Launching fd binary ${this.bin}`);
|
this.log.info(`Launching fd binary ${this.bin}`);
|
||||||
|
@ -53,12 +53,6 @@ class FD {
|
||||||
this.client.connect(this.port, this.host, async function () {
|
this.client.connect(this.port, this.host, async function () {
|
||||||
this.socketConnected = true;
|
this.socketConnected = true;
|
||||||
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
||||||
await (0, delay_1.delay)(1000);
|
|
||||||
const msg = {
|
|
||||||
action: Action.LOAD,
|
|
||||||
image: './test.jpg'
|
|
||||||
};
|
|
||||||
this.send(msg);
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
this.client.on('data', function (data) {
|
this.client.on('data', function (data) {
|
||||||
this.receive(data);
|
this.receive(data);
|
||||||
|
@ -79,10 +73,6 @@ class FD {
|
||||||
logsterr(data) {
|
logsterr(data) {
|
||||||
this.log.error(`[shell] ${data}`);
|
this.log.error(`[shell] ${data}`);
|
||||||
}
|
}
|
||||||
async test() {
|
|
||||||
await (0, delay_1.delay)(10000);
|
|
||||||
this.shell.kill();
|
|
||||||
}
|
|
||||||
send(msg) {
|
send(msg) {
|
||||||
const json = JSON.stringify(msg);
|
const json = JSON.stringify(msg);
|
||||||
this.log.info(json);
|
this.log.info(json);
|
||||||
|
@ -91,7 +81,10 @@ class FD {
|
||||||
receive(json) {
|
receive(json) {
|
||||||
const msg = JSON.parse(json);
|
const msg = JSON.parse(json);
|
||||||
this.log.info(msg);
|
this.log.info(msg);
|
||||||
return msg;
|
if (this.waiting != null) {
|
||||||
|
this.waiting(msg);
|
||||||
|
this.waiting = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async load(image, x, y, w, h) {
|
async load(image, x, y, w, h) {
|
||||||
const msg = {
|
const msg = {
|
||||||
|
@ -102,8 +95,24 @@ class FD {
|
||||||
w,
|
w,
|
||||||
h
|
h
|
||||||
};
|
};
|
||||||
|
const startTime = +new Date();
|
||||||
|
const promise = new Promise(function (resolve, reject) {
|
||||||
|
this.waiting = function (msg) {
|
||||||
|
if (msg.action == Action.LOAD && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action: Action.LOAD,
|
||||||
|
image,
|
||||||
|
time: (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error loading ${image}`));
|
||||||
|
};
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
}
|
}
|
||||||
async display(image, exposure) {
|
async display(image, exposure) {
|
||||||
const msg = {
|
const msg = {
|
||||||
|
@ -111,16 +120,51 @@ class FD {
|
||||||
image,
|
image,
|
||||||
exposure
|
exposure
|
||||||
};
|
};
|
||||||
|
const startTime = +new Date();
|
||||||
|
const promise = new Promise(function (resolve, reject) {
|
||||||
|
this.waiting = function (msg) {
|
||||||
|
if (msg.action == Action.DISPLAY && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action: Action.DISPLAY,
|
||||||
|
image,
|
||||||
|
time: (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error displaying ${image}`));
|
||||||
|
};
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
}
|
}
|
||||||
async stop(image) {
|
async stop(image) {
|
||||||
const msg = {
|
const msg = {
|
||||||
action: Action.STOP,
|
action: Action.STOP,
|
||||||
image
|
image
|
||||||
};
|
};
|
||||||
|
const startTime = +new Date();
|
||||||
|
const promise = new Promise(function (resolve, reject) {
|
||||||
|
this.waiting = function (msg) {
|
||||||
|
if (msg.action == Action.STOP && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action: Action.STOP,
|
||||||
|
image,
|
||||||
|
time: (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error loading ${image}`));
|
||||||
|
};
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
|
}
|
||||||
|
isConnected() {
|
||||||
|
return this.socketConnected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.FD = FD;
|
exports.FD = FD;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -39,6 +39,7 @@ let fd;
|
||||||
let index;
|
let index;
|
||||||
let port;
|
let port;
|
||||||
let sequences;
|
let sequences;
|
||||||
|
let videos;
|
||||||
let width;
|
let width;
|
||||||
let height;
|
let height;
|
||||||
log.info('Starting filmout_manager...');
|
log.info('Starting filmout_manager...');
|
||||||
|
@ -57,6 +58,7 @@ async function createTemplate(filePath) {
|
||||||
}
|
}
|
||||||
async function settings() {
|
async function settings() {
|
||||||
let sequencesExists = false;
|
let sequencesExists = false;
|
||||||
|
let videosExists = false;
|
||||||
if (typeof process.env['FD'] === 'undefined') {
|
if (typeof process.env['FD'] === 'undefined') {
|
||||||
log.error('Please include an FD value containing the path to your fd binary in .env');
|
log.error('Please include an FD value containing the path to your fd binary in .env');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -115,6 +117,19 @@ async function settings() {
|
||||||
}
|
}
|
||||||
log.info(`SEQUENCES=${sequences}`);
|
log.info(`SEQUENCES=${sequences}`);
|
||||||
}
|
}
|
||||||
|
if (typeof process.env['VIDEOS'] === 'undefined') {
|
||||||
|
log.error('Please include a VIDEOS directory where the videos will be located in .env');
|
||||||
|
process.exit(7);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
videos = process.env['VIDEOS'];
|
||||||
|
videosExists = await files_1.Files.exists(videos);
|
||||||
|
if (!sequencesExists) {
|
||||||
|
log.error(`The VIDEOS directory in .env, ${videos}, does not exist`);
|
||||||
|
process.exit(8);
|
||||||
|
}
|
||||||
|
log.info(`VIDEOS=${videos}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
app.get('/', async (req, res, next) => {
|
app.get('/', async (req, res, next) => {
|
||||||
const dirs = await files_1.Files.enumerateSequences(sequences);
|
const dirs = await files_1.Files.enumerateSequences(sequences);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAsB;AACtB,sDAA8B;AAE9B,2DAA6B;AAI7B,8DAAqC;AAKrC,uDAAyC;AAEzC,+BAAiC;AAEjC,mCAAgC;AAMhC,MAAM,GAAG,GAAY,IAAA,eAAS,EAAC,IAAI,CAAC,CAAC;AACrC,MAAM,GAAG,GAAa,IAAA,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E,CAAC;IACjB,KAAK,GAAG,MAAM,cAAc,CAAC,mBAAmB,CAAC,CAAC;IAClD,6GAA6G;IAC7G,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;QAC3B,GAAG,CAAC,IAAI,CAAC,+CAA+C,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;AACJ,CAAC;AAGD,IAAI,EAAE,CAAC"}
|
|
@ -34,7 +34,14 @@ export interface fdOutgoingMessage {
|
||||||
|
|
||||||
export interface fdIncomingMessage {
|
export interface fdIncomingMessage {
|
||||||
action : Action,
|
action : Action,
|
||||||
success : boolean
|
success : boolean,
|
||||||
|
error? : string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface fdResult {
|
||||||
|
action : Action,
|
||||||
|
image : string,
|
||||||
|
time : number
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FD {
|
export class FD {
|
||||||
|
@ -49,6 +56,8 @@ export class FD {
|
||||||
private socketAvailable : boolean = false;
|
private socketAvailable : boolean = false;
|
||||||
private socketConnected : boolean = false;
|
private socketConnected : boolean = false;
|
||||||
|
|
||||||
|
private waiting : Function = null;
|
||||||
|
|
||||||
constructor (bin: string, width : number, height : number, host : string, port : number) {
|
constructor (bin: string, width : number, height : number, host : string, port : number) {
|
||||||
this.bin = bin;
|
this.bin = bin;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
@ -59,7 +68,6 @@ export class FD {
|
||||||
this.shell = new Shell([ this.bin, `${this.width}`, `${this.height}`, `${this.port}` ], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
this.shell = new Shell([ this.bin, `${this.width}`, `${this.height}`, `${this.port}` ], this.logstd.bind(this), this.logsterr.bind(this), null, true);
|
||||||
this.startDisplay();
|
this.startDisplay();
|
||||||
this.startClient();
|
this.startClient();
|
||||||
this.test();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async startDisplay () {
|
private async startDisplay () {
|
||||||
|
@ -77,12 +85,6 @@ export class FD {
|
||||||
this.client.connect(this.port, this.host, async function () {
|
this.client.connect(this.port, this.host, async function () {
|
||||||
this.socketConnected = true;
|
this.socketConnected = true;
|
||||||
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
this.log.info(`TCP socket client connected to ${this.host}:${this.port}`);
|
||||||
await delay(1000);
|
|
||||||
const msg : fdOutgoingMessage = {
|
|
||||||
action : Action.LOAD,
|
|
||||||
image : './test.jpg'
|
|
||||||
};
|
|
||||||
this.send(msg);
|
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.client.on('data', function (data : string) {
|
this.client.on('data', function (data : string) {
|
||||||
|
@ -109,24 +111,22 @@ export class FD {
|
||||||
this.log.error(`[shell] ${data}`);
|
this.log.error(`[shell] ${data}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async test () {
|
|
||||||
await delay(10000);
|
|
||||||
this.shell.kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
private send (msg : fdOutgoingMessage) {
|
private send (msg : fdOutgoingMessage) {
|
||||||
const json : string = JSON.stringify(msg);
|
const json : string = JSON.stringify(msg);
|
||||||
this.log.info(json);
|
this.log.info(json);
|
||||||
this.client.write(json);
|
this.client.write(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private receive (json : string) : fdIncomingMessage {
|
private receive (json : string) {
|
||||||
const msg : fdIncomingMessage = JSON.parse(json);
|
const msg : fdIncomingMessage = JSON.parse(json);
|
||||||
this.log.info(msg);
|
this.log.info(msg);
|
||||||
return msg;
|
if (this.waiting != null) {
|
||||||
|
this.waiting(msg);
|
||||||
|
this.waiting = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async load (image : string, x : number, y : number, w : number, h : number) : Promise<boolean> {
|
public async load (image : string, x : number, y : number, w : number, h : number) : Promise<fdResult> {
|
||||||
const msg : fdOutgoingMessage = {
|
const msg : fdOutgoingMessage = {
|
||||||
action : Action.LOAD,
|
action : Action.LOAD,
|
||||||
image,
|
image,
|
||||||
|
@ -135,27 +135,76 @@ export class FD {
|
||||||
w,
|
w,
|
||||||
h
|
h
|
||||||
};
|
};
|
||||||
|
const startTime : number = +new Date();
|
||||||
|
const promise : Promise<fdResult> = new Promise(function (resolve : Function, reject : Function) {
|
||||||
|
this.waiting = function (msg : fdIncomingMessage) {
|
||||||
|
if (msg.action == Action.LOAD && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action : Action.LOAD,
|
||||||
|
image,
|
||||||
|
time : (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
} else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error loading ${image}`));
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async display (image : string, exposure : number[]) : Promise<boolean> {
|
public async display (image : string, exposure : number[]) : Promise<fdResult> {
|
||||||
const msg : fdOutgoingMessage = {
|
const msg : fdOutgoingMessage = {
|
||||||
action : Action.DISPLAY,
|
action : Action.DISPLAY,
|
||||||
image,
|
image,
|
||||||
exposure
|
exposure
|
||||||
};
|
};
|
||||||
|
const startTime : number = +new Date();
|
||||||
|
const promise : Promise<fdResult> = new Promise(function (resolve : Function, reject : Function) {
|
||||||
|
this.waiting = function (msg : fdIncomingMessage) {
|
||||||
|
if (msg.action == Action.DISPLAY && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action : Action.DISPLAY,
|
||||||
|
image,
|
||||||
|
time : (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
} else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error displaying ${image}`));
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop (image : string) : Promise<boolean> {
|
public async stop (image : string) : Promise<fdResult> {
|
||||||
const msg : fdOutgoingMessage = {
|
const msg : fdOutgoingMessage = {
|
||||||
action : Action.STOP,
|
action : Action.STOP,
|
||||||
image
|
image
|
||||||
};
|
};
|
||||||
|
const startTime : number = +new Date();
|
||||||
|
const promise : Promise<fdResult> = new Promise(function (resolve : Function, reject : Function) {
|
||||||
|
this.waiting = function (msg : fdIncomingMessage) {
|
||||||
|
if (msg.action == Action.STOP && msg.success) {
|
||||||
|
return resolve({
|
||||||
|
action : Action.STOP,
|
||||||
|
image,
|
||||||
|
time : (+new Date()) - startTime
|
||||||
|
});
|
||||||
|
} else if (typeof msg.error !== 'undefined') {
|
||||||
|
return reject(new Error(msg.error));
|
||||||
|
}
|
||||||
|
return reject(new Error(`Error loading ${image}`));
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
this.send(msg);
|
this.send(msg);
|
||||||
return true;
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isConnected () : boolean {
|
||||||
|
return this.socketConnected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/index.ts
16
src/index.ts
|
@ -11,6 +11,7 @@ import { v4 as uuid } from 'uuid';
|
||||||
import getType from 'mime';
|
import getType from 'mime';
|
||||||
import type { Logger } from 'winston';
|
import type { Logger } from 'winston';
|
||||||
import * as Handlebars from 'handlebars';
|
import * as Handlebars from 'handlebars';
|
||||||
|
import { Server } from 'ws';
|
||||||
|
|
||||||
import { createLog } from './log'
|
import { createLog } from './log'
|
||||||
import { sendMail } from './mail';
|
import { sendMail } from './mail';
|
||||||
|
@ -27,6 +28,7 @@ let index : HandlebarsTemplateDelegate<any>;
|
||||||
|
|
||||||
let port : number;
|
let port : number;
|
||||||
let sequences : string;
|
let sequences : string;
|
||||||
|
let videos : string;
|
||||||
let width : number;
|
let width : number;
|
||||||
let height : number;
|
let height : number;
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ async function createTemplate (filePath : string) : Promise<HandlebarsTemplateDe
|
||||||
|
|
||||||
async function settings () {
|
async function settings () {
|
||||||
let sequencesExists : boolean = false;
|
let sequencesExists : boolean = false;
|
||||||
|
let videosExists : boolean = false;
|
||||||
if (typeof process.env['FD'] === 'undefined') {
|
if (typeof process.env['FD'] === 'undefined') {
|
||||||
log.error('Please include an FD value containing the path to your fd binary in .env');
|
log.error('Please include an FD value containing the path to your fd binary in .env');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -99,6 +102,18 @@ async function settings () {
|
||||||
}
|
}
|
||||||
log.info(`SEQUENCES=${sequences}`);
|
log.info(`SEQUENCES=${sequences}`);
|
||||||
}
|
}
|
||||||
|
if (typeof process.env['VIDEOS'] === 'undefined') {
|
||||||
|
log.error('Please include a VIDEOS directory where the videos will be located in .env');
|
||||||
|
process.exit(7);
|
||||||
|
} else {
|
||||||
|
videos = process.env['VIDEOS'];
|
||||||
|
videosExists = await Files.exists(videos);
|
||||||
|
if (!sequencesExists) {
|
||||||
|
log.error(`The VIDEOS directory in .env, ${videos}, does not exist`);
|
||||||
|
process.exit(8);
|
||||||
|
}
|
||||||
|
log.info(`VIDEOS=${videos}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', async (req : Request, res : Response, next : NextFunction) => {
|
app.get('/', async (req : Request, res : Response, next : NextFunction) => {
|
||||||
|
@ -116,4 +131,5 @@ async function main () {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main();
|
main();
|
Loading…
Reference in New Issue