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); }
import React from 'react';
import { requireNativeComponent, UIManager, findNodeHandle } from 'react-native';
const Commands = {
  // setVideoFlip: 'setVideoFlip',
  startMonitor: 'startMonitor',
  pauseMonitor: 'pauseMonitor',
  replayMonitor: 'replayMonitor',
  stopMonitor: 'stopMonitor',
  destroyMonitor: 'destroyMonitor',
  captureImage: 'captureImage',
  startVideoRecord: 'startVideoRecord',
  stopVideoRecord: 'stopVideoRecord',
  openVoice: 'openVoice',
  closeVoice: 'closeVoice',
  // depreceated
  // setSpeakerType: 'setSpeakerType',
  startSingleIntercomAndSpeak: 'startSingleIntercomAndSpeak',
  stopSingleIntercomAndSpeak: 'stopSingleIntercomAndSpeak',
  startDoubleIntercom: 'startDoubleIntercom',
  stopDoubleIntercom: 'stopDoubleIntercom',
  switchStreamTypeMonitor: 'switchStreamTypeMonitor',
  setVideoFullScreen: 'setVideoFullScreen',
  capturePicFromDevAndSave: 'capturePicFromDevAndSave'
};
export const MonitorView = requireNativeComponent('RCTMonitor');
const dispatchCommand = function (viewId, command) {
  let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
  return UIManager.dispatchViewManagerCommand(viewId,
  // we are calling the 'setVideoFlip' command
  // UIManager.RCTMonitor.Commands.setVideoFlip,
  // UIManager.RCTMonitor.Commands[command],
  UIManager.getViewManagerConfig('RCTMonitor').Commands[command] || '', args);
};
export class Monitor extends React.Component {
  constructor(props) {
    super(props);
    this.myRef = /*#__PURE__*/React.createRef();
  }

  // flipVideo() {
  //   const viewId = findNodeHandle(this.myRef.current);

  //   if (typeof viewId !== 'number') {
  //     return;
  //   }

  //   dispatchCommand(viewId, Commands.setVideoFlip);
  // }

  playVideo() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startMonitor);
  }
  pauseVideo() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.pauseMonitor);
  }
  replayVideo() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.replayMonitor);
  }
  stopVideo() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopMonitor);
  }
  destroyVideo() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.destroyMonitor);
  }
  captureImage(path) {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number' || typeof path !== 'string') {
      return;
    }
    dispatchCommand(viewId, Commands.captureImage, [path]);
  }
  startVideoRecord(path) {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number' || typeof path !== 'string') {
      return;
    }
    dispatchCommand(viewId, Commands.startVideoRecord, [path]);
  }
  stopVideoRecord() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopVideoRecord);
  }
  openVoice() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.openVoice);
  }
  closeVoice() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.closeVoice);
  }

  // depreceated
  /**
   * set voice changer
   * 0 normal, 1 male ,2 female
   */
  // setSpeakerType(type: 0 | 1 | 2) {
  //   const viewId = findNodeHandle(this.myRef.current);

  //   if (typeof viewId !== 'number') {
  //     return;
  //   }

  //   dispatchCommand(viewId, Commands.setSpeakerType, [type]);
  // }

  startSingleIntercomAndSpeak() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startSingleIntercomAndSpeak);
  }
  stopSingleIntercomAndSpeak() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopSingleIntercomAndSpeak);
  }
  startDoubleIntercom() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.startDoubleIntercom);
  }
  stopDoubleIntercom() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.stopDoubleIntercom);
  }
  swtichStream() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.switchStreamTypeMonitor);
  }
  setVideoFullScreen(isFullScreen) {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number' || typeof isFullScreen !== 'boolean') {
      return;
    }
    dispatchCommand(viewId, Commands.setVideoFullScreen, [isFullScreen]);
  }
  capturePicFromDevAndSave() {
    const viewId = findNodeHandle(this.myRef.current);
    if (typeof viewId !== 'number') {
      return;
    }
    dispatchCommand(viewId, Commands.capturePicFromDevAndSave);
  }
  render() {
    return /*#__PURE__*/React.createElement(MonitorView, _extends({}, this.props, {
      ref: this.myRef
    }));
  }
}
//# sourceMappingURL=index.js.map