How to use the postal.instanceId function in postal

To help you get started, we’ve selected a few postal 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 postaljs / postal.federation / lib / node / postal.federation.js View on Github external
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";
    return s.join("");
  };
}

postal.fedx = _.extend({

  clients: {},

  transports: {},

  knownIds: [ postal.instanceId ],

  manifest: {},

  _processingIds: [],

  addToManifest: function(channel, topic, instanceId) {
    instanceId = instanceId || postal.instanceId;
    var manifest = this.manifest[instanceId];
    if(!manifest) {
      manifest = this.manifest[instanceId] = {}
    }
    if(!manifest[channel]) {
      manifest[channel] = [ topic ];
    } else {
      if(!_.contains(manifest[channel], topic)) {
        manifest[channel].push(topic);
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
addToManifest: function(channel, topic, instanceId) {
    instanceId = instanceId || postal.instanceId;
    var manifest = this.manifest[instanceId];
    if(!manifest) {
      manifest = this.manifest[instanceId] = {}
    }
    if(!manifest[channel]) {
      manifest[channel] = [ topic ];
    } else {
      if(!_.contains(manifest[channel], topic)) {
        manifest[channel].push(topic);
      }
    }
  },
github postaljs / postal.federation / src / handlers.js View on Github external
data.source.pings[data.packingSlip.pingData.ticket].callback( {
				ticket: data.packingSlip.pingData.ticket,
				instanceId: data.packingSlip.instanceId,
				source: data.source
			} );
			data.source.pings[data.packingSlip.pingData.ticket] = undefined;
		}
		if ( !_.contains( state._clients, data.packingSlip.instanceId ) ) {
			state._clients.push( data.packingSlip.instanceId );
		}
		postal.publish( {
			channel: "postal.federation",
			topic: "client.federated",
			data: {
				remoteId: data.source.instanceId,
				localId: postal.instanceId(),
				transport: data.transport
			}
		} );
	},
	"federation.disconnect": function( data ) {
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
callback : function(data, env) {
    postal.fedx.addToManifest(data.channel, data.topic);
    var payload = _.extend({
      envelope: {
        channel  : "postal.federation",
        topic    : "remote.subscription.created",
        originId : postal.instanceId,
        knownIds : postal.fedx.knownIds,
        data     : { channel: data.channel, topic: data.topic }
      }
    }, postal.fedx.getFedxWrapper("subscription.created"));
    postal.fedx.send(payload);
  }
}).withConstraint(function(d, e){
github postaljs / postal.federation / src / FederationClient.js View on Github external
sendMessage( envelope ) {
		if ( !this.handshakeComplete ) {
			return;
		}
		envelope.originId = envelope.originId || postal.instanceId();
		const env = _.clone( envelope );
		if ( this.instanceId && this.instanceId !== env.lastSender &&
		( !env.knownIds || !env.knownIds.length ||
		( env.knownIds && !_.include( env.knownIds, this.instanceId ) ) )
		) {
			env.knownIds = ( env.knownIds || [] ).concat( _.without( state._clients, this.instanceId ) );
			this.send( getPackingSlip( "message", env ) );
		}
	}
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
callback : function(data, env) {
          env = _.clone(env);
          env.originId = postal.instanceId;
          self.clients[id].send(_.extend({
            envelope: env
          }, self.getFedxWrapper("message")));
        }
      });
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
getFedxWrapper: function(type) {
    return {
      postal     : true,
      type       : type,
      instanceId : postal.instanceId
    }
  },
github postaljs / postal.federation / src / index.js View on Github external
topic: "instanceId.changed",
	callback: function() {
		state._ready = true;
		while ( state._signalQueue.length ) {
			processSignalQ( state._signalQueue.shift() );
		}
		while ( state._outboundQueue.length ) {
			processOutboundQ( state._outboundQueue.shift() );
		}
		while ( state._inboundQueue.length ) {
			processInboundQ( state._inboundQueue.shift() );
		}
	}
} );

if ( postal.instanceId() !== undefined ) {
	state._ready = true;
}
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
callback : function(d, e) {
    postal.fedx._processingIds = e.knownIds;
    postal.fedx.addClientSubscription(e.originId, d.channel, d.topic);
    postal.fedx._processingIds = [];
    var env = _.clone(e);
    env.knownIds = _.union(postal.fedx.knownIds, e.knownIds);
    env.originId = postal.instanceId;
    var payload = _.extend({ envelope: env }, postal.fedx.getFedxWrapper("subscription.created"));
    postal.fedx.send(payload, e.knownIds);
  }
});

postal

Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis