1.7.0 • Published 12 days ago

nuclearnet.js v1.7.0

Weekly downloads
174
License
MIT
Repository
github
Last release
12 days ago

NUClearNet.js

Node.js CI

Node.js module for interacting with the NUClear network.

Installation

The package contains a native module, so you'll need a working C++ compiler on your system to install and build it.

npm install nuclearnet.js --save

Usage

The following example shows a typical usage pattern of creating a network instance, listening for join, leave, and packet events, and sending data.

const { NUClearNet } = require('nuclearnet.js');

// Create a network instance
const net = new NUClearNet();

// Set a join listener to be notified when peers join the network.
// This should be done before calling `connect()` for the first time, to get join events
// from peers that are already on the network.
net.on('nuclear_join', function (peer) {
  console.log(`peer ${peer.name} has joined`);
});

// Set a leave listener to be notified when peers leave the network
net.on('nuclear_leave', function (peer) {
  console.log(`peer ${peer.name} has left`);
});

// Listen for all incoming packets
net.on('nuclear_packet', function (packet) {
  const packetType = packet.type !== undefined ? packet.type : 'unknown type';
  console.log(`got a packet (${packetType}) of length ${packet.payload.length} from peer ${packet.peer.name}`);
});

// Listen for packets of a specific type
net.on('packet_type_a', function (packet) {
  console.log(`got a packet (packet_type_a) of length ${packet.payload.length} from peer ${packet.peer.name}`);

  // Send a response to the peer
  net.send({
    target: packet.peer.name,
    reliable: true,
    type: 'packet_type_b',
    payload: Buffer.from('hello there!'),
  });
});

// Connect to the network using the peer name "My Name"
net.connect({ name: 'My Name' });

API

See index.d.ts for types and API details.

1.7.0

12 days ago

1.6.1

1 month ago

0.1.6-beta.2

2 years ago

1.6.0

2 years ago

0.1.6-beta.6

2 years ago

0.1.6-beta.7

2 years ago

0.1.6-beta.5

2 years ago

1.5.5

3 years ago

1.5.4

5 years ago

1.5.3

6 years ago

1.5.2

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago