Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ desktop.ini
.anvil
*node_modules*
*npm-debug*
/.settings
/.project
42 changes: 33 additions & 9 deletions example/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
<script type="text/javascript" src="../lib/postal.federation.js"></script>
<script type="text/javascript" src="../ext/postal.xframe.js"></script>
<script type="text/javascript">
postal.instanceId("iframe1");
postal.fedx.addFilter([
{ channel: 'postal', topic: '#', direction: 'in' },
{ channel: 'iframez', topic: '#', direction: 'in' },
{ channel: 'parentz', topic: '#', direction: 'out' }
]);
postal.instanceId(postal.utils.createUUID());


postal.addWireTap(function(d, e) {
console.log("ID: " + postal.instanceId() + " - " + JSON.stringify(e, null, 4));
if(console && console.log){console.log( "ID: " + postal.instanceId() + " " + JSON.stringify( e, null, 4 ) );}
//console.debug( "ID: " + postal.instanceId() ,JSON.stringify( e, null, 4 ) );
});
postal.subscribe({
channel: "iframez",
Expand All @@ -26,6 +24,13 @@
$("#msgs").append("<div><pre>" + JSON.stringify(e, null, 4) + "</pre></div>");
}
});
postal.subscribe({
channel: "postal",
topic: "#",
callback: function(d, e) {
$("#msgs").append("<div><pre>" + JSON.stringify(e, null, 4) + "</pre></div>");
}
});

$(function() {

Expand All @@ -37,17 +42,36 @@
});
});
$("#msg3").on('click', function(){
postal.publish({
channel: "postal",
topic: "some.topic",
data: "This message will appear in all"
});
});
$("#msg4").on('click', function(){
postal.fedx.disconnect();
});

postal.fedx.signalReady();
postal.publish({
channel: "postal",
topic: "not yet there",
data: "This message will appear in all"
});
postal.fedx.signalReady(function(){
postal.publish({
channel: "postal",
topic: "yeah i am there",
data: "This message will appear in all"
});
});
});
</script>
</head>
<body>
<div>
<input type="button" value="Send Msg" id="msg2">
<input type="button" value="Disconnect" id="msg3">
<input type="button" value="Send Broadcast Msg" id="msg3">
<input type="button" value="Disconnect" id="msg4">
</div>
<div id="msgs"></div>
</body>
Expand Down
27 changes: 23 additions & 4 deletions example/iframe2.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
<script type="text/javascript" src="../lib/postal.federation.js"></script>
<script type="text/javascript" src="../ext/postal.xframe.js"></script>
<script type="text/javascript">
postal.instanceId("iframe2");
postal.instanceId("iframe2", {allowInstanceIdUpdates : false});
postal.fedx.addFilter([
{ channel: 'postal', topic: '#', direction: 'in' },
{ channel: 'postal', topic: '#', direction: 'both' },
{ channel: 'iframez', topic: '#', direction: 'in' },
{ channel: 'parentz', topic: '#', direction: 'out' }
]);
postal.fedx.restrictRemoteConfig = function (data){
return true;
}
postal.addWireTap(function(d, e) {
console.log("ID: " + postal.instanceId() + " - " + JSON.stringify(e, null, 4));
if(console && console.log){console.log( "ID: " + postal.instanceId() + " " + JSON.stringify( e, null, 4 ) );}
//console.debug( "ID: " + postal.instanceId() , JSON.stringify( e, null, 4 ) );
});
postal.subscribe({
channel: "iframez",
Expand All @@ -26,6 +30,13 @@
$("#msgs").append("<div><pre>" + JSON.stringify(e, null, 4) + "</pre></div>");
}
});
postal.subscribe({
channel: "postal",
topic: "#",
callback: function(d, e) {
$("#msgs").append("<div><pre>" + JSON.stringify(e, null, 4) + "</pre></div>");
}
});

$(function() {

Expand All @@ -37,6 +48,13 @@
});
});
$("#msg3").on('click', function(){
postal.publish({
channel: "postal",
topic: "some.topic",
data: "This message will appear in all"
});
});
$("#msg4").on('click', function(){
postal.fedx.disconnect();
});

Expand All @@ -47,7 +65,8 @@
<body>
<div>
<input type="button" value="Send Msg" id="msg2">
<input type="button" value="Disconnect" id="msg3">
<input type="button" value="Send Broadcast Msg" id="msg3">
<input type="button" value="Disconnect" id="msg4">
</div>
<div id="msgs"></div>
</body>
Expand Down
24 changes: 21 additions & 3 deletions example/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
postal.instanceId( "parent" );

postal.fedx.addFilter( [
{ channel : 'postal', topic : '#', direction : 'out' },
{ channel : 'postal', topic : '#', direction : 'both' },
{ channel : 'iframez', topic : '#', direction : 'out' },
{ channel : 'parentz', topic : '#', direction : 'in' }
] );
postal.fedx.onFederation = function(data){
return {
instanceId : data.source.instanceId + "_ParentDefined",
filters : [
{ channel : 'postal', topic : '#', direction : 'both' },
{ channel : 'iframez', topic : '#', direction : 'out' },
{ channel : 'parentz', topic : '#', direction : 'in' }
]
};
};
postal.addWireTap( function ( d, e ) {
console.log( "ID: " + postal.instanceId() + " " + JSON.stringify( e, null, 4 ) );
if(console && console.log){console.log( "ID: " + postal.instanceId() + " " + JSON.stringify( e, null, 4 ) );}
//console.debug( "ID: " + postal.instanceId() ,JSON.stringify( e, null, 4 ) );
} );

$( function () {
Expand All @@ -20,6 +31,13 @@ $( function () {
$( "#msgs" ).append( "<div><pre>" + JSON.stringify( e, null, 4 ) + "</pre></div>" );
}
} );
postal.subscribe( {
channel : "postal",
topic : "#",
callback : function ( d, e ) {
$( "#msgs" ).append( "<div><pre>" + JSON.stringify( e, null, 4 ) + "</pre></div>" );
}
} );

$( "#msg1" ).on( 'click', function () {
postal.publish( {
Expand All @@ -43,4 +61,4 @@ $( function () {
} );
} );

} );
} );
Loading