2.0.4 • Published 4 years ago

nodewire v2.0.4

Weekly downloads
129
License
ISC
Repository
-
Last release
4 years ago

Creating a node

import {nw, Node} from 'nodewire'

let thenode;
let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImFobWFkLnNAZmF4dGVyLmNvbSIsImluc3RhbmNlIjoiaHgzZjN0Yzh6Y3Q3In0.cHdgXdoD4_Fkr-W0KRhoXJdsgbY-c6rXfbsuUaGgmwg";

nw.once('gack', ()=>{
    thenode = new Node('mynode', {
        inputs: 'start reset',
        outputs: 'count status',
        init: node => {
            setInterval(()=>node.handler.loop(node), 1000);
        },
        onReset: (node, val) => {
            node.count = val;
        },
        getStatus: node => {
            return {
                count: node.count,
                counting: node.start===1
            };
        },
        loop: node => {
            if(node.start===1)
                node.count+=1;
        }
    }); 
})

nw.connect({token: token});
export default thenode;

Connect to a node

import {nw, Node} from 'nodewire'

let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6ImFobWFkLnNAZmF4dGVyLmNvbSIsImluc3RhbmNlIjoiaHgzZjN0Yzh6Y3Q3In0.cHdgXdoD4_Fkr-W0KRhoXJdsgbY-c6rXfbsuUaGgmwg";
nw.onStart(async ()=>{
    const me = new Node('control');
    let thenode = await me.getNode('mynode');
    thenode.setHandler({
        onCount: val => {
            console.log('got', val);
            if(val==10) thenode.start = 0;
        }
    })
    thenode.reset = 0;
    thenode.start = 1;
});

nw.connect({
    token: token,
    server: 'localhost'
});

ReactJs Client

import React, { Component } from 'react';
import {nw, Node} from 'nodewire';

var thenode;
 
class App extends Component {
    state = {count:0, waiting: true}
    constructor(){
        super();
        const initialize = async () =>  {
            const me = new Node('control');
            thenode = await me.getNode('mynode'); 
            this.setState({waiting: false, count: thenode.count});
            thenode.setHandler({
                onCount: val => {
                    this.setState({count: val});
                }
            })
        }
        nw.onStart(initialize);
    }

    render() {
        if(this.state.waiting)
            return (
                <div>
                    Wait ...
                </div>
            )
        return (
            <div>
                <div>
                    {this.state.count}
                </div>
                <button onClick={()=>{
                    thenode.start = 1;
                }}>Start</button>
                <button onClick={()=>{
                    thenode.start = 0;
                }}>Stop</button>
                <button onClick={()=>{
                    thenode.reset = 0;
                }}>Reset</button>
            </div>
        );
    }
}
 
export default App;

React Hooks

import React, { useState, useEffect } from 'react';
import {nw, Node} from 'nodewire';

var thenode;
function App() {
    const [count, setCount] = useState(0);
    const [waiting, setWaiting] = useState(true);
    
    useEffect(() => {
        async function initialize(){
            const me = new Node('control');
            thenode = await me.getNode('mynode'); 
            setCount(thenode.count);
            setWaiting(false);
            thenode.setHandler({
                onCount: val => {
                    setCount(val);
                }
            })
        }
        nw.onStart(initialize);
    }, []);

    if(waiting)
        return (
            <div>
                Wait ...
            </div>
        )
    return (
        <div>
            <div>
               The Count is: {count}
            </div>
            <button onClick={()=>{
                thenode.start = 1;
            }}>Start</button>
            <button onClick={()=>{
                thenode.start = 0;
            }}>Stop</button>
            <button onClick={()=>{
                thenode.reset = 0;
            }}>Reset</button>
        </div>
    );
}
export default App;

issues

  1. when node goes offline, messages should be queued for when it comes back online
  2. monitor delivery, and queue if not delivered

node.setportvalue: if state == disconnected: save cmd else: send and save in temp if val not received in 3 seconds: chnage state to disconnected save tmp

on(gack): for node in nodes: node.set_state = connected node.send_saved_cmds

2.0.3

4 years ago

2.0.2

4 years ago

2.0.4

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.9.9

6 years ago

0.9.8

6 years ago

0.9.7

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.99

6 years ago

0.8.97

6 years ago

0.8.96

6 years ago

0.8.95

6 years ago

0.8.94

6 years ago

0.8.93

6 years ago

0.8.92

6 years ago

0.8.91

6 years ago

0.8.90

6 years ago

0.8.87

6 years ago

0.8.86

6 years ago

0.8.85

6 years ago

0.8.84

6 years ago

0.8.82

6 years ago

0.8.81

6 years ago

0.8.80

6 years ago

0.8.79

6 years ago

0.8.78

6 years ago

0.8.77

6 years ago

0.8.76

6 years ago

0.8.75

7 years ago

0.8.74

7 years ago

0.8.73

7 years ago

0.8.72

7 years ago

0.8.71

7 years ago

0.8.70

7 years ago

0.8.69

7 years ago

0.8.68

7 years ago

0.8.67

7 years ago

0.8.66

7 years ago

0.8.65

7 years ago

0.8.64

7 years ago

0.8.63

7 years ago

0.8.62

7 years ago

0.8.61

7 years ago

0.8.60

7 years ago

0.8.59

7 years ago

0.8.58

7 years ago

0.8.57

7 years ago

0.8.56

7 years ago

0.8.55

7 years ago

0.8.54

7 years ago

0.8.53

7 years ago

0.8.52

7 years ago

0.8.51

7 years ago

0.8.50

7 years ago

0.8.49

7 years ago

0.8.48

7 years ago

0.8.47

7 years ago

0.8.46

7 years ago

0.8.45

7 years ago

0.8.44

7 years ago

0.8.43

7 years ago

0.8.42

7 years ago

0.8.41

7 years ago

0.8.40

7 years ago

0.8.39

7 years ago

0.8.38

7 years ago

0.8.37

7 years ago

0.8.36

7 years ago

0.8.35

7 years ago

0.8.34

7 years ago

0.8.33

7 years ago

0.8.32

7 years ago

0.8.31

7 years ago

0.8.30

7 years ago

0.8.29

7 years ago

0.8.28

7 years ago

0.8.27

7 years ago

0.8.26

7 years ago

0.8.25

7 years ago

0.8.24

7 years ago

0.8.23

7 years ago

0.8.22

7 years ago

0.8.21

7 years ago

0.8.20

7 years ago

0.8.19

7 years ago

0.8.18

7 years ago

0.8.17

7 years ago

0.8.16

7 years ago

0.8.15

7 years ago

0.8.14

7 years ago

0.8.13

7 years ago

0.8.12

7 years ago

0.8.11

7 years ago

0.8.10

7 years ago

0.8.9

7 years ago

0.8.8

7 years ago

0.8.7

7 years ago

0.8.6

7 years ago

0.8.5

7 years ago

0.8.4

7 years ago

0.8.3

7 years ago

0.8.2

7 years ago

0.8.1

7 years ago

0.8.0

7 years ago

0.4.0

8 years ago