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...']}`
|
||||
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
|
||||
// // // // //
|
||||
/**
|
||||
|
@ -453,6 +482,8 @@ module.exports = function(s,config,lang,app,io){
|
|||
], function (req,res){
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
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'
|
||||
if(
|
||||
user.permissions.watch_videos==="0" ||
|
||||
|
@ -472,28 +503,14 @@ module.exports = function(s,config,lang,app,io){
|
|||
})
|
||||
return
|
||||
}
|
||||
const framesPerSecond = s.getPostData(req, 'fps')
|
||||
const framesPosted = s.getPostData(req, 'frames', true) || []
|
||||
const frames = []
|
||||
var n = 0
|
||||
framesPosted.forEach((frame) => {
|
||||
var firstParam = [['ke','=',req.params.ke],['mid','=',req.params.id],['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){
|
||||
s.closeJsonResponse(res,{
|
||||
ok: false
|
||||
})
|
||||
return
|
||||
}
|
||||
const buildResponse = await createVideoFromTimelapse(r.reverse(),s.getPostData(req, 'fps'))
|
||||
initiateTimelapseVideoBuild({
|
||||
groupKey,
|
||||
monitorId,
|
||||
framesPosted,
|
||||
framesPerSecond,
|
||||
}).then((buildResponse) => {
|
||||
s.closeJsonResponse(res,buildResponse)
|
||||
})
|
||||
},res,req);
|
||||
|
@ -597,6 +614,25 @@ module.exports = function(s,config,lang,app,io){
|
|||
})
|
||||
},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 dateNow = new Date()
|
||||
var hoursNow = dateNow.getHours()
|
||||
|
|
|
@ -211,24 +211,19 @@ $(document).ready(function(e){
|
|||
var startDate = dateRange.startDate
|
||||
var endDate = dateRange.endDate
|
||||
var selectedMonitor = monitorsList.val()
|
||||
var parsedFrames = JSON.stringify(currentPlaylistArray.map(function(frame){
|
||||
window.askedForTimelapseVideoBuild = true
|
||||
var parsedFrames = currentPlaylistArray.map(function(frame){
|
||||
return {
|
||||
mid: frame.mid,
|
||||
ke: frame.ke,
|
||||
filename: frame.filename,
|
||||
}
|
||||
}));
|
||||
$.post(apiBaseUrl + '/timelapseBuildVideo/' + $user.ke + '/' + selectedMonitor,{
|
||||
fps: fps,
|
||||
});
|
||||
mainSocket.f({
|
||||
f: 'timelapseVideoBuild',
|
||||
mid: selectedMonitor,
|
||||
frames: parsedFrames,
|
||||
},function(response){
|
||||
setDownloadButtonLabel(response.msg, '')
|
||||
new PNotify({
|
||||
title: lang['Timelapse Frames Video'],
|
||||
text: response.msg,
|
||||
type: response.fileExists ? 'success' : 'info'
|
||||
})
|
||||
if(response.fileExists)downloadTimelapseVideo(response);
|
||||
fps: fps,
|
||||
})
|
||||
})
|
||||
function isElementVisible (el) {
|
||||
|
@ -300,6 +295,18 @@ $(document).ready(function(e){
|
|||
}
|
||||
onWebSocketEvent(function(data){
|
||||
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':
|
||||
var saveBuiltVideo = dashboardOptions().switches.timelapseSaveBuiltVideo
|
||||
let statusText = `${lang['Done!']}`
|
||||
|
|
Loading…
Reference in New Issue