From 8441a4983ed74c000bcd148016662b6dc49201ba Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 3 Jan 2019 17:54:54 +0100 Subject: [PATCH] main: allow passing extra options to --custom-module and make them available through global object "options" --- CHANGELOG.md | 1 + resources/docs/extras/custom-module.md | 1 + resources/docs/getting-started.md | 2 +- src/server/osc/index.js | 8 +++++--- src/server/settings.js | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffa8c0d4..4544393d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - main - `--send` accepts `ip:port` and `domain:port` targets - removed previously deprecated `--sync` option + - `--custom-module` now accepts extra options that can be consumed from the custom module ## 0.40.5 diff --git a/resources/docs/extras/custom-module.md b/resources/docs/extras/custom-module.md index a4058436..14b0a9ad 100644 --- a/resources/docs/extras/custom-module.md +++ b/resources/docs/extras/custom-module.md @@ -56,6 +56,7 @@ The module is executed in a restricted context, only a few globals are available - `clearInterval`: `function(interval)` - `settings.read`: `function(name)`, see [settings.js](https://github.com/jean-emmanuel/open-stage-control/blob/master/app/main/settings.js#L125-L162) for available options - `app`: an [event emitter](https://nodejs.org/api/events.html#events_class_eventemitter) for monitoring the events sent by the different clients. Event names can be found in [callbacks.js](https://github.com/jean-emmanuel/open-stage-control/blob/master/app/main/callbacks.js), callbacks are called with 2 arguments: `data` (object) and `clientId` (string) +- `options`: `array` containing the extra options passed to `--custom-module` after the filename `sendOsc` and `receiveOsc` expect arguments formatted as follow: diff --git a/resources/docs/getting-started.md b/resources/docs/getting-started.md index a99f829b..9a422489 100644 --- a/resources/docs/getting-started.md +++ b/resources/docs/getting-started.md @@ -17,7 +17,7 @@ Below are the available command-line options. Note that when running without any | `-l` | `--load` | session file to load | | | `--state` | state file to load (osc messages will be sent, unless there are other clients connected) | | `-b` | `--blank` | load a blank session and start the editor | -| `-c` | `--custom-module` | custom module file to load | +| `-c` | `--custom-module` | custom module file to load (custom options can be passed after the filename) | | `-p` | `--port` | http port of the server (default to 8080) | | `-o` | `--osc-port` | osc input port (default to --port) | | | `--tcp-port` | tcp server input port | diff --git a/src/server/osc/index.js b/src/server/osc/index.js index 210d187b..77452fe5 100644 --- a/src/server/osc/index.js +++ b/src/server/osc/index.js @@ -17,11 +17,12 @@ class OscServer { this.customModuleEventEmitter = new EventEmitter() this.customModule = (()=>{ - if (!settings.read('customModule')) return false + var customModule = settings.read('customModule') + if (!customModule) return false var file = (()=>{ try { - return fs.readFileSync(settings.read('customModule'),'utf8') + return fs.readFileSync(customModule[0], 'utf8') } catch(err) { console.log('CustomModule Error: File not found: ' + settings.read('customModule')) return false @@ -37,7 +38,8 @@ class OscServer { clearTimeout, setInterval, clearInterval, - settings + settings, + options: customModule.slice(1, customModule.length) } try { diff --git a/src/server/settings.js b/src/server/settings.js index 6d104427..f91908f4 100644 --- a/src/server/settings.js +++ b/src/server/settings.js @@ -16,7 +16,7 @@ var options = { 'l':{alias:'load',type:'string',file:{name:'OSC Session (.json)', extensions: ['json', 'js']},describe:'session file to load'}, 'state':{type:'string',file:{name:'OSC State (.state)', extensions: ['state']},describe:'state file to load'}, 'b':{alias:'blank',type:'boolean',describe:'load a blank session and start the editor'}, - 'c':{alias:'custom-module',type:'string',file:{name:'OSC Custom module (.js)', extensions: ['js']},describe:'custom module file to load'}, + 'c':{alias:'custom-module',type:'array',file:{name:'OSC Custom module (.js)', extensions: ['js']},describe:'custom module file to load (custom options can be passed after the filename)'}, 'p':{alias:'port',type:'number',describe:'http port of the server (default to 8080)', check: (p)=>{ return (!isNaN(p) && p > 1023 && parseInt(p)===p) ?