-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add scripts for being able to run macros externally
means you can run the macros externally from node without chaning them allows you to use your own editor, and git, for macro development note you need to do 'npm install jsxapi' to be able to run it, if you dont have jsaxpi in your global environment
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Let's you run macros easily from node (your laptop) instead of macro editor (device) | ||
* without changing any code in the macro. | ||
*/ | ||
const adapter = require('./universal-adapter'); | ||
|
||
async function go(host, username, password, macro) { | ||
const videoDevice = { host, username, password }; | ||
await adapter(videoDevice); | ||
require(macro); // macro starts with xapi available | ||
} | ||
|
||
if (process.argv.length < 6) { | ||
console.log('Run a Webex Device macro remotely from a node.js environment'); | ||
console.log('Usage: ./run-macro <host> <username> <password> <macrofile>'); | ||
console.log('\neg: ./run 10.47.31.28 admin mypwd ./mymacro.js') | ||
console.log('NOTE: macro file path is relative to the run-macro scripts folder, and must typically start with ./'); | ||
process.exit(1); | ||
} | ||
|
||
const [exec, script, host, username, password, macro] = process.argv; | ||
go(host, username, password, macro); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Adapter that makes it possible to run a pure macro from an external node context instead. | ||
* Useful to develop, test and commit macros on own laptop instead of in macro editor, | ||
* then just copy/paste/export/commit & push the macro file when done. | ||
* | ||
* Macros on video device can just import the xapi object directly, but when external you need | ||
* to provide login details. Some magic here makes lets you connect to the video device with jsxapi, | ||
* then require the macro file, which will run as if it had the same xapi object as the video device | ||
* | ||
* Usage: | ||
* const adapter = require('./universal-adapter'); | ||
* const videoDevice = { host: '10.0.0.99', username: 'admin', password: 'password' }; | ||
* await adapter(videoDevice) | ||
* require('./mymacro'); // macro starts with xapi available | ||
* | ||
*/ | ||
|
||
const jsxapi = require('jsxapi'); | ||
const Module = require('module'); | ||
|
||
const originalRequire = Module.prototype.require; | ||
|
||
function connectXapi ({ host, username, password }) { | ||
return new Promise((resolve, reject) => { | ||
jsxapi | ||
.connect('wss://' + host, { | ||
username, | ||
password, | ||
}) | ||
.on('error', e => reject(e)) | ||
.on('ready', async (xapi) => { | ||
console.log('Connected to', host); | ||
resolve(xapi); | ||
}); | ||
}); | ||
} | ||
|
||
async function init(deviceLogin) { | ||
const xapi = await connectXapi(deviceLogin); | ||
Module.prototype.require = function() { | ||
const moduleName = arguments[0]; | ||
if (moduleName === 'xapi') return xapi; | ||
return originalRequire.apply(this, arguments); | ||
} | ||
} | ||
|
||
module.exports = init; |