Compare commits

...

3 Commits

8 changed files with 174 additions and 42 deletions

View File

@ -7,4 +7,5 @@ HEIGHT=1600
FD=../filmout_display/build/bin/fd
FD_HOST=localhost
FD_PORT=8081
VIDEOS=/home/users/VIDEOS
SEQUENCES=/home/user/SEQUENCES

15
dist/fd/index.d.ts vendored
View File

@ -25,6 +25,12 @@ export interface fdOutgoingMessage {
export interface fdIncomingMessage {
action: Action;
success: boolean;
error?: string;
}
export interface fdResult {
action: Action;
image: string;
time: number;
}
export declare class FD {
private bin;
@ -37,16 +43,17 @@ export declare class FD {
private client;
private socketAvailable;
private socketConnected;
private waiting;
constructor(bin: string, width: number, height: number, host: string, port: number);
private startDisplay;
private startClient;
private logstd;
private logsterr;
private test;
private send;
private receive;
load(image: string, x: number, y: number, w: number, h: number): Promise<boolean>;
display(image: string, exposure: number[]): Promise<boolean>;
stop(image: string): Promise<boolean>;
load(image: string, x: number, y: number, w: number, h: number): Promise<fdResult>;
display(image: string, exposure: number[]): Promise<fdResult>;
stop(image: string): Promise<fdResult>;
isConnected(): boolean;
}
export {};

74
dist/fd/index.js vendored
View File

@ -28,6 +28,7 @@ class FD {
constructor(bin, width, height, host, port) {
this.socketAvailable = false;
this.socketConnected = false;
this.waiting = null;
this.bin = bin;
this.width = width;
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.startDisplay();
this.startClient();
this.test();
}
async startDisplay() {
this.log.info(`Launching fd binary ${this.bin}`);
@ -53,12 +53,6 @@ class FD {
this.client.connect(this.port, this.host, async function () {
this.socketConnected = true;
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));
this.client.on('data', function (data) {
this.receive(data);
@ -79,10 +73,6 @@ class FD {
logsterr(data) {
this.log.error(`[shell] ${data}`);
}
async test() {
await (0, delay_1.delay)(10000);
this.shell.kill();
}
send(msg) {
const json = JSON.stringify(msg);
this.log.info(json);
@ -91,7 +81,10 @@ class FD {
receive(json) {
const msg = JSON.parse(json);
this.log.info(msg);
return msg;
if (this.waiting != null) {
this.waiting(msg);
this.waiting = null;
}
}
async load(image, x, y, w, h) {
const msg = {
@ -102,8 +95,24 @@ class FD {
w,
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);
return true;
return promise;
}
async display(image, exposure) {
const msg = {
@ -111,16 +120,51 @@ class FD {
image,
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);
return true;
return promise;
}
async stop(image) {
const msg = {
action: Action.STOP,
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);
return true;
return promise;
}
isConnected() {
return this.socketConnected;
}
}
exports.FD = FD;

File diff suppressed because one or more lines are too long

15
dist/index.js vendored
View File

@ -39,6 +39,7 @@ let fd;
let index;
let port;
let sequences;
let videos;
let width;
let height;
log.info('Starting filmout_manager...');
@ -57,6 +58,7 @@ async function createTemplate(filePath) {
}
async function settings() {
let sequencesExists = false;
let videosExists = false;
if (typeof process.env['FD'] === 'undefined') {
log.error('Please include an FD value containing the path to your fd binary in .env');
process.exit(1);
@ -115,6 +117,19 @@ async function settings() {
}
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) => {
const dirs = await files_1.Files.enumerateSequences(sequences);

2
dist/index.js.map vendored
View File

@ -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,iBAAO,GAAE,CAAC;AAChC,IAAI,EAAO,CAAC;AACZ,IAAI,KAAuC,CAAC;AAE5C,IAAI,IAAa,CAAC;AAClB,IAAI,SAAkB,CAAC;AACvB,IAAI,KAAc,CAAC;AACnB,IAAI,MAAe,CAAC;AAEpB,GAAG,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAExC,GAAG,CAAC,GAAG,CAAC,qBAAU,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3B,GAAG,CAAC,GAAG,CAAC,qBAAU,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;AAEnD,KAAK,UAAU,cAAc,CAAE,QAAiB;IAC/C,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACJ,IAAI,GAAG,MAAM,kBAAE,CAAC,QAA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QAAQ,CAAC,CAAC;QAC/B,YAAY,GAAG,MAAM,aAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,eAAe,EAAE,CAAC;YACtB,GAAG,CAAC,KAAK,CAAC,iCAAiC,MAAM,kBAAkB,CAAC,CAAC;YACrE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,UAAU,MAAM,EAAE,CAAC,CAAC;IAC9B,CAAC;AACF,CAAC;AAED,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAa,EAAE,GAAc,EAAE,IAAmB,EAAE,EAAE;IACzE,MAAM,IAAI,GAAsB,MAAM,aAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC1E,MAAM,IAAI,GAAY,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IAClB,MAAM,QAAQ,EAAE,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"}

View File

@ -34,7 +34,14 @@ export interface fdOutgoingMessage {
export interface fdIncomingMessage {
action : Action,
success : boolean
success : boolean,
error? : string
}
export interface fdResult {
action : Action,
image : string,
time : number
}
export class FD {
@ -49,6 +56,8 @@ export class FD {
private socketAvailable : boolean = false;
private socketConnected : boolean = false;
private waiting : Function = null;
constructor (bin: string, width : number, height : number, host : string, port : number) {
this.bin = bin;
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.startDisplay();
this.startClient();
this.test();
}
private async startDisplay () {
@ -77,12 +85,6 @@ export class FD {
this.client.connect(this.port, this.host, async function () {
this.socketConnected = true;
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));
this.client.on('data', function (data : string) {
@ -109,24 +111,22 @@ export class FD {
this.log.error(`[shell] ${data}`);
}
private async test () {
await delay(10000);
this.shell.kill();
}
private send (msg : fdOutgoingMessage) {
const json : string = JSON.stringify(msg);
this.log.info(json);
this.client.write(json);
}
private receive (json : string) : fdIncomingMessage {
private receive (json : string) {
const msg : fdIncomingMessage = JSON.parse(json);
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 = {
action : Action.LOAD,
image,
@ -135,27 +135,76 @@ export class FD {
w,
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);
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 = {
action : Action.DISPLAY,
image,
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);
return true;
return promise;
}
public async stop (image : string) : Promise<boolean> {
public async stop (image : string) : Promise<fdResult> {
const msg : fdOutgoingMessage = {
action : Action.STOP,
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);
return true;
return promise;
}
public isConnected () : boolean {
return this.socketConnected;
}
}

View File

@ -11,6 +11,7 @@ import { v4 as uuid } from 'uuid';
import getType from 'mime';
import type { Logger } from 'winston';
import * as Handlebars from 'handlebars';
import { Server } from 'ws';
import { createLog } from './log'
import { sendMail } from './mail';
@ -27,6 +28,7 @@ let index : HandlebarsTemplateDelegate<any>;
let port : number;
let sequences : string;
let videos : string;
let width : number;
let height : number;
@ -48,6 +50,7 @@ async function createTemplate (filePath : string) : Promise<HandlebarsTemplateDe
async function settings () {
let sequencesExists : boolean = false;
let videosExists : boolean = false;
if (typeof process.env['FD'] === 'undefined') {
log.error('Please include an FD value containing the path to your fd binary in .env');
process.exit(1);
@ -99,6 +102,18 @@ async function settings () {
}
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) => {
@ -116,4 +131,5 @@ async function main () {
});
}
main();