From 77549aff562a339657baa754e966e11e510d94ee Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Mon, 29 May 2023 03:38:25 -0400 Subject: [PATCH] improve resiliency when passcode is incorrect --- plugins/qlab/main.js | 46 ++++++++++++++++++++++++++++++--------- plugins/qlab/template.ejs | 26 ++++++++++++++++------ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/plugins/qlab/main.js b/plugins/qlab/main.js index a2a23b3..dbee300 100644 --- a/plugins/qlab/main.js +++ b/plugins/qlab/main.js @@ -50,11 +50,30 @@ exports.ready = function ready(_device) { exports.data = function data(_device, oscData) { const device = _device; - // console.log(oscData); + console.log(oscData); const msgAddr = oscData.address.split('/'); msgAddr.shift(); + // try { + let json = []; + try { + json = JSON.parse(oscData.args[0]); + } catch (err) {} + + if (Object.keys(json).length > 0) { + if (json.status === 'denied') { + if (device.data.workspaces[json.workspace_id]) { + device.data.workspaces[json.workspace_id].permission = 'denied'; + } + return; + } + if (json.status === 'error') { + device.send('/workspaces'); + return; + } + } + if (oscData.address === '/reply/workspaces') { const json = JSON.parse(oscData.args[0]).data; @@ -67,15 +86,17 @@ exports.data = function data(_device, oscData) { cueLists: [], selected: [], }; + device.data.workspaces[json[i].uniqueID].permission = 'ok'; device.send(`/workspace/${json[i].uniqueID}/connect`, device.fields.passcode); } this.deviceInfoUpdate(device, 'status', 'ok'); } else if (/reply\/workspace\/.*\/connect/.test(oscData.address)) { - const json = JSON.parse(oscData.args[0]).data; - if (json === 'badpass') { - device.data.permission = 'denied'; + const json = JSON.parse(oscData.args[0]); + + if (json.data === 'badpass') { + device.data.workspaces[json.workspace_id].permission = 'badpass'; } else { - device.data.permission = 'ok'; + device.data.workspaces[json.workspace_id].permission = 'ok'; device.send(`/workspace/${msgAddr[2]}/cueLists`); device.send(`/workspace/${msgAddr[2]}/updates`, [{ type: 'i', value: 1 }]); } @@ -98,7 +119,7 @@ exports.data = function data(_device, oscData) { device.data.cueKeys[msgAddr[2]] = {}; cue = device.data.cueKeys[msgAddr[2]]; } - // console.log(keyValues.number); + // console.log(json.status); cue.uniqueID = keyValues.uniqueID; cue.number = keyValues.number; cue.listName = keyValues.listName; @@ -172,6 +193,9 @@ exports.data = function data(_device, oscData) { } else if (/reply\/workspace\/.*\/selectedCues/.test(oscData.address)) { const json = JSON.parse(oscData.args[0]); const workspace = device.data.workspaces[msgAddr[2]]; + if (!workspace) { + return; + } workspace.selected = []; for (let i = 0; i < json.data.length; i++) { workspace.selected.push(json.data[i].uniqueID); @@ -189,10 +213,12 @@ exports.data = function data(_device, oscData) { } } else if (/update\/workspace\/.*\/cueList\/.*\/playbackPosition/.test(oscData.address)) { const workspace = device.data.workspaces[msgAddr[2]]; - // const cue = workspace.cues[oscData.args[0]]; - workspace.playbackPosition = oscData.args[0]; - // device.draw(); - device.update('updatePlaybackAndSelected', { workspace: device.data.workspaces[msgAddr[2]] }); + if (workspace) { + // const cue = workspace.cues[oscData.args[0]]; + workspace.playbackPosition = oscData.args[0]; + // device.draw(); + device.update('updatePlaybackAndSelected', { workspace: device.data.workspaces[msgAddr[2]] }); + } } else if (/update\/workspace\/.*\/dashboard/.test(oscData.address)) { device.send(`/workspace/${msgAddr[2]}/selectedCues`); device.send(`/cue_id/active/preWaitElapsed`); diff --git a/plugins/qlab/template.ejs b/plugins/qlab/template.ejs index 710d4c7..47ba696 100644 --- a/plugins/qlab/template.ejs +++ b/plugins/qlab/template.ejs @@ -3,20 +3,32 @@

QLab <%= data.version || "" %>

+ + <% const workspaceKeys = Object.keys(data.workspaces); %> <% for(let i=0; i <% const workspace = data.workspaces[workspaceKeys[i]]; %> - <% for(let j=0; j - <% const cueList = workspace.cueLists[j]; %> + <% if(workspace.permission=="ok"){ %> + + <% for(let j=0; j + <% const cueList = workspace.cueLists[j]; %> + + <% if(cueList.type=="Cue List"){ %> + <%= templates.cuelist({cueList: cueList, allCues: data.cueKeys, rowTemplate: templates.cue, workspace: workspace}) %> + <% }else if(cueList.type=="Cart"){ %> + <%= templates.cart({cueList: cueList, allCues: data.cueKeys, tileTemplate: templates.tile, workspace: workspace}) %> + <% } %> - <% if(cueList.type=="Cue List"){ %> - <%= templates.cuelist({cueList: cueList, allCues: data.cueKeys, rowTemplate: templates.cue, workspace: workspace}) %> - <% }else if(cueList.type=="Cart"){ %> - <%= templates.cart({cueList: cueList, allCues: data.cueKeys, tileTemplate: templates.tile, workspace: workspace}) %> <% } %> + + <% }else{ %> +

<%= workspace.displayName %> — Incorrect Passcode or OSC Access Permissions

+ +

 

<% } %> -<% } %> \ No newline at end of file +<% } %> +