47 lines
No EOL
1.4 KiB
JavaScript
47 lines
No EOL
1.4 KiB
JavaScript
/*
|
|
Echoer
|
|
Created by Zach Fox on 2019-10-28
|
|
Copyright 2019 High Fidelity, Inc.
|
|
|
|
Distributed under the Apache License, Version 2.0.
|
|
See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
*/
|
|
|
|
/* globals document EventBridge setTimeout */
|
|
|
|
// Handle EventBridge messages.
|
|
function onScriptEventReceived(message) {
|
|
try {
|
|
message = JSON.parse(message);
|
|
} catch (error) {
|
|
console.log("Couldn't parse script event message: " + error);
|
|
return;
|
|
}
|
|
|
|
switch (message.method) {
|
|
default:
|
|
console.log("Message received from echoer_ui.html: " + JSON.stringify(message));
|
|
console.log("Emitting 'messageReceived' event via `EventBridge.emitWebEvent()`...");
|
|
EventBridge.emitWebEvent(JSON.stringify({
|
|
app: "echoer",
|
|
method: "messageReceived",
|
|
message: JSON.stringify(message)
|
|
}));
|
|
break;
|
|
}
|
|
}
|
|
|
|
// This delay is necessary to allow for the JS EventBridge to become active.
|
|
// The delay is still necessary for HTML apps in RC78+.
|
|
var EVENTBRIDGE_SETUP_DELAY = 500;
|
|
function onLoad() {
|
|
setTimeout(function() {
|
|
EventBridge.scriptEventReceived.connect(onScriptEventReceived);
|
|
EventBridge.emitWebEvent(JSON.stringify({
|
|
app: "echoer",
|
|
method: "eventBridgeReady"
|
|
}));
|
|
}, EVENTBRIDGE_SETUP_DELAY);
|
|
}
|
|
|
|
onLoad(); |