Added executable

Added controller file to launch other processes
Moved compile dir to build
merge-requests/1/merge
knotteye 2019-09-20 11:09:15 -05:00
parent 4309da7c39
commit d05c59c896
5 changed files with 93 additions and 85 deletions

3
.gitignore vendored
View File

@ -1,5 +1,4 @@
node_modules node_modules
media media
server.js build/**
chanbot.js
lib/inspircd-* lib/inspircd-*

3
satyr Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env node
const satyr = require("./build/controller");
satyr.boot();

29
src/controller.ts Normal file
View File

@ -0,0 +1,29 @@
import * as mediaserver from "./server";
function boot(): void{
const mediaconfig: any = {
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
http: {
port:8000,
allow_origin: '*',
mediaroot: './media'
},
trans: {
ffmpeg: '/usr/bin/ffmpeg',
tasks: [
{
app: 'live',
hls: 'true',
hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]'
}
]
}
};
mediaserver.boot(mediaconfig);
}
export { boot };

View File

@ -1,34 +1,13 @@
import NodeMediaServer = require('node-media-server'); import * as NodeMediaServer from "node-media-server";
import fs = require('fs'); import { mkdir } from "fs";
const { exec } = require('child_process'); const { exec } = require('child_process');
//initialize configs, eventually grab from runtime config file //initialize configs, eventually grab from runtime config file
const mediaconfig = { function initConfig(): void{
rtmp: { ;
port: 1935, }
chunk_size: 60000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
http: {
port:8000,
allow_origin: '*',
mediaroot: './media'
},
trans: {
ffmpeg: '/usr/bin/ffmpeg',
tasks: [
{
app: 'live',
hls: 'true',
hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]'
}
]
}
};
function streamAuth(path: string){ /*function streamAuth(path: string){
if (path.split("/").length > 3){ if (path.split("/").length > 3){
console.log("[NodeMediaServer] Malformed URL, closing connection."); console.log("[NodeMediaServer] Malformed URL, closing connection.");
return false; return false;
@ -47,14 +26,14 @@ function streamAuth(path: string){
} }
console.log("[NodeMediaServer] Stream key ok."); console.log("[NodeMediaServer] Stream key ok.");
return true; return true;
} }*/
function boot (config: any){
const nms = new NodeMediaServer(config);
const nms = new NodeMediaServer(mediaconfig); nms.run();
nms.run(); nms.on('prePublish', (id, StreamPath, args) => {
nms.on('prePublish', (id, StreamPath, args) => {
console.log("[NodeMediaServer] Prepublish Hook for stream id=",id); console.log("[NodeMediaServer] Prepublish Hook for stream id=",id);
let session = nms.getSession(id); let session = nms.getSession(id);
if (StreamPath.split("/").length > 3){ if (StreamPath.split("/").length > 3){
@ -79,14 +58,14 @@ nms.on('prePublish', (id, StreamPath, args) => {
} }
console.log("[NodeMediaServer] Stream key ok."); console.log("[NodeMediaServer] Stream key ok.");
session.publishStreamPath = "/live/amy"; session.publishStreamPath = "/live/amy";
}); });
nms.on('postPublish', (id, StreamPath, args) => { nms.on('postPublish', (id, StreamPath, args) => {
console.log('[NodeMediaServer] Checking record flag for ', `id=${id} StreamPath=${StreamPath}`); console.log('[NodeMediaServer] Checking record flag for ', `id=${id} StreamPath=${StreamPath}`);
//Hook up to postgres DB. //Hook up to postgres DB.
if(true){ if(true){
console.log('[NodeMediaServer] Initiating recording for ', `id=${id} StreamPath=${StreamPath}`); console.log('[NodeMediaServer] Initiating recording for ', `id=${id} StreamPath=${StreamPath}`);
fs.mkdir('./media'+StreamPath, { recursive : true }, (err) => { mkdir('./media'+StreamPath, { recursive : true }, (err) => {
if (err) throw err; if (err) throw err;
}); });
let subprocess = exec('ffmpeg -i rtmp://127.0.0.1'+StreamPath+' -vcodec copy -acodec copy ./media'+StreamPath+'/$(date +%d%b%Y-%H%M).mp4',{ let subprocess = exec('ffmpeg -i rtmp://127.0.0.1'+StreamPath+' -vcodec copy -acodec copy ./media'+StreamPath+'/$(date +%d%b%Y-%H%M).mp4',{
@ -98,4 +77,6 @@ nms.on('postPublish', (id, StreamPath, args) => {
return true; return true;
} }
console.log('[NodeMediaServer] Skipping recording for ', `id=${id} StreamPath=${StreamPath}`); console.log('[NodeMediaServer] Skipping recording for ', `id=${id} StreamPath=${StreamPath}`);
}); });
}
export { boot };

View File

@ -1,13 +1,9 @@
{ {
"compilerOptions": { "compilerOptions": {
"outDir":".", "outDir":"./build",
"allowJs":true "allowJs":true
}, },
"include":[ "include":[
"src/**/*" "src/**/*"
], ],
"exclude":[
"node_modules",
"lib"
]
} }