N2O library for React (WS + MQTT)
React library for build fast and scalable frontend for N2O server (MQTT version)
- MQTT 3.1.1 (Signaling messages)
[not implemented yet]
Websocket transport for files (25MB/s)
npm i --save git+https://github.com/erlang-one/react-n2o#master
import { mq, bert, proto, utf8 } from 'react-n2o'
const mqtt = new mq()
mqtt.start({ host: 'localhost', protocols: [ proto.io ]})
let mes = bert.enc(bert.tuple(bert.atom('SynData'),bert.number(234)))
mqtt.send(mes)
new mq(Options | undefined)
– create instancemq.init(Options | undefined)
– initialize parameters (optional)mq.start(Options | undefined)
– connect to server (auto init if the Options passed)[not implemented yet]
mq.stop()
– disconnectmq.send(Payload, qos = 2)
– send binary data with QoS
Options = {
nodes = 4, // N2O nodes must be equal or less of n2o_ring:nodes()
host, // hostname (string)
port, // MQTT port (number)
protocols, // N2O protocol list of Protocol
onMessage // Callback function
}
Payload argument: ArrayBuffer | Uint8Array
QoS argument: 0 | 1 | 2
Protocol example
let myProto = {
type: 'protocol',
name: 'my protocol',
on: (r) => {
if(r !== 'my format') return false
console.log('my protocol message: ', r)
return true // accept message and stop core foreach for this message
}
}
export default myProto
brew install npm
npm i -g babel-cli
cd ./react-n2o
npm test
- Clone repository to local
git clone
- Link repository of package to npm
In the local module directory:
cd ./react-n2o
npm link
In the directory of the project to use the module:
cd ./you-project-dir
npm link react-n2o
- Modify, test and create Pull Request
- Andrey Martemyanov
- Maxim Sokhatsky