@bigbinary/neeto-media-recorder 1.1.4 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core.js CHANGED
@@ -522,6 +522,113 @@ try {
522
522
 
523
523
  var _regeneratorRuntime = /*@__PURE__*/getDefaultExportFromCjs(regenerator);
524
524
 
525
+ function _setPrototypeOf(o, p) {
526
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
527
+ o.__proto__ = p;
528
+ return o;
529
+ };
530
+ return _setPrototypeOf(o, p);
531
+ }
532
+
533
+ function _inherits(subClass, superClass) {
534
+ if (typeof superClass !== "function" && superClass !== null) {
535
+ throw new TypeError("Super expression must either be null or a function");
536
+ }
537
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
538
+ constructor: {
539
+ value: subClass,
540
+ writable: true,
541
+ configurable: true
542
+ }
543
+ });
544
+ Object.defineProperty(subClass, "prototype", {
545
+ writable: false
546
+ });
547
+ if (superClass) _setPrototypeOf(subClass, superClass);
548
+ }
549
+
550
+ function _assertThisInitialized(self) {
551
+ if (self === void 0) {
552
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
553
+ }
554
+ return self;
555
+ }
556
+
557
+ function _possibleConstructorReturn(self, call) {
558
+ if (call && (_typeof$1(call) === "object" || typeof call === "function")) {
559
+ return call;
560
+ } else if (call !== void 0) {
561
+ throw new TypeError("Derived constructors may only return object or undefined");
562
+ }
563
+ return _assertThisInitialized(self);
564
+ }
565
+
566
+ function _getPrototypeOf(o) {
567
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
568
+ return o.__proto__ || Object.getPrototypeOf(o);
569
+ };
570
+ return _getPrototypeOf(o);
571
+ }
572
+
573
+ function _isNativeFunction(fn) {
574
+ return Function.toString.call(fn).indexOf("[native code]") !== -1;
575
+ }
576
+
577
+ function _isNativeReflectConstruct$1() {
578
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
579
+ if (Reflect.construct.sham) return false;
580
+ if (typeof Proxy === "function") return true;
581
+ try {
582
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
583
+ return true;
584
+ } catch (e) {
585
+ return false;
586
+ }
587
+ }
588
+
589
+ function _construct(Parent, args, Class) {
590
+ if (_isNativeReflectConstruct$1()) {
591
+ _construct = Reflect.construct.bind();
592
+ } else {
593
+ _construct = function _construct(Parent, args, Class) {
594
+ var a = [null];
595
+ a.push.apply(a, args);
596
+ var Constructor = Function.bind.apply(Parent, a);
597
+ var instance = new Constructor();
598
+ if (Class) _setPrototypeOf(instance, Class.prototype);
599
+ return instance;
600
+ };
601
+ }
602
+ return _construct.apply(null, arguments);
603
+ }
604
+
605
+ function _wrapNativeSuper(Class) {
606
+ var _cache = typeof Map === "function" ? new Map() : undefined;
607
+ _wrapNativeSuper = function _wrapNativeSuper(Class) {
608
+ if (Class === null || !_isNativeFunction(Class)) return Class;
609
+ if (typeof Class !== "function") {
610
+ throw new TypeError("Super expression must either be null or a function");
611
+ }
612
+ if (typeof _cache !== "undefined") {
613
+ if (_cache.has(Class)) return _cache.get(Class);
614
+ _cache.set(Class, Wrapper);
615
+ }
616
+ function Wrapper() {
617
+ return _construct(Class, arguments, _getPrototypeOf(this).constructor);
618
+ }
619
+ Wrapper.prototype = Object.create(Class.prototype, {
620
+ constructor: {
621
+ value: Wrapper,
622
+ enumerable: false,
623
+ writable: true,
624
+ configurable: true
625
+ }
626
+ });
627
+ return _setPrototypeOf(Wrapper, Class);
628
+ };
629
+ return _wrapNativeSuper(Class);
630
+ }
631
+
525
632
  var TOTAL_RETRIES = 30;
