How to use the gun/gun.time 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 PsychoLlama / Trace / server / game / expire.js View on Github external
function expired(player) {
	var max, vel = options.speed;
	max = Math.max.apply(Math, Object.keys(player));

	// distance travelled is greater than the board, plus latency
	return (Gun.time.is() - (max + options.latency)) * vel > 700;
}
github PsychoLlama / Trace / web / find.js View on Github external
module.exports = function find(player) {
	var coord, position;
	coord = sort(player);
	coord = coord[coord.length - 1];

	// if the player has no history
	if (!coord) {
		return null;
	}

	// don't mutate the last position, make a copy
	position = Gun.obj.copy(coord);

	position[coord.axis] = distance(coord);
	position.time = Gun.time.is();

	return position;
};
github PsychoLlama / Trace / web / claim.js View on Github external
module.exports = function (number) {
	var start, color, time = Gun.time.is();

	player.db = players.db.path(number).put({});
	player.index = number;
	player.object = players.list[number];

	// get the player starting point
	start = position(number);
	player.db.path(time).stringify(start);

	// give the player a chance to escape
	invincible.player(player.index, true);
};
github gundb / gun-rtc / src / index.js View on Github external
/*jslint nomen: true, node: true */
'use strict';

var handshake = require('../lib/handshake');
var peers = require('../lib/peers');
var SimplePeer = require('simple-peer');
var Gun = require('gun/gun');
var local = require('./local');
Gun.time.now = function () {
	return new Date().getTime();
};

Gun.on('opt').event(function (gun, opt) {
	opt = opt || {};
	var support, browser, wire, rtc = opt.rtc;
	support = SimplePeer.WEBRTC_SUPPORT;
	browser = typeof window !== 'undefined';
	
	if (rtc === false || (!support && browser)) {
		return;
	}

	if (!peers.db) {

		peers.db = new Gun({
github PsychoLlama / Trace / web / clock.js View on Github external
Gun.time.is = function () {
				return Gun.time.is() + Math.round(diff);
			};
github PsychoLlama / Trace / web / turn.js View on Github external
module.exports = function (direction) {
	var time, turn, position;
	position = find(local.player.object);
	if (!position) {
		return;
	}
	turn = extract(direction);
	time = Gun.time.is();

	if (position.axis === turn.axis) {
		return;
	}

	local.player.db.path(time).stringify(turn);
};
github PsychoLlama / Trace / web / find.js View on Github external
function distance(coord) {
	var delta, elapsed = Gun.time.is() - coord.time;
	delta = (elapsed * options.speed) * coord.direction;

	return delta + coord[coord.axis];
}
github PsychoLlama / Trace / web / clock.js View on Github external
}).on(function (msg) {
		if (msg.recieved && !processed) {
			processed = true;

			var now, latency, diff;
			now = Gun.time.is();

			latency = (now - msg.sent) / 2;

			diff = now - (msg.recieved + latency);

			Gun.time.is = function () {
				return Gun.time.is() + Math.round(diff);
			};

			(callback || function () {})();
		}
	});
github PsychoLlama / Trace / web / clock.js View on Github external
module.exports = function (callback) {
	var adjustment = gun.put({
		sent: Gun.time.is()
	}).on(function (msg) {
		if (msg.recieved && !processed) {
			processed = true;

			var now, latency, diff;
			now = Gun.time.is();

			latency = (now - msg.sent) / 2;

			diff = now - (msg.recieved + latency);

			Gun.time.is = function () {
				return Gun.time.is() + Math.round(diff);
			};

			(callback || function () {})();

gun

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

(Zlib OR MIT OR Apache-2.0)
Latest version published 14 days ago

Package Health Score

83 / 100
Full package analysis