Skip to content

🕳️🥊🌐 Allows many topic handlers for different modules over one hyperswarm. Just plug this one swarm into all of them.

Notifications You must be signed in to change notification settings

benzmuircroft/hyperswarmRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🕳️🥊hyperswarmRouter 🌐

Allows many topic handlers for different modules over one hyperswarm. Just plug this one swarm into all of them.

Used By

hyperswarmCRDT

TODO

Installation

npm install "github:benzmuircroft/hyperswarmRouter"

API

// First user
const network = 'c915296031bf40b58ef7f1d6b883512e799c1982b83acdc7ce27a2079a8c196f'; // a hard-coded 64 character hex string
const router = await require('hyperswarmRouter')(network);
let broadcast1, broadcast2;

// connect to peers on 'topic1'
broadcast1 = router.join('topic1', async function handler1(data) {
  // receive and handle broadcasts from peers on 'topic1' here
  console.log(data);
});

// now you can broadcast data to peers on 'topic1'
await broadcast1({ info: 'xyz' });

// connect to peers on 'topic2'
broadcast2 = router.join('topic2', async function handler2(data) {
  // receive and handle broadcasts from peers on 'topic2' here
  console.log(data);
  // leave 'topic2'
  broadcast2 = router.leave('topic2'); // null
});

// now you can broadcast data to peers on 'topic2'
await broadcast2({ type: 'dog', age: 3, array: [0, 1, 2, 3] });
// Second user
const network = 'c915296031bf40b58ef7f1d6b883512e799c1982b83acdc7ce27a2079a8c196f'; // a hard-coded 64 character hex string
const router = await require('hyperswarmRouter')(network);
let broadcast2; // isn't interested in 'topic1'

// connect to peers on 'topic2'
broadcast2 = router.join('topic2', async function handler2(data) {
  // receive and handle broadcasts from peers on 'topic2' here
  console.log(data);
  // leave 'topic2'
  broadcast2 = router.leave('topic2'); // null
});

// now you can broadcast data to peers on 'topic2'
await broadcast2({ type: 'cat', age: 9, array: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] });

About

🕳️🥊🌐 Allows many topic handlers for different modules over one hyperswarm. Just plug this one swarm into all of them.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published