526
633
  var INITIAL_RETRY_DELAY = 4000;
527
634
  var MAX_RETRY_DELAY = 16000;
@@ -545,6 +652,17 @@ var sleep = function sleep(delay) {
545
652
  });
546
653
  };
547
654
 
655
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
656
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
657
+ var RetryError = /*#__PURE__*/function (_Error) {
658
+ _inherits(RetryError, _Error);
659
+ var _super = _createSuper(RetryError);
660
+ function RetryError(message) {
661
+ _classCallCheck(this, RetryError);
662
+ return _super.call(this, message);
663
+ }
664
+ return _createClass(RetryError);
665
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
548
666
  var buildRetryableApi = function buildRetryableApi(apiConnector) {
549
667
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_RETRY_CONFIG,
550
668
  _ref$retries = _ref.retries,
@@ -554,48 +672,54 @@ var buildRetryableApi = function buildRetryableApi(apiConnector) {
554
672
  retryableStatuses = _ref.retryableStatuses;
555
673
  return /*#__PURE__*/function () {
556
674
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(apiConnectorArgs) {
557
- var remainingAttempts, _error$response, isRetryableStatus, isRetryableError;
675
+ var _config$signal;
676
+ var _apiConnectorArgs$con, config, remainingAttempts, shouldCancelRetries, _error$response, isRetryableStatus, isRetryableError;
558
677
  return _regeneratorRuntime.wrap(function _callee$(_context) {
559
678
  while (1) switch (_context.prev = _context.next) {
560
679
  case 0:
680
+ _apiConnectorArgs$con = apiConnectorArgs.config, config = _apiConnectorArgs$con === void 0 ? null : _apiConnectorArgs$con;
561
681
  remainingAttempts = retries + 1;
562
- case 1:
563
- if (!remainingAttempts--) {
564
- _context.next = 21;
682
+ shouldCancelRetries = false;
683
+ config === null || config === void 0 ? void 0 : (_config$signal = config.signal) === null || _config$signal === void 0 ? void 0 : _config$signal.addEventListener("abort", function () {
684
+ shouldCancelRetries = true;
685
+ });
686
+ case 4:
687
+ if (!(remainingAttempts-- && !shouldCancelRetries)) {
688
+ _context.next = 24;
565
689
  break;
566
690
  }
567
- _context.prev = 2;
568
- _context.next = 5;
691
+ _context.prev = 5;
692
+ _context.next = 8;
569
693
  return apiConnector(apiConnectorArgs);
570
- case 5:
571
- return _context.abrupt("return", _context.sent);
572
694
  case 8:
573
- _context.prev = 8;
574
- _context.t0 = _context["catch"](2);
695
+ return _context.abrupt("return", _context.sent);
696
+ case 11:
697
+ _context.prev = 11;
698
+ _context.t0 = _context["catch"](5);
575
699
  isRetryableStatus = isPresent(retryableStatuses) && retryableStatuses.includes((_error$response = _context.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.status);
576
700
  isRetryableError = isRetryableStatus || _context.t0.message === NETWORK_ERROR || _context.t0.code === TIMEOUT_ERROR;
577
701
  if (!(isRetryableError && remainingAttempts > 0)) {
578
- _context.next = 18;
702
+ _context.next = 21;
579
703
  break;
580
704
  }
581
- _context.next = 15;
705
+ _context.next = 18;
582
706
  return sleep(retryDelay);
583
- case 15:
584
- retryDelay = min(retryDelay * 2, MAX_RETRY_DELAY);
585
- _context.next = 19;
586
- break;
587
707
  case 18:
588
- throw _context.t0;
589
- case 19:
590
- _context.next = 1;
708
+ retryDelay = min(retryDelay * 2, MAX_RETRY_DELAY);
709
+ _context.next = 22;
591
710
  break;
592
711
  case 21:
593
- return _context.abrupt("return", null);
712
+ throw _context.t0;
594
713
  case 22:
714
+ _context.next = 4;
715
+ break;
716
+ case 24:
717
+ throw new RetryError("Request cancelled or request retries exhausted");
718
+ case 25:
595
719
  case "end":
596
720
  return _context.stop();
597
721
  }
598
- }, _callee, null, [[2, 8]]);
722
+ }, _callee, null, [[5, 11]]);
599
723
  }));
600
724
  return function (_x) {
601
725
  return _ref2.apply(this, arguments);
@@ -617,10 +741,11 @@ var abortUploadApi = {
617
741
 
618
742
  var create$1 = function create(_ref) {
619
743
  var recordingId = _ref.recordingId,
620
- payload = _ref.payload;
744
+ payload = _ref.payload,
745
+ config = _ref.config;
621
746
  return axios.post("/api/v1/recordings/".concat(recordingId, "/complete_upload"), {
622
747
  completeUpload: payload
623
- });
748
+ }, config);
624
749
  };
625
750
  var retryableCreate$1 = buildRetryableApi(create$1);
626
751
  var completeUploadApi = {
@@ -629,10 +754,11 @@ var completeUploadApi = {
629
754
 
630
755
  var create = function create(_ref) {
631
756
  var recordingId = _ref.recordingId,
632
- payload = _ref.payload;
757
+ payload = _ref.payload,
758
+ config = _ref.config;
633
759
  return axios.post("/api/v1/recordings/".concat(recordingId, "/part_presigned_url"), {
634
760
  partPresignedUrl: payload
635
- });
761
+ }, config);
636
762
  };
637
763
  var retryableCreate = buildRetryableApi(create);
638
764
  var partPresignedUrlApi = {
@@ -668,6 +794,14 @@ var prepareStore$1 = function prepareStore() {
668
794
  }));
669
795
  };
