Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
goog.require('goog.Uri');
goog.require('goog.events');
goog.require('goog.json');
goog.require('goog.net.xpc.CrossPageChannel');
goog.global.initOuter = function(url) {
goog.events.listen(window, 'load', function() { xpcdemo.initOuter(url); });
};
goog.global.initInner = function() {
goog.events.listen(window, 'load', function() { xpcdemo.initInner(); });
};
var xpcdemo = {};
xpcdemo.initOuter = function(url) {
var config = {};
config[goog.net.xpc.CfgFields.PEER_URI] = url;
xpcdemo.channel = new goog.net.xpc.CrossPageChannel(config);
var echoService = function(payload) {
alert('I heard: ' + payload);
};
xpcdemo.channel.registerService('echo', echoService);
var iframeParent = document.body;
var configureIframe = function(iframe) { iframe.style.display = 'none'; };
xpcdemo.channel.createPeerIframe(iframeParent, configureIframe);
xpcdemo.channel.connect(function() {
alert('The parent is connected to the channel!');
xpcdemo.channel.send('echoBack', 'Hello world from Parent!');
});
};
xpcdemo.initInner = function() {
var xpc = (new goog.Uri(window.location.href)).getParameterValue('xpc');
if (xpc) {
var config = goog.json.parse(xpc);
var childChannel = new goog.net.xpc.CrossPageChannel(config);
var connectCallback = function() {
childChannel.send('echo', 'Hello world from Child!');
}, 1000);
};
childChannel.connect(connectCallback);
var echoBack = function(payload) {
alert("I received payload: " + payload);
}
childChannel.registerService('echoBack', echoBack);
} else {
alert('No xpc parameter provided!');
}
};
xpcdemo.push = function(url, payload) {
xpcdemo.channel.send('echoBack', 'Hello world from Parent!' + payload);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.