I've found a solution that works for me. I've published a website with two PlayCanvas "Apps" on it and interacting via script with both of them.
The solution recommend to keep the PlayCanvas applications in an iframe
. So you can host the app yourself or let PlayCanvas do this for you. Another advantage is that you don't have to change anything in our exported project.
So the HTML part is very simple:
<div id="app1-wrapper">
<iframe id="app1-iframe" src="myApp1/index.html" frameborder="0"></iframe>
</div>
<div id="app2-wrapper">
<iframe id="app2-iframe" src="myApp2/index.html" frameborder="0"></iframe>
</div>
In a JavaScript I get the apps from both iframes
and save them in a variable:
var app1_iframe = document.getElementById("app1-iframe").contentWindow;
var app1 = app1_iframe.pc.Application.getApplication("application-canvas");
var app2_iframe = document.getElementById("app2-iframe").contentWindow;
var app2 = app2_iframe.pc.Application.getApplication("application-canvas");
Now you've got access to the app and you can run all functions. For me, I'm firing events to my scripts. Keep in mind that you have to create the listeners for them in your PlayCanvas app.
app1.fire('myFunctionName',value);
app2.fire('myFunctionName',value);
And that's it! Very simple and very flexible in my opinion!