Added skeleton function for recording.
parent
5a637ce866
commit
e128bdcdaa
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
media
|
||||||
|
|
36
server.js
36
server.js
|
@ -1,6 +1,8 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
exports.__esModule = true;
|
exports.__esModule = true;
|
||||||
var NodeMediaServer = require("node-media-server");
|
var NodeMediaServer = require("node-media-server");
|
||||||
|
var fs = require("fs");
|
||||||
|
var exec = require('child_process').exec;
|
||||||
var ircd = require("./lib/ircdjs/lib/server.js").Server;
|
var ircd = require("./lib/ircdjs/lib/server.js").Server;
|
||||||
//initialize configs, eventually grab from runtime config file
|
//initialize configs, eventually grab from runtime config file
|
||||||
var mediaconfig = {
|
var mediaconfig = {
|
||||||
|
@ -13,7 +15,18 @@ var mediaconfig = {
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
port: 8000,
|
port: 8000,
|
||||||
allow_origin: '*'
|
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) {
|
function streamAuth(path) {
|
||||||
|
@ -56,6 +69,7 @@ nms.on('prePublish', function (id, StreamPath, args) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
console.log("[NodeMediaServer] App name ok.");
|
console.log("[NodeMediaServer] App name ok.");
|
||||||
|
//TODO: Hook up to DB and redirect from query
|
||||||
if (key !== "temp") {
|
if (key !== "temp") {
|
||||||
console.log("[NodeMediaServer] Invalid stream key, closing connection.");
|
console.log("[NodeMediaServer] Invalid stream key, closing connection.");
|
||||||
session.reject();
|
session.reject();
|
||||||
|
@ -64,3 +78,23 @@ nms.on('prePublish', function (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', function (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 }, function (err) {
|
||||||
|
if (err)
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
//we kinda stanitize it in prePublish? :blobshrug:
|
||||||
|
var 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);
|
||||||
|
});
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import NodeMediaServer = require("node-media-server");
|
import NodeMediaServer = require("node-media-server");
|
||||||
|
import fs = require ("fs");
|
||||||
|
const { exec } = require('child_process');
|
||||||
const ircd = require("./lib/ircdjs/lib/server.js").Server;
|
const ircd = require("./lib/ircdjs/lib/server.js").Server;
|
||||||
|
|
||||||
//initialize configs, eventually grab from runtime config file
|
//initialize configs, eventually grab from runtime config file
|
||||||
|
@ -12,7 +14,18 @@ const mediaconfig = {
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
port:8000,
|
port:8000,
|
||||||
allow_origin: '*'
|
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]'
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,3 +82,22 @@ 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) => {
|
||||||
|
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}`);
|
||||||
|
});
|
Reference in New Issue