Mist API
A native node.js plugin which uses the C99 Mist implementation. Currently working with Linux x86_64 and nodejs v6, v8, v10. To get it working you need to run a Wish Core on the same host.
Install
npm install mist-api
Example
var MistNode = require('mist-api').MistNode;
function Motor() {
var name = 'Motor';
var number = 42;
var node = new MistNode({ name: name });
node.addEndpoint('mist', { type: 'string' });
node.addEndpoint('mist.name', { type: 'string', read: function(args, peer, cb) { cb(null, name); } });
node.addEndpoint('number', {
type: 'float',
read: function(args, peer, cb) { cb(null, number); },
write: function(value, peer, cb) {
number = parseFloat(value);
cb();
node.changed('number');
}
});
var interval = setInterval(() => { number++; node.changed('number'); }, 5000);
node.addEndpoint('getLog', {
type: 'invoke',
invoke: function(args, peer, cb) {
cb(null, { dataset: [{ x: 2, y: 45 }, { x: 5, y: 55 }], request: args, requestee: peer });
}
});
this.shutdown = function() { clearInterval(interval); node.shutdown(); };
}
var motor = new Motor();
Problems
node-gyp fails on c++ compile error "class v8 has no member IsUint8Array" or similar
This occurs on hosts that have node.js 0.10.x installed as 'nodejs', and
node-gyp. Solution:
This usually occurs on a host with multiple node.js installations, or
if are on a host with an outdated system-wide installation of node.js
(Such as many slightly older Debian installations)
You should use Node version manager (NVM) to install node 6. https://github.com/creationix/nvm
Then you should switch your session to using node.js 6.x, 8, or 10
and install node-gyp to that instance of node.js:
nvm use 6
npm i -g node-gyp