Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fixed or-app startup procedure

Christian Bauerd16fa79c3b9c
diff --git a/client/src/main/webapp/src/or-app/or-app.html b/client/src/main/webapp/src/or-app/or-app.html
index 34e99560e..8be619a74 100644
--- a/client/src/main/webapp/src/or-app/or-app.html
+++ b/client/src/main/webapp/src/or-app/or-app.html
@@ -106,7 +106,7 @@
* 1a. If authentication is required, perform authentication, then fire AppInit.
* 1b. If no authentication is required, fire AppInit.
*
- * 2. Any element registered with defineAppElement() will be set in the openremote namespace
+ * 2. Any element registered with defineAppElement() will be set in the 'openremote' namespace
* so its class is available in GWT jsinterop.
*
* 3. The GWT jsinterop components will be loaded, then fire AppLoaded.
@@ -453,7 +453,7 @@
this.set("requests", requests);
}
- connectEvents() {
+ connectEvents(onConnected) {
// Only authenticated apps can connect to the event service
if (!this.login) {
return;
@@ -481,6 +481,10 @@
console.log("Page unloaded, closing event service connection");
this.disconnectEvents();
});
+
+ if (onConnected) {
+ onConnected()
+ }
};
this.webSocket.onerror = () => {
@@ -576,21 +580,29 @@
openremote.INSTANCE.registerToasts();
openremote.INSTANCE.registerRequests();
- // Connect the WebSocket to event service endpoint
- openremote.INSTANCE.connectEvents();
-
- // Load the authenticated tenant details
- openremote.INSTANCE.loadTenantDetails(() => {
-
+ // Run this when everything is ready
+ let appReady = () => {
// Check if there was a problem
if (!openremote.INSTANCE.error) {
// If not, any other code can run and we are ready
+ console.log("Application ready");
dispatchEvent(new CustomEvent("AppReady", {detail: {app: openremote.INSTANCE}}));
}
-
// Now show the app/document body
openremote.INSTANCE.showApp();
- })
+ };
+
+ // If login is required, must be able to connect WebSocket and load tenant
+ if (openremote.INSTANCE.login) {
+ // Connect the WebSocket to event service endpoint
+ openremote.INSTANCE.connectEvents(() => {
+ // Load the authenticated tenant details
+ openremote.INSTANCE.loadTenantDetails(appReady);
+ });
+ } else {
+ // If no login is required, just start
+ appReady();
+ }
});
// Elements which depend on jsinterop components must be initialized at the right time