Skip to content

Commit

Permalink
Add better logging to the client.
Browse files Browse the repository at this point in the history
  • Loading branch information
sebinside committed Nov 27, 2022
1 parent 2447086 commit 99c2d0e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CSXS/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<ExtensionManifest ExtensionBundleId="de.sebinside.premiereremote" ExtensionBundleVersion="1.0.0" Version="7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ExtensionList>
<Extension Id="de.sebinside.premiereremote.panel" Version="1.0.0" />
<Extension Id="de.sebinside.premiereremote.panel" Version="2.0.0" />
</ExtensionList>
<ExecutionEnvironment>
<HostList>
Expand Down
6 changes: 2 additions & 4 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@
<link rel="stylesheet" href="main.css">
<script type="text/javascript" src="CSInterface.js"></script>
<script type="text/javascript" src="index.js"></script>
<!-- Paradigm fail, but needed for endpoint construction -->
<script type="text/javascript" src="../host/build/out/index.jsx"></script>

<!-- Change this port, if there are conflicts with other software -->
<script type="text/javascript">
const PREMIERE_REMOTE_VERSION = "2.0.0";
const SERVER_PORT = 8081;
const ENABLE_QE = true;
</script>



</head>

<body ondblclick="openHostWindow()">
<div id="statusContainer" class="red">Loading...</div>
<div id="lastCommandContainer">Last Command...</div>
Expand Down
70 changes: 42 additions & 28 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,35 @@
const csInterface = new CSInterface();
const loc = window.location.pathname;
const dir = decodeURI(loc.substring(1, loc.lastIndexOf('/')));
const express = require(dir + "/node_modules/express/index.js");

// Swagger documentation, based on: http://www.acuriousanimal.com/2018/10/20/express-swagger-doc.html
// Dependencies
const express = require(dir + "/node_modules/express/index.js");
const swaggerJsDoc = require(dir + "/node_modules/swagger-jsdoc/index.js");
const swaggerUi = require(dir + "/node_modules/swagger-ui-express/index.js");

const options = {
swaggerDefinition: {
info: {
title: 'AHK2PremiereCEP',
version: '1.0.0',
description: 'Autogenerated documentation for defined javascript functions.',
},
},
// List of files to be processed
apis: [dir + '/../host/build/out/index.jsx'],
};

const specs = swaggerJsDoc(options);

function init() {
console.log("Starting PremiereRemote initialization...");

// Setup server
console.log("Starting PremiereRemote server setup...");
const app = express();
const router = express.Router();
console.log("Finished PremiereRemote server setup.");

// Setup swagger endpoint
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
console.log("Starting Swagger setup...");
setupSwagger(app);
console.log("Finished Swagger setup.");

// Setup endpoints
console.log("Starting API endpoint setup...");
for (const functionDeclaration in host) {
const key = functionDeclaration;
const signature = host[key].toString().split("{")[0];
console.log(`Setting up endpoint: "${key}".`);

if (signature === host[key].toString()) {
console.log("Unable to read function definition of '" + key + "'.");
console.error("Unable to read function definition of '" + key + "'.");
} else {

const parameters = extractParameters(signature);
Expand All @@ -46,7 +39,7 @@ function init() {

// Special code for faster debugging
if (key === "kill") {
res.json({message: 'ok.'});
res.json({ message: 'ok.' });
csInterface.closeExtension();
}

Expand All @@ -65,33 +58,54 @@ function init() {
if (req.query.hasOwnProperty(propName)) {
params.push(req.query[propName]);
} else {
console.log("Param not found: '" + propName + "'");
console.error("Param not found: '" + propName + "'");
}
}

// Check query parameter count
if (parameters.length === params.length && params.length === propertyCount) {
// Execute function with given parameters (also: result)
executeCommand(key, params, res);
} else {
res.json({message: 'error. wrong parameters.'});
res.json({ message: 'error. wrong parameters.' });
}

});
}
}
console.log("Finished API endpoint setup.")

// Start server
console.log(`Starting the PremiereRemote server now on port ${SERVER_PORT}.`);
app.use('/', router);
app.listen(SERVER_PORT);

// Enable QE
if(ENABLE_QE) {
if (ENABLE_QE) {
console.log("Enabling the undocumented QE API. Be careful!")
csInterface.evalScript("framework.enableQualityEngineering();")
}

document.getElementById("statusContainer").innerHTML = "Ready!";
document.getElementById("statusContainer").className = "green";

console.log("Finished PremiereRemote initialization.")
}

function setupSwagger(swaggerApp) {
const options = {
swaggerDefinition: {
info: {
title: 'PremiereRemote',
version: PREMIERE_REMOTE_VERSION,
description: 'Customizable remote access to Adobe Premiere Pro CEP.',
},
},
// List of files to be processed
apis: [dir + '/../host/build/index.jsx'],
};

const specs = swaggerJsDoc(options);
swaggerApp.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
}

const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
Expand All @@ -106,7 +120,7 @@ function extractParameters(signature) {
}

function executeCommand(command, params, res) {
console.log("Execute: " + command);
console.log(`Retrieved endpoint call: "${command}"`);
document.getElementById("lastCommandContainer").innerHTML = command;

command += "(";
Expand All @@ -119,13 +133,13 @@ function executeCommand(command, params, res) {
}
command += ");";

console.log(command);
csInterface.evalScript("host." + command, function(functionResult) {
res.json({message: 'ok.', result: functionResult});
console.log(`Execute command: "${command}"`);
csInterface.evalScript("host." + command, function (functionResult) {
res.json({ message: 'ok.', result: functionResult });
});
}

function openHostWindow() {
console.log('start "' + dir + '"');
console.log(`Opening explorer window for host folder inside "${dir}".`);
require('child_process').exec('start "" "' + dir + '/../host"');
}

0 comments on commit 99c2d0e

Please sign in to comment.