TopazSigGem.js

import SignatureTablet from './SignatureTablet.js'
import { BASE_URL, DEPRECATION_02 } from './Common.js'

/**
 * TopazSigGem
 * @classdesc Class for communicating with a Topaz SigGem Signature Tablet.
 * Inherits all methods on the {@link SignatureTablet} class.
 * @extends SignatureTablet
 * @see {@link SignatureTablet}
 */
class TopazSigGem extends SignatureTablet {
  /**
   * Instantiate a Topaz SigGem Signature Tablet
   * @constructor
   * @param {string} [baseURL] - Protocol, domain, and port for the service.
   * @example
   * const tablet = new TopazSigGem()
   *
   */
  constructor (baseUrl = BASE_URL) {
    super('capture_signature_topaz', baseUrl)
  }

  /**
   * Render an Array of SignatureTabletWidgets and wait for user to click one.
   *
   * @description If any of the provided widgets are Buttons, the method will
   * wait for one to be clicked and will then return the ID of the clicked
   * widget.
   *
   * @param {Object[]} widgets An array of SignatureTabletWidgets to display.
   * @param {Object} [sceneOpt] Options for configuring the scene.
   * @param {boolean} [sceneOpt.clear=true] If `true`, the display will be
   * cleared before adding the Objects.
   * @param {Object} [sceneOpt.backlight=true] If `true`, the backlight will be
   * enabled before adding the Objects.
   *
   * @async
   * @method
   * @returns {string?} ID of the clicked widget (if any Buttons were provided)
   * @example
   * const result = await tablet.displayObjects([
   *  new TextButton("OK", 20, 200),
   *  new TextButton("Cancel", 80, 200)
   * ], {clear: false})
   *
   * console.log(`ID: ${result} was clicked`)
   */
  async displayObjects (objects, sceneOpt = { clear: true, backlight: true }, deviceOpt) {
    const device = await this.setupDevice(deviceOpt)
    if (typeof sceneOpt === 'boolean' && DEPRECATION_02) {
      const clear = sceneOpt
      sceneOpt = { clear, backlight: true }
      console.warn('CaptureBridge SDK Deprecation Warning: ' +
        '`TopazSigGem.displayObjects()` converted the `sceneOpt` argument ' +
        'from a boolean (%s) to an object (%s). This conversion may not be ' +
        'performed in future SDK versions.',
      clear, JSON.stringify(sceneOpt))
    } else {
      sceneOpt = Object.assign({ clear: true, backlight: true }, sceneOpt)
    }

    const { clicked } = await device.displayObjects(objects, sceneOpt)
    return clicked
  }

  /**
   * Get detailed information about a specific tablet
   *
   * @description Returns detailed information about a tablet.
   *
   * @async
   * @method
   * @returns {object} Device info
   * @example
   * const info = await device.info()
   */
  async info (deviceOpt) {
    const device = await this.setupDevice(deviceOpt)
    return device.info()
  }
}

export default TopazSigGem