670
796
 
797
+ /**
798
+ * Due to the custom axios interceptor for s3Api,
799
+ * it'll return false for cancelled requests instead of a cancelled error object.
800
+ */
801
+ var isNotCancelledRequest = function isNotCancelledRequest(resolvedResponse) {
802
+ return typeof resolvedResponse !== "boolean";
803
+ };
804
+
671
805
  function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
672
806
  function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
673
807
  function _classPrivateFieldInitSpec$1(obj, privateMap, value) { _checkPrivateRedeclaration$1(obj, privateMap); privateMap.set(obj, value); }
@@ -783,7 +917,7 @@ var MultipartS3Uploader = /*#__PURE__*/function () {
783
917
  return Promise.all(_classPrivateFieldGet(_this, _s3PartUploadPromises));
784
918
  case 9:
785
919
  resolvedS3PartUploadPromises = _context.sent;
786
- parts = resolvedS3PartUploadPromises.map(function (resolvedResponse) {
920
+ parts = resolvedS3PartUploadPromises.filter(isNotCancelledRequest).map(function (resolvedResponse) {
787
921
  return {
788
922
  etag: resolvedResponse.headers.etag,
789
923
  partNumber: new URL(resolvedResponse.request.responseURL).searchParams.get("partNumber")
@@ -797,6 +931,9 @@ var MultipartS3Uploader = /*#__PURE__*/function () {
797
931
  payload: {
798
932
  parts: parts,
799
933
  uploadId: _classPrivateFieldGet(_this, _uploadId)
934
+ },
935
+ config: {
936
+ signal: _classPrivateFieldGet(_this, _abortController).signal
800
937
  }
801
938
  });
802
939
  case 13:
@@ -908,6 +1045,9 @@ var MultipartS3Uploader = /*#__PURE__*/function () {
908
1045
  payload: {
909
1046
  partNumber: (_classPrivateFieldSet(_this, _partNumber, (_this$partNumber = _classPrivateFieldGet(_this, _partNumber), _this$partNumber2 = _this$partNumber++, _this$partNumber)), _this$partNumber2),
910
1047
  uploadId: _classPrivateFieldGet(_this, _uploadId)
1048
+ },
1049
+ config: {
1050
+ signal: _classPrivateFieldGet(_this, _abortController).signal
911
1051
  }
912
1052
  });
913
1053
  case 4: