I am trying to use two easyXDM sockets on a single parent page without success. Both the sockets connect to the same remote domain but different endpoints. The parent page has two divs false_app_div
and dummy_app_div
.The following shows the code snippets -
On the parent page I have two JS functions activate_false_app()
and activate_dummy_app()
.
window.loadScript = function(src, onload, onerror) {
var head = document.getElementByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
if (script.readyState) {
script.onreadystate = function() {
var state = this.state;
if (state === 'loaded' || state === 'complete') {
script.onreadystate = null;
onload();
}
};
}
};
window.activate_false_app = function() {
var exdm_url = 'http://localhost:8000/js/easyXDM/easyXDM.min.js';
on_load_fn = function() {
window.init_false_app_communication();
};
on_error_fn = function() {
return false;
};
window.loadScript(exdm_url, on_load_fn, on_error_fn);
};
window.init_false_app_communication = function() {
var false_app_socket = new easyXDM.Socket({
remote : 'http://localhost:8000/false_app',
swf : 'http://localhost:8000/js/easyXDM/easyXDM.swf',
container : 'false_ap_div',
onMessage : function(message, origin) {
alert('false_app onMessage');
alert(message);
}
});
};
window.activate_dummy_app = function() {
var exdm_url = 'http://localhost:8000/js/easyXDM/easyXDM.min.js';
on_load_fn = function() {
window.init_dummy_app_communication();
};
on_error_fn = function() {
return false;
};
window.loadScript(exdm_url, on_load_fn, on_error_fn);
};
window.init_dummy_app_communication = function() {
var dummy_app_socket = new easyXDM.Socket({
remote : 'http://localhost:8000/dummy_app',
swf : 'http://localhost:8000/js/easyXDM/easyXDM.swf',
container : 'dummy_app_div',
onMessage : function(message, origin) {
alert('dummy_app onMessage');
alert(message);
};
});
};
If in the parent page, I call either activate_dummy_app()
or activate_false_app()
, it works - that is both work completely fine in isolation. But if I call both, then only one of them works and I get an error on the JS console, that something is undefined (which I could not find).
Also, I know that the problem has something to do with loading two easyXDMs because if I put init_dummy_app_communication
in the on_load_fn
of activate_false_app()
(in addition to init_false_app_communication
already present), then both works.
However, I cannot be sure that easyXDM is already loaded, so both activate_false_app
and activate_dummy_app
has to load easyXDM, so that they work in isolation as well as together. I tried working with noConflict
function, but the documentation there is poor and ended up with nothing concrete there.
Has someone faced a similar problem or knows what I am missing here?