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

« Previous Version 2 Current »

Often you will need to get information from the Gumband Cloud through the Gumband SDK, and in order to do this the SDK will first need to authenticate itself with the Gumband Cloud. Until authentication is complete, the SDK will be marked as “not ready”. This article will help you understand the two ways you can discern if the SDK is ready to get settings, dispatch metric events, etc.

Using an Observer Pattern to listen for READY events

The SDK emits READY from its event emitter once it has successfully authenticated with the Gumband Cloud and a websocket connection has been established. You can listen for this event 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();

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 an EXHIBIT_OFFLINE event. Listening to this will let you know you lost connection. However after a short period of time the Gumband SDK will automatically begin trying to 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