excuse the bad English! I'm using Nest js, and the scenejs/render library https://github.com/daybrush/scenejs-render to generate a video from the animation created, everything in the local server works perfect but in the remote server it doesn't do anything, it finishes the process immediately.
One important thing is that I test the command directly in the ssh console and it works perfectly.
I run dist/main.js and everything works fine but when I create the service on the server it does nothing
this is my parent class
<pre>
import {
ChildProcess,
SendHandle,
Serializable,
spawn
} from 'child_process';
type onMessageCallback = (
message: Serializable,
sendHandle: SendHandle,
) => void;
type onErrorCallback = (error: Error) => void;
type onFinishedCallback = (code: number, signal: string) => void;
type onDisconnectCallback = () => void;
type onChangeStatusCallback = (processStatus: Serializable, sendHandle: SendHandle) => void;
export class TerminalProccess {
protected proccess: ChildProcess;
constructor(protected command: string, protected options: string[], path?: string) {
this.proccess = spawn(command, options, {cwd: path});
}
public onChangeStatus(callback: onChangeStatusCallback){
this.proccess.stdout.on('data', callback)
}
public onMessage(callback: onMessageCallback) {
this.proccess.on('message', callback);
}
public onError(callback: onErrorCallback) {
this.proccess.on('error', callback);
}
public onClose(callback: onFinishedCallback) {
this.proccess.on('close', callback);
}
public onDisconnect(callback: onDisconnectCallback) {
this.proccess.on('disconnect', callback);
}
public onExit(callback: onFinishedCallback) {
this.proccess.on('exit', callback);
}
public kill() {
this.proccess.kill();
}
}
</pre>
this is my child class
<pre>
import { Logger } from '@nestjs/common';
import { Serializable } from 'child_process';
import { Server } from 'socket.io';
import { TerminalProccess } from './proccess.class';
import { RedisData } from './redis.class';
import { NotifySockets } from '../websockets/notify.class'
import * as fs from 'fs';
// const fs = require('fs');
export class VideoRenderProccess extends TerminalProccess {
private percentageValue: number = 0;
// private path: string;
private notify: NotifySockets;
private redis: RedisData;
private endFrameValue: number;
private currentFrameValue: number = 0;
private step: number = 1;
private uuid: string;
private logger: Logger = new Logger('status render video')
constructor(
uuid: string,
port: number = 3100,
notify: NotifySockets,
redis: RedisData,
command: string = 'render',
options: string[] = [
'-i',
`index.html`,
'-o',
`video.mp4`,
'--port',
`${port}`,
'--media',
`${uuid}`,
'--multi',
'4'
]) {
super(command, options, `${process.env.SRC_VIDEOS_ROOT}${uuid}`);
console.log(command, options, uuid);
this.onMessage(this.printMessage);
this.onError(this.printError);
this.onChangeStatus(this.printMessage.bind(this));
this.onClose(this.sendNotifyComplete.bind(this));
this.notify = notify;
this.redis = redis;
this.uuid = uuid;
}
private async printMessage(message: Serializable) {
this.getPercentage(message.toString())
this.onPercentageChange()
const messageSend = {
percentage: this.percentage,
step: this.getStep
}
const clientId = await this.getCliente(this.uuid)
this.notify.notify(JSON.stringify(messageSend), clientId, "percentage-updated")
this.logger.log('VideoRenderProccess message: ' + message);
}
private getPercentage(data) {
if (data.includes('Start Capture')) {
const regExp = /\(([^)]+)\)/;
const matches = regExp.exec(data);
const arrayData = matches[1].split(",")
const endFrameData = arrayData[4].split(":")
const endFrameNumber: number = parseInt(endFrameData[1])
this.setEndFrame(endFrameNumber)
} else if (data.includes('Capture frame')) {
this.setcurrentFrameValue()
} else if (data.includes('Processing')) {
const arrayData = data.split(":")
this.setcurrentFrameValue(parseInt(arrayData[1]))
this.setStep(2)
}
}
setEndFrame(number) {
this.endFrameValue = number;
}
get getEndFrame() {
return this.endFrameValue;
}
setStep(number) {
this.step = number;
}
get getStep() {
return this.step;
}
setcurrentFrameValue(number?) {
if (!number) {
this.currentFrameValue += 1;
} else {
this.currentFrameValue = number;
}
}
get getcurrentFrameValue() {
return this.currentFrameValue;
}
set percentage(number: number) {
this.percentageValue = number;
}
get percentage() {
return this.percentageValue;
}
onPercentageChange() {
this.percentage = this.getcurrentFrameValue * 100 / this.getEndFrame
}
private printError(error: Error) {
console.log('VideoRenderProccess error: ' + error);
}
private async sendNotifyComplete(code: number, signal: string) {
const existVideo = await this.validateIfExistsVideo()
let messageSend = {}
if(existVideo){
messageSend = {
status: 'success',
uuid: this.uuid,
percentage: 100
}
} else {
messageSend = {
status: 'error',
uuid: this.uuid,
percentage: 0
}
}
const clientId = await this.getCliente(this.uuid)
this.notify.notify(JSON.stringify(messageSend), clientId, 'endCreateVideo')
this.redis.delete(clientId);
this.redis.delete(this.uuid);
}
private async getCliente(proccess: string){
const clientId = await this.redis.getData(proccess)
return clientId;
}
private async validateIfExistsVideo(){
try {
const path = process.env.SRC_VIDEOS_ROOT + this.uuid + '/video.mp4'
if(fs.existsSync(path)) {
console.log("The file exists.");
return true
} else {
console.log('The file does not exist.');
}
} catch (err) {
console.error(err);
}
}
}
</pre>
And this is my service
[enter image description here][1]
[1]: https://i.stack.imgur.com/Fa5kj.jpgenter code here