fix caching for snapshot icon

install-with-shinobicctv-user-instead-of-root
Moe 2020-08-15 22:06:22 -07:00
parent 9b00ec8d93
commit b14ef3cda6
2 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,9 @@
const fs = require('fs')
const spawn = require('child_process').spawn
const isWindows = process.platform === "win32";
var writeToStderr = function(text){
// fs.appendFileSync(rawMonitorConfig.sdir + 'errors.log',text + '\n','utf8')
process.stderr.write(Buffer.from(`${text}`, 'utf8' ))
}
if(!process.argv[2] || !process.argv[3]){
return writeToStderr('Missing FFMPEG Command String or no command operator')
@ -16,7 +18,11 @@ const exitAction = function(){
if(isWindows){
spawn("taskkill", ["/pid", snapProcess.pid, '/f', '/t'])
}else{
process.kill(-snapProcess.pid)
try{
process.kill(-snapProcess.pid)
}catch(err){
}
}
}
process.on('SIGTERM', exitAction);
@ -31,7 +37,6 @@ const temporaryImageFile = jsonData.temporaryImageFile
const iconImageFile = jsonData.iconImageFile
const useIcon = jsonData.useIcon
const rawMonitorConfig = jsonData.rawMonitorConfig
// var writeToStderr = function(text){
// process.stderr.write(Buffer.from(text))
// }
@ -44,7 +49,7 @@ snapProcess.stdout.on('data',(data)=>{
writeToStderr(data.toString())
})
snapProcess.on('close',function(data){
if(useIcon === true){
if(useIcon){
var fileCopy = fs.createReadStream(temporaryImageFile).pipe(fs.createWriteStream(iconImageFile))
fileCopy.on('close',function(){
process.exit();

View File

@ -109,7 +109,7 @@ module.exports = function(s,config,lang){
}
s.getRawSnapshotFromMonitor = function(monitor,options){
return new Promise((resolve,reject) => {
var options = {flags: ''}
options = options instanceof Object ? options : {flags: ''}
s.checkDetails(monitor)
var inputOptions = []
var outputOptions = []
@ -161,7 +161,7 @@ module.exports = function(s,config,lang){
]
var snapProcess = spawn('node',cameraCommandParams,{detached: true})
snapProcess.stderr.on('data',function(data){
console.log(data.toString())
s.debugLog(data.toString())
})
snapProcess.on('close',function(data){
clearTimeout(snapProcessTimeout)
@ -522,14 +522,14 @@ module.exports = function(s,config,lang){
return options
}
s.cameraSendSnapshot = async (e,options) => {
if(!options)options = {}
options = Object.assign({
flags: '-s 200x200'
},options || {})
s.checkDetails(e)
if(config.doSnapshot === true){
if(s.group[e.ke] && s.group[e.ke].rawMonitorConfigurations && s.group[e.ke].rawMonitorConfigurations[e.mid] && s.group[e.ke].rawMonitorConfigurations[e.mid].mode !== 'stop'){
var pathDir = s.dir.streams+e.ke+'/'+e.mid+'/'
const {screenShot, isStaticFile} = await s.getRawSnapshotFromMonitor(s.group[e.ke].rawMonitorConfigurations[e.mid],Object.assign({
flags: '-s 200x200'
},options))
const {screenShot, isStaticFile} = await s.getRawSnapshotFromMonitor(s.group[e.ke].rawMonitorConfigurations[e.mid],options)
if(screenShot && (screenShot[screenShot.length-2] === 0xFF && screenShot[screenShot.length-1] === 0xD9)){
s.tx({
f: 'monitor_snapshot',
@ -553,13 +553,13 @@ module.exports = function(s,config,lang){
const getDefaultImage = async () => {
return await fs.promises.readFile(config.defaultMjpeg)
}
if(!options)options = {}
options = Object.assign({
flags: '-s 200x200'
},options || {})
if(config.doSnapshot === true){
if(s.group[e.ke] && s.group[e.ke].rawMonitorConfigurations && s.group[e.ke].rawMonitorConfigurations[e.mid] && s.group[e.ke].rawMonitorConfigurations[e.mid].mode !== 'stop'){
var pathDir = s.dir.streams+e.ke+'/'+e.mid+'/'
const {screenShot, isStaticFile} = await s.getRawSnapshotFromMonitor(s.group[e.ke].rawMonitorConfigurations[e.mid],Object.assign({
flags: '-s 200x200'
},options))
const {screenShot, isStaticFile} = await s.getRawSnapshotFromMonitor(s.group[e.ke].rawMonitorConfigurations[e.mid],options)
if(screenShot && (screenShot[screenShot.length-2] === 0xFF && screenShot[screenShot.length-1] === 0xD9)){
return screenShot
}else{