Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Often you will need to get information from the GumbandSDK and in order to do this the SDK will need to be ready for you to use its methods and properties. This article will help you understand the ways you can discern if the SDK is ready to interaction/drive your exhibit.

Using a Singleton

First, we are going to assume you have followed the “Best Practice: Wrapping Gumband SDK as A Singleton Class”. With this pattern you have ensured that no matter where or when you “new-up” your GumbandService class you will get the same object in-memory.

Once you have a reference to the singleton you can identify if an Exhibit is ready in 2 different ways.

Using an Observer Pattern to listen for READY events

The SDK emits READY from it’s event emitter once all health checks have been performed. You can listen for this event within your singleton in this manner:

// FILE: your-gumband-project/gumband/gumband-service-wrapper.js
const { Gumband, Sockets } = require("@deeplocal/gumband-node-sdk");

/**
 * A class that wraps the Gumband SDK and handles websocket messages 
 * that come from the Gumband Cloud.
 */
class GumbandService {
    /**
     * A reference to the Gumband SDK instance.
     */
    gumbandSDK;

    // Static Variable to hold the singleton instance
    static instance;
    
    constructor(window) {
        if(GumbandService.instance) {
          return GumbandService.instance;
        }   
        this.gumbandSDK = new Gumband(...constructorArgs);
        this.addSDKListeners();
        Gumband.instance = this.
    }

    /**
     * Add listeners to the Gumband SDK to handle messages from the Gumband Cloud.
     */
    addSDKListeners() {
        this.gumbandSDK.on(Sockets.READY, async (manifest) => {
          // Call whatever you need to happen once the exhibit is ready.
        })
    }
}

module.exports = { GumbandService };

Use the isReady() Method

If you prefer to procedurally check if the SDK is ready there is a method to check the internal flag (the same internal flag that will be set on the above emitted event).

Building on the snippet above, lets assume you are using your gumband service in an arbitrary location of your code.

// FILE: your-gumband-project/app/main.js
const { GumbandService } = require('../gumband/gumband-service-wrapper')

const gb = new GumbandService() // 👈 Get reference to the singleton

if (gb.gumbandSDK.isReady()) {
  console.log('Gumband SDK is ready for operation')
} else {
  console.log('Gumband SDK is not yet ready, check later, or listen for READY event')
}

Additional Notes

Intermittent Connection

If the exhibit disconnects we emit a EXHIBIT_OFFLINE event. Listening to this will let you know you lost connection. However after a short period of time the exhibit will automatically begin trying authenticate & reconnect at a set interval. If it fails it will emit ERROR and then queue another attempt, if authentication & reconnection succeeds then the SDK will emit "READY" again.

  • No labels