Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GLDuval committed May 7, 2023
1 parent 112c228 commit 6bd0747
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 11 additions & 1 deletion script/rtspServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} <rtsp-url> <websocket-port>`
);
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]
},
});
5 changes: 3 additions & 2 deletions src/main/rtspServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,7 +15,7 @@ const rtspServers: Map<number, RtspProcess> = 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
Expand All @@ -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) {
Expand Down

0 comments on commit 6bd0747

Please sign in to comment.