cache side panel icon for faster loading and lower load on client open
parent
2ad0dbcc4d
commit
3a81da567c
|
@ -105,6 +105,7 @@ module.exports = function(s,config,lang){
|
||||||
callback = options
|
callback = options
|
||||||
var options = {flags: ''}
|
var options = {flags: ''}
|
||||||
}
|
}
|
||||||
|
s.checkDetails(monitor)
|
||||||
var inputOptions = []
|
var inputOptions = []
|
||||||
var outputOptions = []
|
var outputOptions = []
|
||||||
var streamDir = s.dir.streams + monitor.ke + '/' + monitor.mid + '/'
|
var streamDir = s.dir.streams + monitor.ke + '/' + monitor.mid + '/'
|
||||||
|
@ -112,11 +113,24 @@ module.exports = function(s,config,lang){
|
||||||
var secondsInward = options.secondsInward || '0'
|
var secondsInward = options.secondsInward || '0'
|
||||||
if(secondsInward.length === 1)secondsInward = '0' + secondsInward
|
if(secondsInward.length === 1)secondsInward = '0' + secondsInward
|
||||||
if(options.flags)outputOptions.push(options.flags)
|
if(options.flags)outputOptions.push(options.flags)
|
||||||
var runExtraction = function(){
|
const checkExists = function(streamDir,callback){
|
||||||
|
s.fileStats(streamDir,function(err){
|
||||||
|
var response = false
|
||||||
|
if(err){
|
||||||
|
// s.debugLog(err)
|
||||||
|
}else{
|
||||||
|
response = true
|
||||||
|
}
|
||||||
|
callback(response)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const noIconChecks = function(){
|
||||||
|
const runExtraction = function(){
|
||||||
try{
|
try{
|
||||||
var snapBuffer = []
|
var snapBuffer = []
|
||||||
var temporaryImageFile = streamDir + s.gid(5) + '.jpg'
|
var temporaryImageFile = streamDir + s.gid(5) + '.jpg'
|
||||||
var ffmpegCmd = `-loglevel quiet -re -probesize 1000000 -analyzeduration 1000000 ${inputOptions.join(' ')} -i "${url}" ${outputOptions.join(' ')} -vframes 1 ${temporaryImageFile}`
|
var iconImageFile = streamDir + 'icon.jpg'
|
||||||
|
var ffmpegCmd = `-loglevel quiet -re -probesize 1000000 -analyzeduration 1000000 ${inputOptions.join(' ')} -i "${url}" ${outputOptions.join(' ')} -vframes 1 "${temporaryImageFile}"`
|
||||||
var snapProcess = spawn(config.ffmpegDir,s.splitForFFPMEG(ffmpegCmd),{detached: true})
|
var snapProcess = spawn(config.ffmpegDir,s.splitForFFPMEG(ffmpegCmd),{detached: true})
|
||||||
snapProcess.stderr.on('data',function(data){
|
snapProcess.stderr.on('data',function(data){
|
||||||
console.log(data.toString())
|
console.log(data.toString())
|
||||||
|
@ -125,9 +139,14 @@ module.exports = function(s,config,lang){
|
||||||
clearTimeout(snapProcessTimeout)
|
clearTimeout(snapProcessTimeout)
|
||||||
fs.readFile(temporaryImageFile,function(err,buffer){
|
fs.readFile(temporaryImageFile,function(err,buffer){
|
||||||
if(buffer){
|
if(buffer){
|
||||||
|
if(options.useIcon === true){
|
||||||
|
fs.writeFile(iconImageFile,buffer,function(){
|
||||||
callback(buffer,false)
|
callback(buffer,false)
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
callback(buffer,false)
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
s.debugLog(err,ffmpegCmd)
|
|
||||||
fs.readFile(config.defaultMjpeg,function(err,buffer){
|
fs.readFile(config.defaultMjpeg,function(err,buffer){
|
||||||
callback(buffer,false)
|
callback(buffer,false)
|
||||||
})
|
})
|
||||||
|
@ -149,17 +168,6 @@ module.exports = function(s,config,lang){
|
||||||
if(url){
|
if(url){
|
||||||
runExtraction()
|
runExtraction()
|
||||||
}else{
|
}else{
|
||||||
var checkExists = function(streamDir,callback){
|
|
||||||
s.fileStats(streamDir,function(err){
|
|
||||||
var response = false
|
|
||||||
if(err){
|
|
||||||
// s.debugLog(err)
|
|
||||||
}else{
|
|
||||||
response = true
|
|
||||||
}
|
|
||||||
callback(response)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
checkExists(streamDir + 's.jpg',function(success){
|
checkExists(streamDir + 's.jpg',function(success){
|
||||||
if(success === false){
|
if(success === false){
|
||||||
checkExists(streamDir + 'detectorStream.m3u8',function(success){
|
checkExists(streamDir + 'detectorStream.m3u8',function(success){
|
||||||
|
@ -171,9 +179,9 @@ module.exports = function(s,config,lang){
|
||||||
switch(monitor.protocol){
|
switch(monitor.protocol){
|
||||||
case'rtsp':
|
case'rtsp':
|
||||||
if(
|
if(
|
||||||
monitor.details.rtsp_transport
|
details.rtsp_transport
|
||||||
&& monitor.details.rtsp_transport !== ''
|
&& details.rtsp_transport !== ''
|
||||||
&& monitor.details.rtsp_transport !== 'no'
|
&& details.rtsp_transport !== 'no'
|
||||||
){
|
){
|
||||||
inputOptions.push('-rtsp_transport ' + monitor.details.rtsp_transport)
|
inputOptions.push('-rtsp_transport ' + monitor.details.rtsp_transport)
|
||||||
}
|
}
|
||||||
|
@ -202,6 +210,20 @@ module.exports = function(s,config,lang){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(options.useIcon === true){
|
||||||
|
checkExists(streamDir + 's.jpg',function(success){
|
||||||
|
if(success === false){
|
||||||
|
noIconChecks()
|
||||||
|
}else{
|
||||||
|
s.readFile(streamDir + 'icon.jpg',function(err,snapBuffer){
|
||||||
|
callback(snapBuffer,true)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
noIconChecks()
|
||||||
|
}
|
||||||
|
}
|
||||||
s.mergeDetectorBufferChunks = function(monitor,callback){
|
s.mergeDetectorBufferChunks = function(monitor,callback){
|
||||||
var pathDir = s.dir.streams+monitor.ke+'/'+monitor.id+'/'
|
var pathDir = s.dir.streams+monitor.ke+'/'+monitor.id+'/'
|
||||||
var mergedFile = s.formattedTime()+'.mp4'
|
var mergedFile = s.formattedTime()+'.mp4'
|
||||||
|
@ -632,16 +654,15 @@ module.exports = function(s,config,lang){
|
||||||
}
|
}
|
||||||
return options
|
return options
|
||||||
}
|
}
|
||||||
s.cameraSendSnapshot = function(e){
|
s.cameraSendSnapshot = function(e,options){
|
||||||
|
if(!options)options = {}
|
||||||
s.checkDetails(e)
|
s.checkDetails(e)
|
||||||
if(config.doSnapshot === true){
|
if(config.doSnapshot === true){
|
||||||
if(e.mon.mode !== 'stop'){
|
if(e.mon.mode !== 'stop'){
|
||||||
var pathDir = s.dir.streams+e.ke+'/'+e.mid+'/'
|
var pathDir = s.dir.streams+e.ke+'/'+e.mid+'/'
|
||||||
var url = s.buildMonitorUrl(e.mon)
|
s.getRawSnapshotFromMonitor(e.mon,Object.assign({
|
||||||
s.getRawSnapshotFromMonitor(e.mon,{
|
flags: '-s 200x200'
|
||||||
flags: '-s 200x200',
|
},options),function(data,isStaticFile){
|
||||||
url: url
|
|
||||||
},function(data,isStaticFile){
|
|
||||||
if(data && (data[data.length-2] === 0xFF && data[data.length-1] === 0xD9)){
|
if(data && (data[data.length-2] === 0xFF && data[data.length-1] === 0xD9)){
|
||||||
s.tx({
|
s.tx({
|
||||||
f: 'monitor_snapshot',
|
f: 'monitor_snapshot',
|
||||||
|
@ -1285,7 +1306,7 @@ module.exports = function(s,config,lang){
|
||||||
s.resetStreamCheck(e)
|
s.resetStreamCheck(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
s.cameraSendSnapshot({mid:e.id,ke:e.ke,mon:e})
|
s.cameraSendSnapshot({mid:e.id,ke:e.ke,mon:e},{useIcon: true})
|
||||||
//check host to see if has password and user in it
|
//check host to see if has password and user in it
|
||||||
clearTimeout(s.group[e.ke].activeMonitors[e.id].recordingChecker)
|
clearTimeout(s.group[e.ke].activeMonitors[e.id].recordingChecker)
|
||||||
if(s.group[e.ke].activeMonitors[e.id].isStarted === true){
|
if(s.group[e.ke].activeMonitors[e.id].isStarted === true){
|
||||||
|
@ -1628,7 +1649,7 @@ module.exports = function(s,config,lang){
|
||||||
s.group[e.ke].activeMonitors[e.id].isStarted = false
|
s.group[e.ke].activeMonitors[e.id].isStarted = false
|
||||||
s.group[e.ke].activeMonitors[e.id].isRecording = false
|
s.group[e.ke].activeMonitors[e.id].isRecording = false
|
||||||
s.tx({f:'monitor_stopping',mid:e.id,ke:e.ke,time:s.formattedTime()},'GRP_'+e.ke);
|
s.tx({f:'monitor_stopping',mid:e.id,ke:e.ke,time:s.formattedTime()},'GRP_'+e.ke);
|
||||||
s.cameraSendSnapshot({mid:e.id,ke:e.ke,mon:e})
|
s.cameraSendSnapshot({mid:e.id,ke:e.ke,mon:e},{useIcon: true})
|
||||||
if(e.functionMode === 'stop'){
|
if(e.functionMode === 'stop'){
|
||||||
s.userLog(e,{type:lang['Monitor Stopped'],msg:lang.MonitorStoppedText});
|
s.userLog(e,{type:lang['Monitor Stopped'],msg:lang.MonitorStoppedText});
|
||||||
clearTimeout(s.group[e.ke].activeMonitors[e.id].delete)
|
clearTimeout(s.group[e.ke].activeMonitors[e.id].delete)
|
||||||
|
|
Loading…
Reference in New Issue