Giter Club home page Giter Club logo

react-n2o's Introduction

react-n2o

N2O library for React (WS + MQTT)

Overview

React library for build fast and scalable frontend for N2O server (MQTT version)

Features

  • MQTT 3.1.1 (Signaling messages)
  • [not implemented yet] Websocket transport for files (25MB/s)

Dependency

Add to you React project

npm i --save git+https://github.com/erlang-one/react-n2o#master

Usage

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)

API

mq

  • new mq(Options | undefined) – create instance
  • mq.init(Options | undefined) – initialize parameters (optional)
  • mq.start(Options | undefined) – connect to server (auto init if the Options passed)
  • [not implemented yet] mq.stop() – disconnect
  • mq.send(Payload, qos = 2) – send binary data with QoS

Options

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

Payload argument: ArrayBuffer | Uint8Array

QoS

QoS argument: 0 | 1 | 2

Protocol

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

Testing

brew install npm
npm i -g babel-cli
cd ./react-n2o
npm test

Contributing

  1. Clone repository to local
git clone 
  1. 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
  1. Modify, test and create Pull Request

Credits

  • Andrey Martemyanov
  • Maxim Sokhatsky

react-n2o's People

Contributors

m-2k avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

pyzh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.