content/hifi-content/caitlyn/scratch/eventBridgeTest/old/eventBridge.js
2022-02-13 22:19:19 +01:00

53 lines
No EOL
1.5 KiB
JavaScript

(function () {
var WINDOW_URL = "http://hifi-content.s3.amazonaws.com/caitlyn/dev/scratch/UnityUIs/index.html"; // URL to the unity based webapp
var ExternalWebApp_ = {};
ExternalWebApp_.init = function () {
};
ExternalWebApp_.destroy = function () {
};
var main = function () {
ExternalWebApp_.init();
var externalWebApp_WindowListener = {};
externalWebApp_WindowListener.onLoad = function (event) {
print("loaded" + event.value);
if (!event.hasOwnProperty("value")){
return;
}
};
var externalWebApp_Window = new OverlayWebWindow({ // Create and load the web app
title: 'My External Web App',
source: WINDOW_URL,
width: 768,
height: 1024,
visible: true
});
// Insert custom events here:
externalWebApp_WindowListener.onEchoMessage = function (event) {
print("CM: Echo event! "+event.value);
}
externalWebApp_Window.webEventReceived.connect(function (data) { // Received JSON data
var event = JSON.parse(data);
if (externalWebApp_WindowListener[event.type]) {
externalWebApp_WindowListener[event.type](event);
print("CM: Received message: "+event.value);
}
});
};
main();
function cleanup() {
ExternalWebApp_.destroy();
}
Script.scriptEnding.connect(cleanup);
}());