mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-05-06 22:29:24 +00:00
Added executable
Added controller file to launch other processes Moved compile dir to build
This commit is contained in:
parent
4309da7c39
commit
d05c59c896
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
node_modules
|
||||
media
|
||||
server.js
|
||||
chanbot.js
|
||||
build/**
|
||||
lib/inspircd-*
|
||||
|
3
satyr
Executable file
3
satyr
Executable file
@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env node
|
||||
const satyr = require("./build/controller");
|
||||
satyr.boot();
|
29
src/controller.ts
Normal file
29
src/controller.ts
Normal 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 };
|
137
src/server.ts
137
src/server.ts
@ -1,34 +1,13 @@
|
||||
import NodeMediaServer = require('node-media-server');
|
||||
import fs = require('fs');
|
||||
import * as NodeMediaServer from "node-media-server";
|
||||
import { mkdir } from "fs";
|
||||
const { exec } = require('child_process');
|
||||
|
||||
//initialize configs, eventually grab from runtime config file
|
||||
const mediaconfig = {
|
||||
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 initConfig(): void{
|
||||
;
|
||||
}
|
||||
|
||||
function streamAuth(path: string){
|
||||
/*function streamAuth(path: string){
|
||||
if (path.split("/").length > 3){
|
||||
console.log("[NodeMediaServer] Malformed URL, closing connection.");
|
||||
return false;
|
||||
@ -47,55 +26,57 @@ function streamAuth(path: string){
|
||||
}
|
||||
console.log("[NodeMediaServer] Stream key ok.");
|
||||
return true;
|
||||
}*/
|
||||
|
||||
function boot (config: any){
|
||||
const nms = new NodeMediaServer(config);
|
||||
|
||||
nms.run();
|
||||
|
||||
nms.on('prePublish', (id, StreamPath, args) => {
|
||||
console.log("[NodeMediaServer] Prepublish Hook for stream id=",id);
|
||||
let session = nms.getSession(id);
|
||||
if (StreamPath.split("/").length > 3){
|
||||
console.log("[NodeMediaServer] Malformed URL, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
let app: string = StreamPath.split("/")[1];
|
||||
let key: string = StreamPath.split("/")[2];
|
||||
console.log("[NodeMediaServer] Authenticating stream with credentials: ",`app=${app} key=${key}`);
|
||||
if (app !== "stream"){
|
||||
console.log("[NodeMediaServer] Invalid app name, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
console.log("[NodeMediaServer] App name ok.");
|
||||
//TODO: Hook up to DB and redirect from query
|
||||
if (key !== "temp"){
|
||||
console.log("[NodeMediaServer] Invalid stream key, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
console.log("[NodeMediaServer] Stream key ok.");
|
||||
session.publishStreamPath = "/live/amy";
|
||||
});
|
||||
|
||||
nms.on('postPublish', (id, StreamPath, args) => {
|
||||
console.log('[NodeMediaServer] Checking record flag for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
//Hook up to postgres DB.
|
||||
if(true){
|
||||
console.log('[NodeMediaServer] Initiating recording for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
mkdir('./media'+StreamPath, { recursive : true }, (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',{
|
||||
detached : true,
|
||||
stdio : 'inherit'
|
||||
});
|
||||
subprocess.unref();
|
||||
//spawn an ffmpeg process to record the stream, then detach it completely
|
||||
return true;
|
||||
}
|
||||
console.log('[NodeMediaServer] Skipping recording for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const nms = new NodeMediaServer(mediaconfig);
|
||||
|
||||
nms.run();
|
||||
|
||||
nms.on('prePublish', (id, StreamPath, args) => {
|
||||
console.log("[NodeMediaServer] Prepublish Hook for stream id=",id);
|
||||
let session = nms.getSession(id);
|
||||
if (StreamPath.split("/").length > 3){
|
||||
console.log("[NodeMediaServer] Malformed URL, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
let app: string = StreamPath.split("/")[1];
|
||||
let key: string = StreamPath.split("/")[2];
|
||||
console.log("[NodeMediaServer] Authenticating stream with credentials: ",`app=${app} key=${key}`);
|
||||
if (app !== "stream"){
|
||||
console.log("[NodeMediaServer] Invalid app name, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
console.log("[NodeMediaServer] App name ok.");
|
||||
//TODO: Hook up to DB and redirect from query
|
||||
if (key !== "temp"){
|
||||
console.log("[NodeMediaServer] Invalid stream key, closing connection.");
|
||||
session.reject();
|
||||
return false;
|
||||
}
|
||||
console.log("[NodeMediaServer] Stream key ok.");
|
||||
session.publishStreamPath = "/live/amy";
|
||||
});
|
||||
|
||||
nms.on('postPublish', (id, StreamPath, args) => {
|
||||
console.log('[NodeMediaServer] Checking record flag for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
//Hook up to postgres DB.
|
||||
if(true){
|
||||
console.log('[NodeMediaServer] Initiating recording for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
fs.mkdir('./media'+StreamPath, { recursive : true }, (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',{
|
||||
detached : true,
|
||||
stdio : 'inherit'
|
||||
});
|
||||
subprocess.unref();
|
||||
//spawn an ffmpeg process to record the stream, then detach it completely
|
||||
return true;
|
||||
}
|
||||
console.log('[NodeMediaServer] Skipping recording for ', `id=${id} StreamPath=${StreamPath}`);
|
||||
});
|
||||
export { boot };
|
@ -1,13 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir":".",
|
||||
"outDir":"./build",
|
||||
"allowJs":true
|
||||
},
|
||||
"include":[
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude":[
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user