2.0.4 • Published 3 years ago

nodewire v2.0.4

Weekly downloads
129
License
ISC
Repository
-
Last release
3 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

3 years ago

2.0.2

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago

0.9.9

5 years ago

0.9.8

5 years ago

0.9.7

5 years ago

0.9.6

5 years ago

0.9.5

5 years ago

0.9.4

5 years ago

0.9.3

5 years ago

0.9.2

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.99

5 years ago

0.8.97

5 years ago

0.8.96

5 years ago

0.8.95

5 years ago

0.8.94

5 years ago

0.8.93

5 years ago

0.8.92

5 years ago

0.8.91

5 years ago

0.8.90

5 years ago

0.8.87

5 years ago

0.8.86

5 years ago

0.8.85

5 years ago

0.8.84

5 years ago

0.8.82

5 years ago

0.8.81

5 years ago

0.8.80

5 years ago

0.8.79

5 years ago

0.8.78

5 years ago

0.8.77

5 years ago

0.8.76

5 years ago

0.8.75

6 years ago

0.8.74

6 years ago

0.8.73

6 years ago

0.8.72

6 years ago

0.8.71

6 years ago

0.8.70

6 years ago

0.8.69

6 years ago

0.8.68

6 years ago

0.8.67

6 years ago

0.8.66

6 years ago

0.8.65

6 years ago

0.8.64

6 years ago

0.8.63

6 years ago

0.8.62

6 years ago

0.8.61

6 years ago

0.8.60

6 years ago

0.8.59

6 years ago

0.8.58

6 years ago

0.8.57

6 years ago

0.8.56

6 years ago

0.8.55

6 years ago

0.8.54

6 years ago

0.8.53

6 years ago

0.8.52

6 years ago

0.8.51

6 years ago

0.8.50

6 years ago

0.8.49

6 years ago

0.8.48

6 years ago

0.8.47

6 years ago

0.8.46

6 years ago

0.8.45

6 years ago

0.8.44

6 years ago

0.8.43

6 years ago

0.8.42

6 years ago

0.8.41

6 years ago

0.8.40

6 years ago

0.8.39

6 years ago

0.8.38

6 years ago

0.8.37

6 years ago

0.8.36

6 years ago

0.8.35

6 years ago

0.8.34

6 years ago

0.8.33

6 years ago

0.8.32

6 years ago

0.8.31

6 years ago

0.8.30

6 years ago

0.8.29

6 years ago

0.8.28

6 years ago

0.8.27

6 years ago

0.8.26

6 years ago

0.8.25

6 years ago

0.8.24

6 years ago

0.8.23

6 years ago

0.8.22

6 years ago

0.8.21

6 years ago

0.8.20

6 years ago

0.8.19

6 years ago

0.8.18

6 years ago

0.8.17

6 years ago

0.8.16

6 years ago

0.8.15

6 years ago

0.8.14

6 years ago

0.8.13

6 years ago

0.8.12

6 years ago

0.8.11

6 years ago

0.8.10

6 years ago

0.8.9

6 years ago

0.8.8

6 years ago

0.8.7

6 years ago

0.8.6

6 years ago

0.8.5

6 years ago

0.8.4

6 years ago

0.8.3

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago

0.4.0

7 years ago