-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 68449b3
Showing
29 changed files
with
19,997 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
desktop.ini | ||
.eprj | ||
.idea | ||
.anvil | ||
*node_modules* | ||
*npm-debug* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
This project is available under a dual license of MIT or GPL v2.0 | ||
|
||
Copyright (c) 2012 Jim Cowart (MIT License) | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
See the MIT License for more details: http://opensource.org/licenses/MIT | ||
|
||
-------------------------------------------------------------------- | ||
|
||
Copyright (C) 2012 Jim Cowart (GPL v2.0 License) | ||
|
||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or (at | ||
your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. | ||
|
||
See the GNU General Public License for more details: | ||
http://opensource.org/licenses/GPL-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This is not ready for you to use yet. Really. | ||
|
||
## Check back in a couple of weeks - or follow this project on github to see when we give it a real version! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"anvil.uglify" : { | ||
"all": true | ||
}, | ||
"anvil.http" : { | ||
"paths" : { | ||
"/" : "./" | ||
} | ||
}, | ||
"output": { | ||
"full": "lib", | ||
"partial": { | ||
"/*" : [ "./example/client/js", "./example" ] | ||
} | ||
}, | ||
"dependencies" : [ "anvil.http", "anvil.uglify" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name" : "postal.socketio", | ||
"version" : "0.0.0", | ||
"main" : ["lib/postal.socketio.js"], | ||
"dependencies": { | ||
"underscore" : "~1.1.7", | ||
"postal.js" : "~0.7.3", | ||
"postal.federation" : "~0.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<base href="/"> | ||
<title>postal.socketio playground</title> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script type="text/javascript" src="js/underscore.js"></script> | ||
<script type="text/javascript" src="js/postal.js"></script> | ||
<script type="text/javascript" src="js/postal.federation.js"></script> | ||
<script type="text/javascript" src="js/postal.socketio.js"></script> | ||
<script type="text/javascript" src="js/main.js"></script> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
postal.instanceId = "browser-client-123"; | ||
|
||
postal.addWireTap(function(d, e) { | ||
console.log("ID: " + postal.instanceId + " " + JSON.stringify(e, null, 4)); | ||
}); | ||
|
||
window.__socket = io.connect(window.location.origin); | ||
|
||
postal.fedx.transports.socketio.signalReady(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/* | ||
postal.federation | ||
Copyright (C) 2012 - Jim Cowart (http://freshbrewedcode.com/jimcowart) | ||
License: Dual licensed MIT & GPL v2.0 | ||
Version 0.1.0 | ||
*/ | ||
(function ( root, factory ) { | ||
if ( typeof module === "object" && module.exports ) { | ||
// Node, or CommonJS-Like environments | ||
module.exports = factory( require( "underscore" ), require( "postal" ) ); | ||
} else if ( typeof define === "function" && define.amd ) { | ||
// AMD. Register as an anonymous module. | ||
define( ["underscore", "postal"], function ( _, postal ) { | ||
return factory( _, postal, root ); | ||
} ); | ||
} else { | ||
// Browser globals | ||
root.postal = factory( root._, root.postal, root ); | ||
} | ||
}( this, function ( _, postal, global, undefined ) { | ||
|
||
var _defaults = { | ||
enabled : true, | ||
constraintMode : 'blacklist', | ||
bridgeSysChannel : true | ||
}; | ||
var _config = _defaults; | ||
|
||
var FederationClient = function(id) { | ||
this.id = id; | ||
this.activeTransport = undefined; | ||
}; | ||
|
||
FederationClient.prototype.send = function(envelope, transport) { | ||
transport = transport || this.activeTransport; | ||
if(transport) { | ||
this[transport].send(envelope); | ||
} | ||
}; | ||
|
||
postal.fedx = _.extend({ | ||
|
||
clients: {}, | ||
|
||
transports: {}, | ||
|
||
constraints: {}, | ||
|
||
FederationClient: FederationClient, | ||
|
||
addClient: function(transportClient, type) { | ||
var _client = this.clients[transportClient.instanceId] || (this.clients[transportClient.instanceId] = new FederationClient(transportClient.instanceId)); | ||
transportClient.attachToClient(_client); | ||
_client.activeTransport = _client.activeTransport || type; | ||
}, | ||
|
||
addConstraint: function(channel, topic) { | ||
if(!this.constraints[channel]) { | ||
this.constraints[channel] = [ topic ]; | ||
} else if(!(_.include(this.constraints[channel], topic))) { | ||
this.constraints[channel].push(topic); | ||
} | ||
}, | ||
|
||
removeConstraint: function(channel, topic) { | ||
if(this.constraints[channel] && _.include(this.constraints[channel], topic)) { | ||
this.constraints[channel] = _.without(this.constraints[channel], topic); | ||
} | ||
}, | ||
|
||
canSendRemote: function(channel, topic) { | ||
var channelPresent = this.constraints.hasOwnProperty(channel); | ||
var topicMatch = (channelPresent && _.any(this.constraints[channel], function(binding){ | ||
return postal.configuration.resolver.compare(binding, topic); | ||
})); | ||
var blacklisting = _config.constraintMode === 'blacklist'; | ||
var sysChannelOK = ((!_config.bridgeSysChannel && channel !== postal.configuration.SYSTEM_CHANNEL) || _config.bridgeSysChannel); | ||
|
||
return _config.enabled && sysChannelOK && | ||
( | ||
(blacklisting && (!channelPresent || (channelPresent && !topicMatch))) || | ||
(!blacklisting && channelPresent && topicMatch) | ||
); | ||
}, | ||
|
||
configure: function(cfg) { | ||
if(cfg.constraintMode && cfg.constraintMode !== 'blacklist' && cfg.mode !== 'whitelist') { | ||
throw new Error("postal.fedx constraintMode must be 'blacklist' or 'whitelist'."); | ||
} | ||
if(cfg){ | ||
_config = _.defaults(cfg, _defaults); | ||
} | ||
return _config; | ||
}, | ||
|
||
onFederatedMsg: function(envelope, senderId) { | ||
envelope.lastSender = senderId; | ||
postal.publish(envelope); | ||
}, | ||
|
||
send : function(envelope) { | ||
envelope.originId = envelope.originId || postal.instanceId; | ||
_.each(this.clients, function(client, id) { | ||
var env = _.clone(envelope); | ||
if(id !== env.lastSender && | ||
( !env.knownIds || | ||
!env.knownIds.length || | ||
(env.knownIds && !_.include(env.knownIds, id))) | ||
) { | ||
env.knownIds = (env.knownIds || []).concat(_.without(_.keys(this.clients), id)); | ||
client.send(env); | ||
} | ||
}, this); | ||
}, | ||
|
||
signalReady: function(transportName) { | ||
if(transportName) { | ||
this.transports[transportName].signalReady(); | ||
} else { | ||
_.each(this.transports, function(transport) { | ||
transport.signalReady(); | ||
}, this); | ||
} | ||
} | ||
|
||
}, postal.fedx); | ||
|
||
postal.addWireTap(function(data, envelope){ | ||
if(postal.fedx.canSendRemote(envelope.channel, envelope.topic)) { | ||
postal.fedx.send(envelope); | ||
} | ||
}); | ||
|
||
return postal; | ||
|
||
} )); |
Oops, something went wrong.