Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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);
}
}
},
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 ) {
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){
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 ) );
}
}
callback : function(data, env) {
env = _.clone(env);
env.originId = postal.instanceId;
self.clients[id].send(_.extend({
envelope: env
}, self.getFedxWrapper("message")));
}
});
getFedxWrapper: function(type) {
return {
postal : true,
type : type,
instanceId : postal.instanceId
}
},
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;
}
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);
}
});