Created
December 10, 2018 14:53
-
-
Save masterex1000/e984823ac267d6a0018c384f6a28c87c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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