How to use the gun function in gun

To help you get started, we’ve selected a few gun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dtube / dtube / client / app.js View on Github external
Meteor.startup(function(){
  console.log('DTube APP Started')
  var konami = new KonamiCode();
  konami.listen(function() {
    // ??
  })

  window.steem = steem
  window.testgun=Gun({peers:["https://guntest.herokuapp.com/gun"],localStorage:!1});
  window.testgun.get("test").on(function(t){testgun.count=(testgun.count||0)+1});
  Session.set('remoteSettings', Meteor.settings.public.remote)

  // choose steem api on startup
  if(!localStorage.getItem('steemAPI'))
    steem.api.setOptions({ url: Meteor.settings.public.remote.APINodes[0], useAppbaseApi: true}); //Default
  else
    steem.api.setOptions({ url: localStorage.getItem('steemAPI'), useAppbaseApi: true }); //Set saved API.

  Session.set('steemAPI', steem.api.options.url)
  Session.set('lastHot', null)
  Session.set('lastTrending', null)
  Session.set('lastCreated', null)
  Session.set('lastBlogs', {})
  Session.set('tagDays', 7)
  Session.set('tagSortBy', null)
github irislib / iris-lib / src / socialNetwork.js View on Github external
async _init() {
    let keypair = this.options.keypair;
    if (!keypair) {
      keypair = await Key.getDefault();
    }
    const gun = this.options.gun || new Gun();
    const user = gun.user();
    user.auth(keypair);
    this.writable = true;
    this.rootContact = new Attribute(`keyID`, Key.getId(keypair));
    user.get(`epub`).put(keypair.epub);
    // Initialize indexes with deterministic gun souls (.top)
    this.gun = user.get(`iris`).put(user.top(`iris`));
    this.gun.get(`identitiesBySearchKey`).put(user.top(`identitiesBySearchKey`));
    this.gun.get(`identitiesByTrustDistance`).put(user.top(`identitiesByTrustDistance`));
    this.gun.get(`messages`).put(user.top(`messages`));
    this.gun.get(`messagesByTimestamp`).put(user.top(`messagesByTimestamp`));
    this.gun.get(`messagesByHash`).put(user.top(`messagesByHash`));
    this.gun.get(`messagesByDistance`).put(user.top(`messagesByDistance`));

    this.messages = new Collection({gun: this.gun, class: Message, indexes: [`time`, `trustDistance`]});
    this.contacts = new Collection({gun: this.gun, class: Contact});
github irislib / iris-lib / src / server.js View on Github external
if (!process.env.IRIS_NO_IPFS) {
    let IPFS = null;
    try {
      IPFS = require('js-ipfs');
    }
    catch (err) {
      console.warn('IRIS_NO_IPFS not set, and `js-ipfs` library not found! Local IPFS node NOT instantiated.');
    }
    if (IPFS) {
      await IPFS.create({repo: `${configDir}/${ipfsRepo}`});
    }
  }

  // Instantiate gun
  debug(gunConfig);
  const gun = new Gun(gunConfig);

  // Load default Iris index with given configuration
  config.gun = gun;
  const index = new Iris.SocialNetwork(config);
  debug(`index!`, index);

  //await index.create(); // Create an index, if one does not exist
  console.info(`Iris is up and running!`);
})().catch(e => {
  console.error(e);
github irislib / iris-lib / src / util.js View on Github external
const newGuns = ports.map(port => {
      const server = http.createServer(Gun.serve).listen(port, ip);
      const g = new Gun({
        radisk: false,
        port: port,
        multicast: false,
        peers: {},
        // file: `${configDir}/${gunDBName}.${port}`,
        web: server,
      });
      g.netPort = port;
      g.netId = netId;
      return g;
    });
github SocialXNetwork / socialx_react_native / packages / database / src / tcpServer.ts View on Github external
//
// have to do this before instancing gun(?)
const gunPeers: Array<{ send: (msg: any) => void }> = [];

Gun.on('out', function(msg: any) {
	// @ts-ignore
	this.to.next(msg);
	msg = JSON.stringify(msg);
	// tslint:disable-next-line
	gunPeers.forEach(function(peer) {
		peer.send(msg);
	});
});

const gun = Gun({
	file: 'data',
});

const server = http.createServer((req, res) => {
	let insert = '';
	if (req.url!.endsWith('gun.js')) {
		insert = '../';
	}

	fs.createReadStream(require('path').join(__dirname, insert, req.url))
		.on('error', () => {
			// static files!
			res.writeHead(200, { 'Content-Type': 'text/html' });
			res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
		})
		.pipe(res); // stream

gun

A realtime, decentralized, offline-first, graph data synchronization engine.

(Zlib OR MIT OR Apache-2.0)
Latest version published 1 year ago

Package Health Score

64 / 100
Full package analysis