Skip to content

meething/gundb-multisocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mozilla-builders

Gun MultiSocket

Single HTTP/S server providing multiple ephemeral GunDB WebSocket instances with path based routing and mesh isolation.

Notes

  • uses its own mem storage adaptor to avoid any disk writes
  • uses its own websockets adaptor allowing injection into Gun contructors
  • MUST be served through SSL and can easily be deployed on glitch and other platforms.

Configuration

  • requires a valid set of SSL/TLS certificates (letsencrypt)

Installation

npm install

Usage

npm

Explode your ENV variables manually and launch using npm:

SSL=true SSLKEY=/path/to/privkey.pem SSLCERT=/path/to/fullchain.pem npm start

pm2

Configure the options in multisocket.config.js and launch using pm2:

pm2 start multisocket.config.js

Remix on Glitch

Gun WS Flow

Practical Example

In this example we want the data of Jack and Jill to be partitioned and not shared between different ws /paths

localStorage.clear();

// Create the first gun endpoint
var random1 = Math.random().toString(36).substring(7);
var gun1 = Gun({peers:["https://gundb-multiserver.glitch.me/"+random1], musticast: false, localStorage: false, radisk: false, file: false});
// Create Jack
gun1.get('jack').put({ name: "Jack" });

// This should be triggered for Jack only
gun1.get('jack').on(function(data, key){
  console.log("gun 1 update:", data);
});
// This should never be triggered! It's from Jill after all.
gun1.get('jill').on(function(data, key){
  console.log("Jack should NOT see Jill's update", data);
});

// Create the second gun endpoint
var random2 = Math.random().toString(36).substring(7);
var gun2 = Gun({peers:["https://gundb-multiserver.glitch.me/"+random2], multicast: false, localStorage: false, radisk: false, file: false});
// Create Jill
gun2.get('jill').put({ name: "Jill"});
// This should be triggered for Jill only
gun2.get('jill').on(function(data, key){
  console.log("gun 2 update:", data);
});
Credits

This project is a component of Gun Meething powered by GunDB