custom-module: add support for standard module export syntax
This commit is contained in:
parent
e7ec5208e1
commit
cce58c9fc9
3 changed files with 32 additions and 29 deletions
|
|
@ -9,6 +9,7 @@
|
|||
- custom module
|
||||
- expose shorthand functions `send` and `receives`
|
||||
- expose a client object instead of just an id in `app` event handlers to allow retrieving the client's ip address as well
|
||||
- custom modules can now be written like standard nodejs modules (using `module.exports` assignement instead of a self-invoking function pattern)
|
||||
|
||||
## 0.42.0
|
||||
|
||||
|
|
|
|||
|
|
@ -2,46 +2,45 @@
|
|||
|
||||
Using the `-c / --custom-module` command-line switch, users can load a javascript file to tune the way Open Stage Control behaves regarding osc.
|
||||
|
||||
It must be of the following form:
|
||||
|
||||
```js
|
||||
(function(){
|
||||
|
||||
// Do whatever you want, initialize some variables, declare some functions, ...
|
||||
// Do whatever you want, initialize some variables, declare some functions, ...
|
||||
|
||||
return {
|
||||
init: function(){
|
||||
// this will be executed once when the osc server starts
|
||||
},
|
||||
oscInFilter:function(data){
|
||||
// Filter incomming osc messages
|
||||
module.exports = {
|
||||
|
||||
var {address, args, host, port} = data
|
||||
init: function(){
|
||||
// this will be executed once when the osc server starts
|
||||
},
|
||||
|
||||
// do what you want
|
||||
oscInFilter:function(data){
|
||||
// Filter incomming osc messages
|
||||
|
||||
// address = string
|
||||
// args = array of {value, type} objects
|
||||
// host = string
|
||||
// port = integer
|
||||
var {address, args, host, port} = data
|
||||
|
||||
// return data if you want the message to be processed
|
||||
return {address, args, host, port}
|
||||
// do what you want
|
||||
|
||||
},
|
||||
oscOutFilter:function(data){
|
||||
// Filter outgoing osc messages
|
||||
// address = string
|
||||
// args = array of {value, type} objects
|
||||
// host = string
|
||||
// port = integer
|
||||
|
||||
var {address, args, host, port} = data
|
||||
// return data if you want the message to be processed
|
||||
return {address, args, host, port}
|
||||
|
||||
// same as oscInFilter
|
||||
},
|
||||
|
||||
// return data if you want the message to be and sent
|
||||
return {address, args, host, port}
|
||||
}
|
||||
oscOutFilter:function(data){
|
||||
// Filter outgoing osc messages
|
||||
|
||||
var {address, args, host, port} = data
|
||||
|
||||
// same as oscInFilter
|
||||
|
||||
// return data if you want the message to be and sent
|
||||
return {address, args, host, port}
|
||||
}
|
||||
|
||||
})()
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -54,11 +54,14 @@ class OscServer {
|
|||
setTimeout, clearTimeout,
|
||||
setInterval, clearInterval,
|
||||
settings,
|
||||
options: customModule.slice(1, customModule.length)
|
||||
options: customModule.slice(1, customModule.length),
|
||||
module: {},
|
||||
}
|
||||
|
||||
try {
|
||||
mod = vm.runInContext(file, vm.createContext(context))
|
||||
var context = vm.createContext(context)
|
||||
mod = vm.runInContext(file, context)
|
||||
if (context.module.exports) mod = context.module.exports
|
||||
} catch(err) {
|
||||
console.error(err)
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue