Camera.js

import StreamingCapturePlugin from './StreamingCapturePlugin.js'
import {
  BASE_URL,
  DEFAULT_CAPTURE_OPT,
  DEPRECATION_01
} from './Common.js'

/**
 * Camera
 * @classdesc Class for invoking methods on a Camera
 * @extends StreamingCapturePlugin
 * @see {@link CanonCamera}
 */
class Camera extends StreamingCapturePlugin {
  /**
   * Instantiate a Generic Camera
   * @constructor
   * @param {string} pluginId - The Id of the desired plugin to use for this
   * camera instance. The plugin must support the `start_feed`, `stop_feed`,
   * `devices`, and `capture` methods.
   * @param {string} [baseURL] - Protocol, domain, and port for the service.
   * @example
   * const camera = new Camera('capture_camera_canon')
   */
  constructor (pluginId, baseUrl = BASE_URL) {
    super(pluginId, baseUrl)
  }

  /**
   * Capture a photo
   * @param {CaptureOptions} [captureOpt] - Additional options for capturing a
   * photo.
   * @param {string|object} [deviceOpt] - Take the photo using either a specific
   * Device ID or a Device Object. The default is the first available device.
   *
   * @async
   * @example
   * // Capture a photo as an ObjectURL, add it to an img element and append to
   * // the document's body.
   * const img = document.createElement('img')
   * img.src = await camera.takePhoto()
   * document.body.appendChild(img)
   */
  async takePhoto (captureOpt = {}, deviceOpt) {
    if (typeof captureOpt === 'string' && DEPRECATION_01) {
      captureOpt = { kind: captureOpt }
      console.warn('CaptureBridge SDK Deprecation Warning: ' +
        '`Camera.takePhoto()` converted the `captureOpt` argument from a ' +
        'string (%s) to an object (%s). This conversion may not be performed ' +
        'in future SDK versions.',
      captureOpt.kind, JSON.stringify(captureOpt))
    }
    const mergedOpt = Object.assign({}, DEFAULT_CAPTURE_OPT, captureOpt)
    return await this.fullCapture(mergedOpt, deviceOpt)
  }
}

export default Camera