docs: custom module update
This commit is contained in:
parent
ca63ddf072
commit
f4718abeed
1 changed files with 35 additions and 37 deletions
|
|
@ -34,7 +34,7 @@ module.exports = {
|
|||
oscOutFilter:function(data){
|
||||
// Filter outgoing osc messages
|
||||
|
||||
var {address, args, host, port} = data
|
||||
var {address, args, host, port, clientId} = data
|
||||
|
||||
// same as oscInFilter
|
||||
|
||||
|
|
@ -50,48 +50,46 @@ module.exports = {
|
|||
|
||||
The module is executed in a restricted context, only a few globals are available :
|
||||
|
||||
- `console`: `object`
|
||||
- `sendOsc`: `function({host, port, address, args})`
|
||||
- `receiveOsc`: `function({host, port, address, args})`
|
||||
- `send`: `function(host, port, address, arg1, arg2, ...)`
|
||||
- `receive`: `function(host, port, address, arg1, arg2, ...)`
|
||||
- `receive`: `function(address, arg1, arg2, ...)`
|
||||
- `setTimeout`: `function(function, delay)`
|
||||
- `clearTimeout`: `function(timeout)`
|
||||
- `setInterval`: `function(function, delay)`
|
||||
- `clearInterval`: `function(interval)`
|
||||
- `settings.read`: `function(name)`, see [settings.js](https://github.com/jean-emmanuel/open-stage-control/blob/master/src/server/settings.js#L55-L103) 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/src/server/callbacks.js), callbacks are called with 2 arguments: `data` (object) and `client` (object: `{address, id}`)
|
||||
- `options`: `array` containing the extra options passed to `--custom-module` after the filename
|
||||
- `loadJSON`: `function(path)` loads a json file (path is relative to the custom module location)
|
||||
- `saveJSON`: `function(path, object)` save an object/array to a json file (path is relative to the custom module location)
|
||||
#### `app`: [`Event Emitter`](https://nodejs.org/api/events.html#events_class_eventemitter)
|
||||
Useful 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/src/server/callbacks.js), callbacks are called with 2 arguments: `data` (object) and `client` (object: `{address, id}`)
|
||||
|
||||
#### `receive`: `function(host, port, address, ...args, options)`
|
||||
|
||||
Send osc/midi message to connected clients. `host` and `port` can be specified to simulate a specific origin for the message.
|
||||
|
||||
- `host` (optional): `string` ip address, valid hostname or `"midi"`
|
||||
- `port` (optional): `integer` port number or `string` midi device name
|
||||
- `address`: osc address
|
||||
- `args`: value or `{type: "OSC_TYPE_LETTER", value: VALUE}` `object`
|
||||
- `options` (optional): set to `{clientId: id}` to define which client receives the message (where `id` is the client's id as retreived from `app` events or `oscOutFilter`)
|
||||
|
||||
#### `send`: `function(host, port, address, ...args)`
|
||||
|
||||
Send osc/midi to a target.
|
||||
|
||||
|
||||
`sendOsc` and `receiveOsc` expect arguments formatted as follow:
|
||||
#### `settings.read`: `function(name)`
|
||||
|
||||
- `address`: `string`
|
||||
- `args`: `array` of `{type: "OSC_TYPE_LETTER", value: VALUE}` `objects`
|
||||
- `host`: `string` ip address, valid hostname or `midi`
|
||||
- `port`: `integer` port number or `string` midi device name
|
||||
Returns specified server option. `name` must be the option's long name without the leading dashes (ie: `"send"`, not `"s"`)
|
||||
|
||||
`send` and `receive` are shorthands for `sendOsc` and `receiveOsc` that don't require args to be formatted as objects (numbers are casted to floats by default):
|
||||
#### `options`: `array`
|
||||
|
||||
```js
|
||||
// calling
|
||||
send('127.0.0.1', 5555, '/test' 1, 2, {type: 'i', value: 3})
|
||||
Contains the extra options passed to `--custom-module` after the filename
|
||||
|
||||
// equals
|
||||
sendOsc({
|
||||
host: '127.0.0.1',
|
||||
port: 5555,
|
||||
address: '/test',
|
||||
args: [
|
||||
{type: 'f', value: 1},
|
||||
{type: 'f', value: 2},
|
||||
{type: 'i', value: 3},
|
||||
]
|
||||
})
|
||||
```
|
||||
#### `loadJSON`: `function(path)`
|
||||
|
||||
Loads a json file (path is relative to the custom module location)
|
||||
|
||||
#### `saveJSON`: `function(path, object)`
|
||||
|
||||
Saves an object/array to a json file (path is relative to the custom module location)
|
||||
|
||||
#### Other javascript globals
|
||||
- `console`
|
||||
- `setTimeout`
|
||||
- `clearTimeout`
|
||||
- `setInterval`
|
||||
- `clearInterval`
|
||||
|
||||
## Managing big modules
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue