I'm making a simple app in JS (using p5.js library) via Cordova, I want it to send faders positions in OSC in order to control stage lights from my smartphone (The thing is free apps -like OSC controller by Adam Katz- run fine but doesn't have enough parameters and flexibility for my usage).
So I created my project, made the graphics without trouble (with p5.js), but I'm stuck with the OSC plugin part: I installed this plugin : text with the cordova :
cordova plugin add cordova-plugin-osc
In my project directory.
But when I tried to use function from this plugin (as describe in the example) :
var port = 8000;
var osc = new OSC();
I got this error from emulated device inspector's console :
Uncaught ReferenceError: OSC is not defined
at main.js:1
I first tried to copy the OSC.js file from the plugin in my /www/ directory and to mention it in my html file... without succes.
I verified that the plugin was well installed (I also tried to installed inside the project directory but the /www/ directory inside the project, but he told me the plugin was already installed).
I also tried to require it at the beginning of my code:
var OSC = require ('OSC');
but it seems to be a nodejs function that I may not use in cordova?
well, you might understand that I'm kinda lost with all that...
Ok got it.
It is just that as the plugin depend on cordova, it has to wait for the device to be ready. So variable declaration from the plugin cannot be 'public', it has to be in a function that doesn't start before the "deviceReady" status.
So works fine like this for me :
function oscFire() {
var osc = new OSC();
let SentValue = int(map(fader[CurrentFader], w / 15 * 2, w - w / 8, 0, 256));
osc.send({
remoteAddress: ip,
remotePort: port,
address: '/fader' + CurrentFader,
arguments: [SentValue]
});
}