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; }

import { NativeEventEmitter } from 'react-native';
import { RfidBleNative } from './NativeModule';
export * from './NativeModule';
const EVENT_PREFIX = 'RFID_BLE';

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

export 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')
};
export const AUTO_SCAN_DEFAULT_DURATION = 6000; // in ms

class RfidBle extends 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);
  }

}

export default new RfidBle(RfidBleNative);
//# sourceMappingURL=index.js.map