tweak auto-closing of Substreams
parent
e27c49f93f
commit
4af73b062d
|
|
@ -29,6 +29,7 @@ module.exports = function(s,config,lang){
|
|||
monitorConfigurationMigrator,
|
||||
attachStreamChannelHandlers,
|
||||
setActiveViewer,
|
||||
getActiveViewerCount,
|
||||
destroySubstreamProcess,
|
||||
attachMainProcessHandlers,
|
||||
} = require('./monitor/utils.js')(s,config,lang)
|
||||
|
|
@ -1513,15 +1514,17 @@ module.exports = function(s,config,lang){
|
|||
break;
|
||||
case'watch_off'://live streamers - leave
|
||||
if(cn.monitorsCurrentlyWatching){delete(cn.monitorsCurrentlyWatching[e.id])}
|
||||
let currentCount = setActiveViewer(e.ke,e.id,cn.id,false)
|
||||
setActiveViewer(e.ke,e.id,cn.id,false)
|
||||
s.debugLog('closeing')
|
||||
let currentCount = getActiveViewerCount(e.ke,e.id)
|
||||
s.debugLog(currentCount,currentCount === 0,!!s.group[e.ke].activeMonitors[e.id].subStreamProcess)
|
||||
if(currentCount === 0 && s.group[e.ke].activeMonitors[e.id].subStreamProcess){
|
||||
clearTimeout(s.group[e.ke].activeMonitors[e.id].noViewerCountDisableSubstream)
|
||||
s.group[e.ke].activeMonitors[e.id].noViewerCountDisableSubstream = setTimeout(function(){
|
||||
s.debugLog('closed')
|
||||
clearTimeout(s.group[e.ke].activeMonitors[e.id].noViewerCountDisableSubstream)
|
||||
if(currentCount === 0 && s.group[e.ke].activeMonitors[e.id].subStreamProcessActivated){
|
||||
s.group[e.ke].activeMonitors[e.id].noViewerCountDisableSubstream = setTimeout(async () => {
|
||||
s.group[e.ke].activeMonitors[e.id].allowDestroySubstream = true
|
||||
destroySubstreamProcess(s.group[e.ke].activeMonitors[e.id])
|
||||
},5000)
|
||||
await destroySubstreamProcess(s.group[e.ke].activeMonitors[e.id])
|
||||
s.debugLog('closed')
|
||||
},10000)
|
||||
}
|
||||
break;
|
||||
case'restart'://restart monitor
|
||||
|
|
|
|||
|
|
@ -232,6 +232,7 @@ module.exports = (s,config,lang) => {
|
|||
substreamConfig.input.type = !substreamConfig.input.fulladdress ? monitorConfig.type : substreamConfig.input.type || monitorConfig.details.rtsp_transport
|
||||
substreamConfig.input.fulladdress = substreamConfig.input.fulladdress || s.buildMonitorUrl(monitorConfig)
|
||||
substreamConfig.input.rtsp_transport = substreamConfig.input.rtsp_transport || monitorConfig.details.rtsp_transport
|
||||
activeMonitor.subStreamProcessActivated = true
|
||||
const {
|
||||
inputAndConnectionFields,
|
||||
outputFields,
|
||||
|
|
@ -275,8 +276,7 @@ module.exports = (s,config,lang) => {
|
|||
s.userLog({
|
||||
ke: e.ke,
|
||||
mid: e.mid,
|
||||
},
|
||||
{
|
||||
},{
|
||||
type: lang["Substream Process"],
|
||||
msg: data.toString()
|
||||
})
|
||||
|
|
@ -318,21 +318,25 @@ module.exports = (s,config,lang) => {
|
|||
hadSubStream: false,
|
||||
alreadyClosing: false
|
||||
}
|
||||
if(activeMonitor.subStreamProcessClosing){
|
||||
response.alreadyClosing = true
|
||||
}else if(activeMonitor.subStreamProcess){
|
||||
activeMonitor.subStreamProcessClosing = true
|
||||
activeMonitor.subStreamChannel = null;
|
||||
const closeResponse = await processKill(activeMonitor.subStreamProcess)
|
||||
response.hadSubStream = true
|
||||
response.closeResponse = closeResponse
|
||||
delete(activeMonitor.subStreamProcess)
|
||||
s.tx({
|
||||
f: 'substream_end',
|
||||
mid: activeMonitor.mid,
|
||||
ke: activeMonitor.ke
|
||||
},'GRP_'+activeMonitor.ke);
|
||||
activeMonitor.subStreamProcessClosing = false
|
||||
try{
|
||||
if(activeMonitor.subStreamProcessClosing){
|
||||
response.alreadyClosing = true
|
||||
}else if(activeMonitor.subStreamProcess){
|
||||
activeMonitor.subStreamProcessClosing = true
|
||||
activeMonitor.subStreamChannel = null;
|
||||
const closeResponse = await processKill(activeMonitor.subStreamProcess)
|
||||
response.hadSubStream = true
|
||||
response.closeResponse = closeResponse
|
||||
delete(activeMonitor.subStreamProcess)
|
||||
s.tx({
|
||||
f: 'substream_end',
|
||||
mid: activeMonitor.mid,
|
||||
ke: activeMonitor.ke
|
||||
},'GRP_'+activeMonitor.ke);
|
||||
activeMonitor.subStreamProcessClosing = false
|
||||
}
|
||||
}catch(err){
|
||||
s.debugLog('destroySubstreamProcess',err)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
|
@ -392,6 +396,11 @@ module.exports = (s,config,lang) => {
|
|||
},'MON_' + groupKey + monitorId)
|
||||
return numberOfViewers;
|
||||
}
|
||||
function getActiveViewerCount(groupKey,monitorId){
|
||||
const viewerList = s.group[groupKey].activeMonitors[monitorId].watch;
|
||||
const numberOfViewers = viewerList.length
|
||||
return numberOfViewers;
|
||||
}
|
||||
function setTimedActiveViewerForHttp(req){
|
||||
const groupKey = req.params.ke
|
||||
const connectionId = req.params.auth
|
||||
|
|
@ -472,6 +481,7 @@ module.exports = (s,config,lang) => {
|
|||
destroySubstreamProcess: destroySubstreamProcess,
|
||||
attachStreamChannelHandlers: attachStreamChannelHandlers,
|
||||
setActiveViewer: setActiveViewer,
|
||||
getActiveViewerCount: getActiveViewerCount,
|
||||
setTimedActiveViewerForHttp: setTimedActiveViewerForHttp,
|
||||
attachMainProcessHandlers: attachMainProcessHandlers,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue