add timelapseVideoBuild to Websocket API
parent
62d7b8d7f0
commit
83750bb20e
|
@ -400,6 +400,35 @@ module.exports = function(s,config,lang,app,io){
|
||||||
response.msg = `${lang.Building}... ${lang['Please Wait...']}`
|
response.msg = `${lang.Building}... ${lang['Please Wait...']}`
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
function initiateTimelapseVideoBuild({
|
||||||
|
groupKey,
|
||||||
|
monitorId,
|
||||||
|
framesPerSecond,
|
||||||
|
framesPosted,
|
||||||
|
}){
|
||||||
|
return new Promise((resolve,reject) => {
|
||||||
|
let response = {ok: false}
|
||||||
|
const frames = []
|
||||||
|
var n = 0
|
||||||
|
framesPosted.forEach((frame) => {
|
||||||
|
var firstParam = [['ke','=',groupKey],['mid','=',monitorId],['filename','=',frame.filename]]
|
||||||
|
if(n !== 0)firstParam[0] = (['or']).concat(firstParam[0])
|
||||||
|
frames.push(...firstParam)
|
||||||
|
++n
|
||||||
|
})
|
||||||
|
s.knexQuery({
|
||||||
|
action: "select",
|
||||||
|
columns: "*",
|
||||||
|
table: "Timelapse Frames",
|
||||||
|
where: frames
|
||||||
|
},async (err,r) => {
|
||||||
|
if(r.length > 0){
|
||||||
|
response = await createVideoFromTimelapse(r.reverse(),framesPerSecond)
|
||||||
|
}
|
||||||
|
resolve(response)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
// Web Paths
|
// Web Paths
|
||||||
// // // // //
|
// // // // //
|
||||||
/**
|
/**
|
||||||
|
@ -453,6 +482,8 @@ module.exports = function(s,config,lang,app,io){
|
||||||
], function (req,res){
|
], function (req,res){
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
s.auth(req.params,function(user){
|
s.auth(req.params,function(user){
|
||||||
|
const groupKey = req.params.ke
|
||||||
|
const monitorId = req.params.id
|
||||||
var hasRestrictions = user.details.sub && user.details.allmonitors !== '1'
|
var hasRestrictions = user.details.sub && user.details.allmonitors !== '1'
|
||||||
if(
|
if(
|
||||||
user.permissions.watch_videos==="0" ||
|
user.permissions.watch_videos==="0" ||
|
||||||
|
@ -472,28 +503,14 @@ module.exports = function(s,config,lang,app,io){
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const framesPerSecond = s.getPostData(req, 'fps')
|
||||||
const framesPosted = s.getPostData(req, 'frames', true) || []
|
const framesPosted = s.getPostData(req, 'frames', true) || []
|
||||||
const frames = []
|
initiateTimelapseVideoBuild({
|
||||||
var n = 0
|
groupKey,
|
||||||
framesPosted.forEach((frame) => {
|
monitorId,
|
||||||
var firstParam = [['ke','=',req.params.ke],['mid','=',req.params.id],['filename','=',frame.filename]]
|
framesPosted,
|
||||||
if(n !== 0)firstParam[0] = (['or']).concat(firstParam[0])
|
framesPerSecond,
|
||||||
frames.push(...firstParam)
|
}).then((buildResponse) => {
|
||||||
++n
|
|
||||||
})
|
|
||||||
s.knexQuery({
|
|
||||||
action: "select",
|
|
||||||
columns: "*",
|
|
||||||
table: "Timelapse Frames",
|
|
||||||
where: frames
|
|
||||||
},async (err,r) => {
|
|
||||||
if(r.length === 0){
|
|
||||||
s.closeJsonResponse(res,{
|
|
||||||
ok: false
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const buildResponse = await createVideoFromTimelapse(r.reverse(),s.getPostData(req, 'fps'))
|
|
||||||
s.closeJsonResponse(res,buildResponse)
|
s.closeJsonResponse(res,buildResponse)
|
||||||
})
|
})
|
||||||
},res,req);
|
},res,req);
|
||||||
|
@ -597,6 +614,25 @@ module.exports = function(s,config,lang,app,io){
|
||||||
})
|
})
|
||||||
},res,req);
|
},res,req);
|
||||||
});
|
});
|
||||||
|
s.onOtherWebSocketMessages((d,connection) => {
|
||||||
|
switch(d.f){
|
||||||
|
case'timelapseVideoBuild':
|
||||||
|
initiateTimelapseVideoBuild({
|
||||||
|
groupKey: d.ke,
|
||||||
|
monitorId: d.mid,
|
||||||
|
framesPosted: d.frames,
|
||||||
|
framesPerSecond: d.fps,
|
||||||
|
}).then((buildResponse) => {
|
||||||
|
s.tx({
|
||||||
|
f: 'timelapse_build_requested',
|
||||||
|
ke: d.ke,
|
||||||
|
mid: d.mid,
|
||||||
|
buildResponse: buildResponse,
|
||||||
|
},'GRP_'+d.ke);
|
||||||
|
})
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
var buildTimelapseVideos = function(){
|
var buildTimelapseVideos = function(){
|
||||||
var dateNow = new Date()
|
var dateNow = new Date()
|
||||||
var hoursNow = dateNow.getHours()
|
var hoursNow = dateNow.getHours()
|
||||||
|
|
|
@ -211,24 +211,19 @@ $(document).ready(function(e){
|
||||||
var startDate = dateRange.startDate
|
var startDate = dateRange.startDate
|
||||||
var endDate = dateRange.endDate
|
var endDate = dateRange.endDate
|
||||||
var selectedMonitor = monitorsList.val()
|
var selectedMonitor = monitorsList.val()
|
||||||
var parsedFrames = JSON.stringify(currentPlaylistArray.map(function(frame){
|
window.askedForTimelapseVideoBuild = true
|
||||||
|
var parsedFrames = currentPlaylistArray.map(function(frame){
|
||||||
return {
|
return {
|
||||||
mid: frame.mid,
|
mid: frame.mid,
|
||||||
ke: frame.ke,
|
ke: frame.ke,
|
||||||
filename: frame.filename,
|
filename: frame.filename,
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
$.post(apiBaseUrl + '/timelapseBuildVideo/' + $user.ke + '/' + selectedMonitor,{
|
mainSocket.f({
|
||||||
fps: fps,
|
f: 'timelapseVideoBuild',
|
||||||
|
mid: selectedMonitor,
|
||||||
frames: parsedFrames,
|
frames: parsedFrames,
|
||||||
},function(response){
|
fps: fps,
|
||||||
setDownloadButtonLabel(response.msg, '')
|
|
||||||
new PNotify({
|
|
||||||
title: lang['Timelapse Frames Video'],
|
|
||||||
text: response.msg,
|
|
||||||
type: response.fileExists ? 'success' : 'info'
|
|
||||||
})
|
|
||||||
if(response.fileExists)downloadTimelapseVideo(response);
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
function isElementVisible (el) {
|
function isElementVisible (el) {
|
||||||
|
@ -300,6 +295,18 @@ $(document).ready(function(e){
|
||||||
}
|
}
|
||||||
onWebSocketEvent(function(data){
|
onWebSocketEvent(function(data){
|
||||||
switch(data.f){
|
switch(data.f){
|
||||||
|
case'timelapse_build_requested':
|
||||||
|
console.log(data)
|
||||||
|
var response = data.buildResponse;
|
||||||
|
setDownloadButtonLabel(response.msg, '')
|
||||||
|
new PNotify({
|
||||||
|
title: lang['Timelapse Frames Video'],
|
||||||
|
text: response.msg,
|
||||||
|
type: response.fileExists ? 'success' : 'info'
|
||||||
|
});
|
||||||
|
if(response.fileExists && window.askedForTimelapseVideoBuild)downloadTimelapseVideo(response);
|
||||||
|
window.askedForTimelapseVideoBuild = false
|
||||||
|
break;
|
||||||
case'fileBin_item_added':
|
case'fileBin_item_added':
|
||||||
var saveBuiltVideo = dashboardOptions().switches.timelapseSaveBuiltVideo
|
var saveBuiltVideo = dashboardOptions().switches.timelapseSaveBuiltVideo
|
||||||
let statusText = `${lang['Done!']}`
|
let statusText = `${lang['Done!']}`
|
||||||
|
|
Loading…
Reference in New Issue