import CapturePlugin from './CapturePlugin.js'
import { BASE_URL, DEFAULT_CAPTURE_OPT, DEPRECATION_01 } from './Common.js'
/**
* Scanner
* @classdesc Class for invoking methods on a Scanner
*
* @see {@link CanonScanner}
*/
class Scanner extends CapturePlugin {
/**
* Instantiate a Generic Scanner
* @constructor
* @param {string} [baseURL] - Protocol, domain, and port for the service.
* @param {string} pluginId - The Id of the desired plugin to use for this
* scanner instance. The plugin must support the "devices", and "capture"
* methods.
* @example
* const scanner = new Scanner('capture_scanner_windows')
*/
constructor (plugin, baseUrl = BASE_URL) {
super(plugin, baseUrl)
}
/**
* Scan a document
*
* @param {CaptureOptions} [captureOpt] - Additional options for capturing a
* signature.
*
* @param {string|object} [deviceOpt] - Can a document using either a specific
* Device ID or a Device Object. The default is the first available device.
*
* @async
* @example
* // Scan document as an ArrayBuffer and add it to an img tag appended to
* // the document's body.
* const img = document.createElement('img')
* img.src = await scanner.scan()
* document.body.appendChild(img)
*/
async scan (captureOpt = {}, deviceOpt) {
if (typeof captureOpt === 'string' && DEPRECATION_01) {
captureOpt = { kind: captureOpt }
console.warn('CaptureBridge SDK Deprecation Warning: `Scanner.scan()` ' +
'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 Scanner