"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var _exportNames = {
  RfidBleEvent: true,
  AUTO_SCAN_DEFAULT_DURATION: true
};
exports.default = exports.AUTO_SCAN_DEFAULT_DURATION = exports.RfidBleEvent = void 0;

var _reactNative = require("react-native");

var _NativeModule = require("./NativeModule");

Object.keys(_NativeModule).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
  if (key in exports && exports[key] === _NativeModule[key]) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function () {
      return _NativeModule[key];
    }
  });
});

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

const EVENT_PREFIX = 'RFID_BLE';

const eventWithPrefix = eventName => `${EVENT_PREFIX}:${eventName}`;

const RfidBleEvent = {
  DEBUG: eventWithPrefix('DEBUG'),
  START_SCANNING: eventWithPrefix('START_SCANNING'),
  STOP_SCANNING: eventWithPrefix('STOP_SCANNING'),
  READER_RECEIVED: eventWithPrefix('READER_RECEIVED'),
  READER_CONNECTED: eventWithPrefix('READER_CONNECTED'),
  READER_DISCONNECTED: eventWithPrefix('READER_DISCONNECTED'),
  EPC_REPLIES_READ: eventWithPrefix('EPC_REPLIES_READ')
};
exports.RfidBleEvent = RfidBleEvent;
const AUTO_SCAN_DEFAULT_DURATION = 6000; // in ms

exports.AUTO_SCAN_DEFAULT_DURATION = AUTO_SCAN_DEFAULT_DURATION;

class RfidBle extends _reactNative.NativeEventEmitter {
  constructor(__nativeModule) {
    super();
    this.__nativeModule = __nativeModule;

    _defineProperty(this, "__autoScanTimeoutID", null);
  }

  requestEnabled() {
    return this.__nativeModule.requestEnabled();
  }

  autoScan(duration = AUTO_SCAN_DEFAULT_DURATION) {
    this.__autoScanTimeoutID = setTimeout(this.stopScan.bind(this), duration);
    return this.startScan();
  }

  startScan() {
    return this.__nativeModule.startScan();
  }

  stopScan() {
    clearTimeout(this.__autoScanTimeoutID);
    return this.__nativeModule.stopScan();
  }

  connectToReader(readerAddress) {
    return this.__nativeModule.connectToReader(readerAddress);
  }

  disconnect() {
    return this.__nativeModule.disconnect();
  }

  on(eventType, listener) {
    return super.addListener(eventType, listener);
  }

}

var _default = new RfidBle(_NativeModule.RfidBleNative);

exports.default = _default;
//# sourceMappingURL=index.js.map