From 6bd074717548a94f2ea4776178483b44039ffaa9 Mon Sep 17 00:00:00 2001 From: GLDuval Date: Sun, 7 May 2023 14:15:31 -0400 Subject: [PATCH] Small fixes --- script/rtspServer.js | 12 +++++++++++- src/main/rtspServer.ts | 5 +++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/script/rtspServer.js b/script/rtspServer.js index 6f8383e6..76a166b9 100644 --- a/script/rtspServer.js +++ b/script/rtspServer.js @@ -3,13 +3,23 @@ const Stream = require('node-rtsp-stream'); // Get node args const args = process.argv.slice(2); +// Check if required arguments are present +if (args.length < 2) { + const filename = __filename.split('/').pop(); + // eslint-disable-next-line no-console + console.error( + `Missing Arguments! Usage: node ${filename} ` + ); + process.exit(1); +} + new Stream({ name: 'RTSP-Stream', streamUrl: args[0], wsPort: parseInt(args[1]), ffmpegOptions: { // options ffmpeg flags - '-r': 30, // options with required values specify the value after the key + '-re': '', // read input at native frame rate '-q': 0, // quality video in scale [0, 32] }, }); diff --git a/src/main/rtspServer.ts b/src/main/rtspServer.ts index ab65fa2b..d59af8cd 100644 --- a/src/main/rtspServer.ts +++ b/src/main/rtspServer.ts @@ -3,6 +3,7 @@ import { app, ipcMain } from 'electron'; import { ExecaChildProcess, execa } from 'execa'; import path from 'path'; import { isDev } from '@/main/isDev'; +import { RTSP_START, RTSP_STOP } from './preload'; interface RtspProcess { process: ExecaChildProcess; @@ -14,7 +15,7 @@ const rtspServers: Map = new Map(); // Stack array of ports from (9000 to 9060) to use for rtsp servers const ports = Array.from({ length: 61 }, (_, i) => i + 9000); -ipcMain.handle('rtsp_start', (event, url: string) => { +ipcMain.handle(RTSP_START, (_, url: string) => { const nextPort = ports.shift() ?? 9000; const process = execa('node', [ isDev @@ -32,7 +33,7 @@ ipcMain.handle('rtsp_start', (event, url: string) => { return nextPort; }); -ipcMain.on('rtsp_stop', (event, port: number) => { +ipcMain.on(RTSP_STOP, (_, port: number) => { const rtspProcess = rtspServers.get(port); if (!rtspProcess) {