"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.MonitorView = exports.Monitor = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
const Commands = {
  setVideoFlip: 'setVideoFlip',
  startMonitor: 'startMonitor',
  pauseMonitor: 'pauseMonitor',
  replayMonitor: 'replayMonitor',
  stopMonitor: 'stopMonitor',
  destroyMonitor: 'destroyMonitor',
  captureImage: 'captureImage',
  startVideoRecord: 'startVideoRecord',
  stopVideoRecord: 'stopVideoRecord',
  openVoice: 'openVoice',
  closeVoice: 'closeVoice',
  setSpeakerType: 'setSpeakerType',
  startSingleIntercomAndSpeak: 'startSingleIntercomAndSpeak',
  stopSingleIntercomAndSpeak: 'stopSingleIntercomAndSpeak',
  startDoubleIntercom: 'startDoubleIntercom',
  stopDoubleIntercom: 'stopDoubleIntercom',
  switchStreamTypeMonitor: 'switchStreamTypeMonitor',
  setVideoFullScreen: 'setVideoFullScreen',
  capturePicFromDevAndSave: 'capturePicFromDevAndSave'
};
const MonitorView = (0, _reactNative.requireNativeComponent)('RCTMonitor');
exports.MonitorView = MonitorView;
const dispatchCommand = function (viewId, command) {
  let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  return _reactNative.UIManager.dispatchViewManagerCommand(viewId,
  // we are calling the 'setVideoFlip' command
  // UIManager.RCTMonitor.Commands.setVideoFlip,
  // UIManager.RCTMonitor.Commands[command],
  _reactNative.UIManager.getViewManagerConfig('RCTMonitor').Commands[command] || '', args);
};
class Monitor extends _react.default.Component {
  constructor(props) {
    super(props);
    this.myRef = /*#__PURE__*/_react.default.createRef();
  }
  flipVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.setVideoFlip);
  }
  playVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startMonitor);
  }
  pauseVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.pauseMonitor);
  }
  replayVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.replayMonitor);
  }
  stopVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopMonitor);
  }
  destroyVideo() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.destroyMonitor);
  }
  captureImage(path) {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number' || typeof path !== 'string') {
      return;
    }
    dispatchCommand(viewId, Commands.captureImage, [path]);
  }
  startVideoRecord(path) {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number' || typeof path !== 'string') {
      return;
    }
    dispatchCommand(viewId, Commands.startVideoRecord, [path]);
  }
  stopVideoRecord() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopVideoRecord);
  }
  openVoice() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.openVoice);
  }
  closeVoice() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.closeVoice);
  }

  /**
   * set voice changer
   * 0 normal, 1 male ,2 female
   */
  setSpeakerType(type) {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.setSpeakerType, [type]);
  }
  startSingleIntercomAndSpeak() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startSingleIntercomAndSpeak);
  }
  stopSingleIntercomAndSpeak() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopSingleIntercomAndSpeak);
  }
  startDoubleIntercom() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startDoubleIntercom);
  }
  stopDoubleIntercom() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopDoubleIntercom);
  }
  swtichStream() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.switchStreamTypeMonitor);
  }
  setVideoFullScreen(isFullScreen) {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number' || typeof isFullScreen !== 'boolean') {
      return;
    }
    dispatchCommand(viewId, Commands.setVideoFullScreen, [isFullScreen]);
  }
  capturePicFromDevAndSave() {
    const viewId = (0, _reactNative.findNodeHandle)(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.capturePicFromDevAndSave);
  }
  render() {
    return /*#__PURE__*/_react.default.createElement(MonitorView, _extends({}, this.props, {
      ref: this.myRef
    }));
  }
}
exports.Monitor = Monitor;
//# sourceMappingURL=index.js.map