Skip to content

Instantly share code, notes, and snippets.

@masterex1000
Created December 10, 2018 14:53
Show Gist options
  • Save masterex1000/e984823ac267d6a0018c384f6a28c87c to your computer and use it in GitHub Desktop.
Save masterex1000/e984823ac267d6a0018c384f6a28c87c to your computer and use it in GitHub Desktop.
/**
* A thin event-driven rpc system built with gun
*
* this implementation is bigger than it needs to be
* but it does have some nice quality of life features
**/
var DEBUG = true; //Set to false if not debugging garp
class Rpc {
constructor(gun, name) {
this.gun = gun;
this.name = (typeof name !== 'undefined') ? name : '';
gun.on("opt", context => {
this.validater(context);
});
}
validater(ctx) {
ctx.on("in", function (msg) {
this.to.next(msg);
if(DEBUG)
console.log(msg);
});
}
}
if(typeof window == "undefined") {
module.exports = {
Rpc: Rpc,
}
}
//This is a basic and flexable test enviroment
var Gun = require("gun");
// Put Dev Dependencies Here
let Garp = require("./garp.js");
// end dev dependines
//Pre-Gun Stuff
let myRpc = new Garp.Rpc(Gun, "My Server"); // Create a new Garp Client/Server
//End Pre-Gun Stuff
var peers = []; //put the peers here
//peers.push("https://notabug.io/gun");
var gun = Gun({peers:peers});
//Start Tester code
//console.log(Garp);
//gun.get('aaaaaaaaaa').get("bbbbbbb").on(() => {});
gun._.on('out', {"asdf":"aaaaa"});
//gun.get("aaaaaaaaaa").get("bbbbbbb").put("aaaaaaaa");
@bugs181
Copy link

bugs181 commented Dec 10, 2018

As mentioned in Gitter;

This line:
let myRpc = new Garp.Rpc(Gun, "My Server"); // Create a new Garp Client/Server

Should be
let myRpc = new Garp(Gun, "My Server"); // Create a new Garp Client/Server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment