(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "rxjs", "rxjs/operators", "@bottlenose/rxws", "../internals/createAwsSignedUrl", "../internals/convertAudioToAWSBinaryMessage", "../internals/decodeAWSMessage", "../internals/shortenChunks"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("rxjs"), require("rxjs/operators"), require("@bottlenose/rxws"), require("../internals/createAwsSignedUrl"), require("../internals/convertAudioToAWSBinaryMessage"), require("../internals/decodeAWSMessage"), require("../internals/shortenChunks"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.rxjs, global.operators, global.rxws, global.createAwsSignedUrl, global.convertAudioToAWSBinaryMessage, global.decodeAWSMessage, global.shortenChunks);
    global.toAWS = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _rxjs, _operators, _rxws, _createAwsSignedUrl, _convertAudioToAWSBinaryMessage, _decodeAWSMessage, _shortenChunks) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  _createAwsSignedUrl = _interopRequireDefault(_createAwsSignedUrl);
  _convertAudioToAWSBinaryMessage = _interopRequireDefault(_convertAudioToAWSBinaryMessage);
  _decodeAWSMessage = _interopRequireDefault(_decodeAWSMessage);
  _shortenChunks = _interopRequireDefault(_shortenChunks);

  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

  const errors = {
    missingCredentials: () => new Error('toAWS operator requires AWS credentials')
  };

  const toAWS = function toAWS({
    region = process.env.AWS_REGION || 'us-east-1',
    accessKeyId = process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY,
    stop$ = (0, _rxjs.of)(),
    isMedical = false,
    specialty = 'PRIMARYCARE',
    type = 'CONVERSATION',
    chunkSize = 512,
    _conduit = _rxws.conduit,
    _serializer = audioBinary => (0, _convertAudioToAWSBinaryMessage.default)({
      audioBinary
    }),
    _deserializer = message => (0, _decodeAWSMessage.default)({
      message
    }),
    _getPresignedUrl = _createAwsSignedUrl.default
  } = {}) {
    if (!accessKeyId) return (0, _rxjs.throwError)(errors.missingCredentials());
    if (!secretAccessKey) return (0, _rxjs.throwError)(errors.missingCredentials());
    return fileChunk$ => {
      const url = _getPresignedUrl({
        region,
        accessKeyId,
        secretAccessKey,
        isMedical,
        type,
        specialty
      });

      const message$ = fileChunk$.pipe((0, _shortenChunks.default)(chunkSize), _conduit({
        url,
        serializer: _serializer,
        deserializer: _deserializer
      }), (0, _operators.takeUntil)(stop$));
      return message$;
    };
  };

  var _default = toAWS;
  _exports.default = _default;
});
//# sourceMappingURL=toAWS.js.map