How to use the postal.fedx 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 / src / index.js View on Github external
import _ from "lodash";
import postal from "postal";
import "./postal-utils";
import { packingSlips, getPackingSlip } from "./packingSlips";
import { state, disconnect, NO_OP, configure } from "./state";
import { handlers, onFederatedMsg } from "./handlers";
import filters, { matchesFilter, addFilter, removeFilter } from "./filters";
import FederationClient from "./FederationClient";

const fedx = postal.fedx = {
	FederationClient: FederationClient,
	packingSlips: packingSlips,
	handlers: handlers,
	clients: state._clients,
	transports: state._transports,
	filters,
	addFilter,
	removeFilter,
	canSendRemote: function( channel, topic ) {
		return matchesFilter( channel, topic, "out" );
	},
	configure: configure,
	getPackingSlip,
	onFederatedMsg: onFederatedMsg,
	sendMessage: function( envelope ) {
		if ( !state._ready ) {
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
if(!subs[channel][topic]) {
      subs[channel][topic] = postal.subscribe({
        channel  : channel,
        topic    : topic,
        callback : function(data, env) {
          env = _.clone(env);
          env.originId = postal.instanceId;
          self.clients[id].send(_.extend({
            envelope: env
          }, self.getFedxWrapper("message")));
        }
      });
    }
  }

}, postal.fedx);

postal.subscribe({
  channel  : postal.configuration.SYSTEM_CHANNEL,
  topic    : "subscription.created",
  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);
github postaljs / postal.federation / lib / node / postal.federation.js View on Github external
callback : function(d, e) {
    var subs = postal.fedx.clients[e.originId].subscriptions;
    if(subs[d.channel] && subs[d.channel][d.topic]) {
      postal.fedx._processingIds = e.knownIds;
      subs[d.channel][d.topic].unsubscribe();
      postal.fedx._processingIds = [];
    }
  }
});
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){

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