Merge branch 'dev'
commit
e197f0674f
|
@ -192,20 +192,11 @@ module.exports = (s,config,lang) => {
|
|||
//`e` is the monitor object
|
||||
//`x` is an object used to contain temporary values.
|
||||
const channelStreamDirectory = !isNaN(parseInt(number)) ? `${e.sdir || s.getStreamsDirectory(e)}channel${number}/` : e.sdir
|
||||
if(channelStreamDirectory !== e.sdir){
|
||||
if (fs.existsSync(channelStreamDirectory)) {
|
||||
try {
|
||||
fs.rmSync(channelStreamDirectory, { recursive: true, force: true })
|
||||
}catch(err){
|
||||
// s.debugLog(err)
|
||||
}
|
||||
}
|
||||
if (!fs.existsSync(channelStreamDirectory)) {
|
||||
try {
|
||||
fs.mkdirSync(channelStreamDirectory)
|
||||
}catch(err){
|
||||
// s.debugLog(err)
|
||||
}
|
||||
if(channelStreamDirectory !== e.sdir && !fs.existsSync(channelStreamDirectory)){
|
||||
try {
|
||||
fs.mkdirSync(channelStreamDirectory)
|
||||
}catch(err){
|
||||
// s.debugLog(err)
|
||||
}
|
||||
}
|
||||
const channelNumber = number - config.pipeAddition
|
||||
|
@ -448,7 +439,7 @@ module.exports = (s,config,lang) => {
|
|||
}
|
||||
if((!videoCodecisCopy || outputRequiresEncoding) && !e.details.hwaccel_format){
|
||||
if(videoWidth && videoHeight)streamFlags.push(`-s ${videoWidth}x${videoHeight}`)
|
||||
if(videoFps && streamType === 'mjpeg' || streamType === 'b64' || videoFps && !videoCodecisCopy){
|
||||
if(videoFps && streamType === 'mjpeg' || videoFps && streamType === 'b64' || videoFps && !videoCodecisCopy){
|
||||
streamFilters.push(`fps=${videoFps}`)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ module.exports = (s,config,lang) => {
|
|||
mid: activeMonitor.mid,
|
||||
ke: activeMonitor.ke,
|
||||
channel: activeMonitor.subStreamChannel
|
||||
},'GRP_'+activeMonitor.mid);
|
||||
},'GRP_'+activeMonitor.ke);
|
||||
}
|
||||
const spawnSubstreamProcess = function(e){
|
||||
// e = monitorConfig
|
||||
|
@ -395,26 +395,6 @@ module.exports = (s,config,lang) => {
|
|||
},2000)
|
||||
}
|
||||
})
|
||||
activeMonitor.subStreamOutputReady = false;
|
||||
if (outputFields.stream_type == 'hls') {
|
||||
const channelStream = subStreamProcess.spawnargs.at(-1);
|
||||
activeMonitor.subStreamOutputReadyCheck = setInterval(function () {
|
||||
if (fs.existsSync(channelStream)) {
|
||||
activeMonitor.subStreamOutputReady = true;
|
||||
clearInterval(activeMonitor.subStreamOutputReadyCheck);
|
||||
}
|
||||
}, 1000);
|
||||
} else if (outputFields.stream_type == 'mp4') {
|
||||
const pipeNumber = activeMonitor.subStreamChannel + config.pipeAddition;
|
||||
subStreamProcess.stdio[pipeNumber].once('data', (data) => {
|
||||
activeMonitor.subStreamOutputReady = true;
|
||||
});
|
||||
} else {
|
||||
const pipeNumber = activeMonitor.subStreamChannel + config.pipeAddition;
|
||||
activeMonitor.emitterChannel[pipeNumber].once('data', (data) => {
|
||||
activeMonitor.subStreamOutputReady = true;
|
||||
});
|
||||
}
|
||||
activeMonitor.subStreamProcess = subStreamProcess
|
||||
sendSubstreamEvent(groupKey, monitorId)
|
||||
return subStreamProcess
|
||||
|
@ -445,6 +425,7 @@ module.exports = (s,config,lang) => {
|
|||
activeMonitor.subStreamProcessClosing = false
|
||||
}
|
||||
}catch(err){
|
||||
console.error(err)
|
||||
s.debugLog('destroySubstreamProcess',err)
|
||||
}
|
||||
return response
|
||||
|
|
|
@ -95,11 +95,10 @@ module.exports = function(s,config,lang,app){
|
|||
res.end('404 : Monitor not found');
|
||||
return
|
||||
}
|
||||
s.checkChildProxy(req.params,async function(){
|
||||
s.checkChildProxy(req.params,function(){
|
||||
var Channel = 'MAIN'
|
||||
if(req.params.channel){
|
||||
Channel = parseInt(req.params.channel)+config.pipeAddition
|
||||
await s.toggleSubstreamAndWaitForOutput(req.params.ke, monitorId);
|
||||
}
|
||||
var mp4frag = s.group[req.params.ke].activeMonitors[req.params.id].mp4frag[Channel];
|
||||
var errorMessage = 'MP4 Stream is not enabled'
|
||||
|
@ -159,7 +158,7 @@ module.exports = function(s,config,lang,app){
|
|||
s.closeJsonResponse(res,{ok: false, msg: lang['Not Authorized']});
|
||||
return;
|
||||
}
|
||||
s.checkChildProxy(req.params,async function(){
|
||||
s.checkChildProxy(req.params,function(){
|
||||
if(s.group[req.params.ke]&&s.group[req.params.ke].activeMonitors&&s.group[req.params.ke].activeMonitors[req.params.id]){
|
||||
if(user.permissions.watch_stream==="0"||user.details.sub&&user.details.allmonitors!=='1'&&user.details.monitors.indexOf(req.params.id)===-1){
|
||||
res.end(user.lang['Not Permitted'])
|
||||
|
@ -171,7 +170,6 @@ module.exports = function(s,config,lang,app){
|
|||
if(!req.params.channel){
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitter
|
||||
}else{
|
||||
await s.toggleSubstreamAndWaitForOutput(req.params.ke, monitorId);
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitterChannel[chosenChannel]
|
||||
}
|
||||
res.writeHead(200, {
|
||||
|
@ -230,7 +228,7 @@ module.exports = function(s,config,lang,app){
|
|||
s.closeJsonResponse(res,{ok: false, msg: lang['Not Authorized']});
|
||||
return;
|
||||
}
|
||||
s.checkChildProxy(req.params,async function(){
|
||||
s.checkChildProxy(req.params,function(){
|
||||
noCache(res)
|
||||
if(user.permissions.watch_stream==="0"||user.details.sub&&user.details.allmonitors!=='1'&&user.details.monitors.indexOf(req.params.id)===-1){
|
||||
res.end(user.lang['Not Permitted'])
|
||||
|
@ -243,19 +241,6 @@ module.exports = function(s,config,lang,app){
|
|||
req.dir+=req.params.file;
|
||||
}
|
||||
res.on('finish',function(){res.end();});
|
||||
if (req.params.file.endsWith('.m3u8')) {
|
||||
await s.toggleSubstreamAndWaitForOutput(req.params.ke, monitorId);
|
||||
const monitorTimeout = s.getStreamWaitTimeout(req.params.ke, monitorId);
|
||||
var ip = s.getClientIp(req)
|
||||
s.camera('watch_on',{
|
||||
id : req.params.id,
|
||||
ke: req.params.ke,
|
||||
monitorTimeout: monitorTimeout
|
||||
},{
|
||||
id: req.params.auth + ip + req.headers['user-agent'],
|
||||
url: req.originalUrl
|
||||
})
|
||||
}
|
||||
if (fs.existsSync(req.dir)){
|
||||
fs.createReadStream(req.dir).pipe(res);
|
||||
}else{
|
||||
|
@ -325,21 +310,19 @@ module.exports = function(s,config,lang,app){
|
|||
*/
|
||||
app.get([config.webPaths.apiPrefix+':auth/flv/:ke/:id/s.flv',config.webPaths.apiPrefix+':auth/flv/:ke/:id/:channel/s.flv'], function(req,res) {
|
||||
s.auth(req.params,function(user){
|
||||
const monitorId = req.params.id
|
||||
if(cantLiveStreamPermission(user,monitorId,'watch_stream')){
|
||||
s.closeJsonResponse(res,{ok: false, msg: lang['Not Authorized']});
|
||||
return;
|
||||
}
|
||||
s.checkChildProxy(req.params, async function () {
|
||||
s.checkChildProxy(req.params,function(){
|
||||
noCache(res)
|
||||
var Emitter,chunkChannel
|
||||
if(!req.params.channel){
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitter
|
||||
chunkChannel = 'MAIN'
|
||||
}else{
|
||||
await s.toggleSubstreamAndWaitForOutput(req.params.ke, monitorId);
|
||||
chunkChannel = parseInt(req.params.channel) + config.pipeAddition;
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitterChannel[chunkChannel];
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitterChannel[parseInt(req.params.channel)+config.pipeAddition]
|
||||
chunkChannel = parseInt(req.params.channel)+config.pipeAddition
|
||||
}
|
||||
if(s.group[req.params.ke].activeMonitors[req.params.id].firstStreamChunk[chunkChannel]){
|
||||
//variable name of contentWriter
|
||||
|
@ -387,19 +370,17 @@ module.exports = function(s,config,lang,app){
|
|||
config.webPaths.apiPrefix+':auth/h264/:ke/:id'
|
||||
], function (req, res) {
|
||||
s.auth(req.params,function(user){
|
||||
const monitorId = req.params.id;
|
||||
if(cantLiveStreamPermission(user,monitorId,'watch_stream')){
|
||||
s.closeJsonResponse(res,{ok: false, msg: lang['Not Authorized']});
|
||||
return;
|
||||
}
|
||||
s.checkChildProxy(req.params, async function(){
|
||||
s.checkChildProxy(req.params,function(){
|
||||
noCache(res)
|
||||
if(!req.query.feed){req.query.feed='1'}
|
||||
var Emitter
|
||||
if(!req.params.feed){
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].streamIn[req.query.feed]
|
||||
}else{
|
||||
await s.toggleSubstreamAndWaitForOutput(req.params.ke, monitorId);
|
||||
Emitter = s.group[req.params.ke].activeMonitors[req.params.id].emitterChannel[parseInt(req.params.feed)+config.pipeAddition]
|
||||
}
|
||||
var contentWriter
|
||||
|
|
|
@ -223,7 +223,7 @@ function toggleSubStream(monitorId,callback){
|
|||
}
|
||||
if(monitor.subStreamToggleLock)return false;
|
||||
monitor.subStreamToggleLock = true
|
||||
$.getJSON(getApiPrefix() + '/toggleSubstream/'+$user.ke+'/'+monitorId,function(d){
|
||||
$.getJSON(getApiPrefix() + '/toggleSubstream/'+$user.ke+'/'+monitorId + (monitor.subStreamActive ? '?action=stop' : ''),function(d){
|
||||
monitor.subStreamToggleLock = false
|
||||
debugLog(d)
|
||||
if(callback)callback()
|
||||
|
|
Loading…
Reference in New Issue