@bigbinary/neeto-media-recorder 2.7.17 → 2.7.18

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.
Files changed (3) hide show
  1. package/index.js +82 -58
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { shallow } from 'zustand/shallow';
2
2
  import { useState, useRef, useCallback, useEffect, forwardRef, useImperativeHandle } from 'react';
3
+ import { useMutation, isCancelledError } from '@tanstack/react-query';
3
4
  import classNames from 'classnames';
4
5
  import { isNotEmpty, noop } from '@bigbinary/neeto-cist';
5
6
  import Browser from '@bigbinary/neeto-icons/Browser';
@@ -11,7 +12,6 @@ import Button from '@bigbinary/neetoui/Button';
11
12
  import Callout from '@bigbinary/neetoui/Callout';
12
13
  import Typography from '@bigbinary/neetoui/Typography';
13
14
  import { useTranslation, Trans } from 'react-i18next';
14
- import { useMutation } from '@tanstack/react-query';
15
15
  import axios from 'axios';
16
16
  import platform from 'platform';
17
17
  import { isNotNil, isEmpty } from 'ramda';
@@ -661,14 +661,14 @@ var AbortUpload = withT(function (_ref) {
661
661
  className: "w-full space-y-2 text-center",
662
662
  children: [/*#__PURE__*/jsxs(Typography, {
663
663
  className: "select-none",
664
- "data-cy": "recorder-discarding-recording-message",
664
+ "data-testid": "recorder-discarding-recording-message",
665
665
  style: "h2",
666
666
  children: [t("neetoMediaRecorder.record.discardingVideo"), /*#__PURE__*/jsx(Spinner, {
667
667
  className: "ml-3"
668
668
  })]
669
669
  }), /*#__PURE__*/jsx(Typography, {
670
670
  className: "select-none",
671
- "data-cy": "recorder-do-not-leave-page-message",
671
+ "data-testid": "recorder-do-not-leave-page-message",
672
672
  children: t("neetoMediaRecorder.record.doNotLeaveThePage")
673
673
  })]
674
674
  })
@@ -807,7 +807,7 @@ var Controls = function Controls(_ref) {
807
807
  className: "flex gap-4",
808
808
  children: [/*#__PURE__*/jsx(Button, {
809
809
  className: "flex-shrink-0",
810
- "data-cy": "media-recorder-record-button",
810
+ "data-testid": "media-recorder-record-button",
811
811
  icon: function icon() {
812
812
  return /*#__PURE__*/jsx(Computer, {
813
813
  size: 20
@@ -820,7 +820,7 @@ var Controls = function Controls(_ref) {
820
820
  onClick: startRecording
821
821
  }), /*#__PURE__*/jsx(Button, {
822
822
  className: "flex-shrink-0",
823
- "data-cy": "media-recorder-discard-button",
823
+ "data-testid": "media-recorder-discard-button",
824
824
  icon: function icon() {
825
825
  return /*#__PURE__*/jsx(Delete, {
826
826
  size: 20
@@ -836,7 +836,7 @@ var Controls = function Controls(_ref) {
836
836
  className: "flex gap-4",
837
837
  children: [/*#__PURE__*/jsx(Button, {
838
838
  className: "flex-shrink-0",
839
- "data-cy": "media-recorder-no-audio-button",
839
+ "data-testid": "media-recorder-no-audio-button",
840
840
  label: t("neetoMediaRecorder.record.iDontNeedAudio"),
841
841
  size: "large",
842
842
  style: "danger",
@@ -848,7 +848,7 @@ var Controls = function Controls(_ref) {
848
848
  }
849
849
  }), /*#__PURE__*/jsx(Button, {
850
850
  className: "flex-shrink-0",
851
- "data-cy": "media-recorder-grant-microphone-permission-button",
851
+ "data-testid": "media-recorder-grant-microphone-permission-button",
852
852
  icon: Unlock,
853
853
  iconPosition: "left",
854
854
  iconSize: 20,
@@ -860,7 +860,7 @@ var Controls = function Controls(_ref) {
860
860
  className: "flex items-center gap-3",
861
861
  children: [/*#__PURE__*/jsx(Button, {
862
862
  className: "nrec-done-button flex-shrink-0",
863
- "data-cy": "media-recorder-stop-button",
863
+ "data-testid": "media-recorder-stop-button",
864
864
  icon: function icon() {
865
865
  return /*#__PURE__*/jsx(StopIcon, {
866
866
  size: 28
@@ -875,7 +875,7 @@ var Controls = function Controls(_ref) {
875
875
  })]
876
876
  }), isStatus(SCREEN_RECORDER_STATUS.recording) && /*#__PURE__*/jsx(Button, {
877
877
  className: "flex-shrink-0",
878
- "data-cy": "media-recorder-pause-button",
878
+ "data-testid": "media-recorder-pause-button",
879
879
  style: "text",
880
880
  tooltipProps: {
881
881
  content: t("neetoMediaRecorder.record.pause"),
@@ -888,7 +888,7 @@ var Controls = function Controls(_ref) {
888
888
  })
889
889
  }), isStatus(SCREEN_RECORDER_STATUS.paused) && /*#__PURE__*/jsx(Button, {
890
890
  className: "flex-shrink-0",
891
- "data-cy": "media-recorder-play-button",
891
+ "data-testid": "media-recorder-play-button",
892
892
  style: "text",
893
893
  tooltipProps: {
894
894
  content: t("neetoMediaRecorder.record.resume"),
@@ -902,7 +902,7 @@ var Controls = function Controls(_ref) {
902
902
  className: "flex items-center gap-3",
903
903
  children: [/*#__PURE__*/jsx(Button, {
904
904
  className: "flex-shrink-0",
905
- "data-cy": "media-recorder-restart-button",
905
+ "data-testid": "media-recorder-restart-button",
906
906
  style: "text",
907
907
  tooltipProps: {
908
908
  content: t("neetoMediaRecorder.record.restart"),
@@ -916,7 +916,7 @@ var Controls = function Controls(_ref) {
916
916
  })
917
917
  }), /*#__PURE__*/jsx(Button, {
918
918
  className: "flex-shrink-0",
919
- "data-cy": "media-recorder-discard-button",
919
+ "data-testid": "media-recorder-discard-button",
920
920
  style: "text",
921
921
  tooltipProps: {
922
922
  content: t("neetoMediaRecorder.record.discard"),
@@ -1152,19 +1152,19 @@ var Timer = function Timer() {
1152
1152
  elapsedTime = _useRecorderStore.elapsedTime;
1153
1153
  return /*#__PURE__*/jsxs("div", {
1154
1154
  className: "mb-4 flex flex-col items-center justify-center",
1155
- "data-cy": "recorder-timer-wrapper",
1155
+ "data-testid": "recorder-timer-wrapper",
1156
1156
  children: [/*#__PURE__*/jsx(Typography, {
1157
1157
  className: "neeto-ui-text-4xl mb-3 flex justify-center",
1158
- "data-cy": "recorder-timer-elapsed-time",
1158
+ "data-testid": "recorder-timer-elapsed-time",
1159
1159
  weight: "semibold",
1160
1160
  children: getTimeString(elapsedTime)
1161
1161
  }), /*#__PURE__*/jsx(Typography, {
1162
1162
  className: "mb-2",
1163
- "data-cy": "recorder-recording-in-progress-message",
1163
+ "data-testid": "recorder-recording-in-progress-message",
1164
1164
  style: "h3",
1165
1165
  children: t("neetoMediaRecorder.record.inProgress")
1166
1166
  }), /*#__PURE__*/jsx(Typography, {
1167
- "data-cy": "recorder-do-not-leave-page-message",
1167
+ "data-testid": "recorder-do-not-leave-page-message",
1168
1168
  style: "body2",
1169
1169
  children: t("neetoMediaRecorder.record.doNotLeaveThePage")
1170
1170
  })]
@@ -1177,7 +1177,7 @@ var UnSupportedBrowser = withT(function (_ref) {
1177
1177
  className: "flex h-screen w-full items-center justify-center",
1178
1178
  children: /*#__PURE__*/jsx(Callout, {
1179
1179
  className: "p-5",
1180
- "data-cy": "recorder-unsupported-browser-callout",
1180
+ "data-testid": "recorder-unsupported-browser-callout",
1181
1181
  style: "danger",
1182
1182
  children: t("neetoMediaRecorder.unsupportedBrowser")
1183
1183
  })
@@ -1282,12 +1282,12 @@ var UploadingInProgress = function UploadingInProgress(_ref) {
1282
1282
  className: "w-full pb-6 text-center",
1283
1283
  children: [/*#__PURE__*/jsx(Typography, {
1284
1284
  className: "select-none pb-6",
1285
- "data-cy": "please-dont-close-this-tab",
1285
+ "data-testid": "please-dont-close-this-tab",
1286
1286
  style: "h1",
1287
1287
  children: t("neetoMediaRecorder.record.pleaseDontCloseThisTab")
1288
1288
  }), /*#__PURE__*/jsx(Typography, {
1289
1289
  className: "select-none pb-3",
1290
- "data-cy": "recorder-uploading-recording-message",
1290
+ "data-testid": "recorder-uploading-recording-message",
1291
1291
  style: "h2",
1292
1292
  weight: "normal",
1293
1293
  children: t("neetoMediaRecorder.record.uploadingRecording")
@@ -1301,33 +1301,33 @@ var UploadingInProgress = function UploadingInProgress(_ref) {
1301
1301
  })
1302
1302
  }), /*#__PURE__*/jsx(Typography, {
1303
1303
  className: "select-none",
1304
- "data-cy": "recorder-do-not-leave-page-message",
1304
+ "data-testid": "recorder-do-not-leave-page-message",
1305
1305
  style: "body2",
1306
1306
  children: t("neetoMediaRecorder.record.copyLinkDescription")
1307
1307
  })]
1308
1308
  }), /*#__PURE__*/jsxs("div", {
1309
1309
  className: "flex flex-wrap items-center justify-center gap-3",
1310
1310
  children: [/*#__PURE__*/jsx(CopyToClipboardButton, {
1311
- "data-cy": "recorder-copy-link-button",
1311
+ "data-testid": "recorder-copy-link-button",
1312
1312
  icon: Copy,
1313
1313
  label: t("neetoMediaRecorder.record.copyToClipboard"),
1314
1314
  style: "tertiary",
1315
1315
  value: generatePublicUrl(recording.id, baseURL)
1316
1316
  }), /*#__PURE__*/jsx(Button, {
1317
- "data-cy": "recorder-download-webm-button",
1317
+ "data-testid": "recorder-download-webm-button",
1318
1318
  icon: Download,
1319
1319
  style: "tertiary",
1320
1320
  label: isMp4Supported() ? t("neetoMediaRecorder.record.downloadMp4") : t("neetoMediaRecorder.record.downloadWebm"),
1321
1321
  onClick: handleRecordingBlobDownload
1322
1322
  }), /*#__PURE__*/jsx(Button, {
1323
- "data-cy": "recorder-retry-upload-button",
1323
+ "data-testid": "recorder-retry-upload-button",
1324
1324
  disabled: isRetryUpload,
1325
1325
  icon: Refresh,
1326
1326
  label: t("neetoMediaRecorder.record.retry"),
1327
1327
  style: "tertiary",
1328
1328
  onClick: onRetryUpload
1329
1329
  }), /*#__PURE__*/jsx(Button, {
1330
- "data-cy": "recorder-discard-recording-button",
1330
+ "data-testid": "recorder-discard-recording-button",
1331
1331
  icon: Close,
1332
1332
  label: t("neetoMediaRecorder.record.discardRecording"),
1333
1333
  style: "tertiary",
@@ -1572,25 +1572,49 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1572
1572
  }
1573
1573
  }, [elapsedTime]);
1574
1574
  recordingRef.current = recording;
1575
+ var handleCreateRecordingError = function handleCreateRecordingError(error) {
1576
+ if (isCancelledError(error)) return;
1577
+ screenRecorder.setError(SCREEN_RECORDER_ERROR.FailedToStart);
1578
+ onError(SCREEN_RECORDER_ERROR.FailedToStart);
1579
+ };
1575
1580
  var handleCreateRecording = /*#__PURE__*/function () {
1576
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1581
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1577
1582
  var payload;
1578
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1579
- while (1) switch (_context.prev = _context.next) {
1583
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1584
+ while (1) switch (_context2.prev = _context2.next) {
1580
1585
  case 0:
1581
1586
  payload = {
1582
1587
  folderId: folderId
1583
1588
  };
1584
- _context.next = 3;
1589
+ _context2.next = 3;
1585
1590
  return getDeviceInfo(mimeType);
1586
1591
  case 3:
1587
- payload.deviceInfo = _context.sent;
1588
- createRecordingPromise.current = createRecording(payload);
1592
+ payload.deviceInfo = _context2.sent;
1593
+ createRecordingPromise.current = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1594
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1595
+ while (1) switch (_context.prev = _context.next) {
1596
+ case 0:
1597
+ _context.prev = 0;
1598
+ _context.next = 3;
1599
+ return createRecording(payload);
1600
+ case 3:
1601
+ _context.next = 8;
1602
+ break;
1603
+ case 5:
1604
+ _context.prev = 5;
1605
+ _context.t0 = _context["catch"](0);
1606
+ handleCreateRecordingError(_context.t0);
1607
+ case 8:
1608
+ case "end":
1609
+ return _context.stop();
1610
+ }
1611
+ }, _callee, null, [[0, 5]]);
1612
+ }))();
1589
1613
  case 5:
1590
1614
  case "end":
1591
- return _context.stop();
1615
+ return _context2.stop();
1592
1616
  }
1593
- }, _callee);
1617
+ }, _callee2);
1594
1618
  }));
1595
1619
  return function handleCreateRecording() {
1596
1620
  return _ref3.apply(this, arguments);
@@ -1601,35 +1625,35 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1601
1625
  return onUploadComplete((_recordingRef$current = recordingRef.current) === null || _recordingRef$current === void 0 ? void 0 : _recordingRef$current.id);
1602
1626
  };
1603
1627
  var handleDiscardRecording = /*#__PURE__*/function () {
1604
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1605
- var _ref5,
1606
- _ref5$forceAbort,
1628
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1629
+ var _ref6,
1630
+ _ref6$forceAbort,
1607
1631
  forceAbort,
1608
1632
  multipartS3Uploader,
1609
- _args2 = arguments;
1610
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1611
- while (1) switch (_context2.prev = _context2.next) {
1633
+ _args3 = arguments;
1634
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1635
+ while (1) switch (_context3.prev = _context3.next) {
1612
1636
  case 0:
1613
- _ref5 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref5$forceAbort = _ref5.forceAbort, forceAbort = _ref5$forceAbort === void 0 ? false : _ref5$forceAbort;
1637
+ _ref6 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref6$forceAbort = _ref6.forceAbort, forceAbort = _ref6$forceAbort === void 0 ? false : _ref6$forceAbort;
1614
1638
  multipartS3Uploader = getMultipartS3Uploader();
1615
- _context2.next = 4;
1639
+ _context3.next = 4;
1616
1640
  return multipartS3Uploader.abortUpload(forceAbort);
1617
1641
  case 4:
1618
1642
  if (!(multipartS3Uploader.status === UPLOAD_STATUS$1.aborting)) {
1619
- _context2.next = 6;
1643
+ _context3.next = 6;
1620
1644
  break;
1621
1645
  }
1622
- return _context2.abrupt("return");
1646
+ return _context3.abrupt("return");
1623
1647
  case 6:
1624
1648
  onDiscard();
1625
1649
  case 7:
1626
1650
  case "end":
1627
- return _context2.stop();
1651
+ return _context3.stop();
1628
1652
  }
1629
- }, _callee2);
1653
+ }, _callee3);
1630
1654
  }));
1631
1655
  return function handleDiscardRecording() {
1632
- return _ref4.apply(this, arguments);
1656
+ return _ref5.apply(this, arguments);
1633
1657
  };
1634
1658
  }();
1635
1659
  var handleRestartRecording = function handleRestartRecording() {
@@ -1701,15 +1725,15 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1701
1725
  var multipartS3Uploader = getMultipartS3Uploader({
1702
1726
  initialize: true
1703
1727
  });
1704
- var recorderCallbacks = (_recorderCallbacks = {}, _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onDataAvailable, multipartS3Uploader.push), _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onStop, _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
1705
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1706
- while (1) switch (_context3.prev = _context3.next) {
1728
+ var recorderCallbacks = (_recorderCallbacks = {}, _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onDataAvailable, multipartS3Uploader.push), _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onStop, _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
1729
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1730
+ while (1) switch (_context4.prev = _context4.next) {
1707
1731
  case 0:
1708
1732
  if (!createRecordingPromise.current) {
1709
- _context3.next = 4;
1733
+ _context4.next = 4;
1710
1734
  break;
1711
1735
  }
1712
- _context3.next = 3;
1736
+ _context4.next = 3;
1713
1737
  return createRecordingPromise.current;
1714
1738
  case 3:
1715
1739
  createRecordingPromise.current = null;
@@ -1717,9 +1741,9 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1717
1741
  multipartS3Uploader.completeUpload();
1718
1742
  case 5:
1719
1743
  case "end":
1720
- return _context3.stop();
1744
+ return _context4.stop();
1721
1745
  }
1722
- }, _callee3);
1746
+ }, _callee4);
1723
1747
  }))), _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onDiscard, handleDiscardRecording), _defineProperty(_recorderCallbacks, SCREEN_RECORDER_EVENT.onRestart, handleRestartRecording), _recorderCallbacks);
1724
1748
  var uploaderCallbacks = (_uploaderCallbacks2 = {}, _defineProperty(_uploaderCallbacks2, UPLOAD_EVENT.onComplete, handleUploadComplete), _defineProperty(_uploaderCallbacks2, UPLOAD_EVENT.onError, handleUploadError), _defineProperty(_uploaderCallbacks2, UPLOAD_EVENT.onProgress, handleUploadProgress), _uploaderCallbacks2);
1725
1749
  Object.keys(recorderCallbacks).forEach(function (key) {
@@ -1761,7 +1785,7 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1761
1785
  className: "flex h-screen w-full flex-col items-center justify-center gap-4",
1762
1786
  children: [/*#__PURE__*/jsx(Callout, {
1763
1787
  className: "p-5",
1764
- "data-cy": "recorder-unsupported-browser-callout",
1788
+ "data-testid": "recorder-unsupported-browser-callout",
1765
1789
  style: "danger",
1766
1790
  children: t("neetoMediaRecorder.notSupportedError")
1767
1791
  }), /*#__PURE__*/jsx(Button, {
@@ -1802,7 +1826,7 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1802
1826
  className: classNames("w-full max-w-3xl"),
1803
1827
  children: [/*#__PURE__*/jsx(UseDesktopAppCallout, {}), error === SCREEN_RECORDER_ERROR.InsufficientData && /*#__PURE__*/jsx(Callout, {
1804
1828
  className: "mb-2 p-3",
1805
- "data-cy": "recorder-insufficient-data-error-callout",
1829
+ "data-testid": "recorder-insufficient-data-error-callout",
1806
1830
  style: "danger",
1807
1831
  children: t("neetoMediaRecorder.insufficientDataError")
1808
1832
  }), error === SCREEN_RECORDER_ERROR.NotAllowedError && /*#__PURE__*/jsxs("div", {
@@ -1847,17 +1871,17 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1847
1871
  }), /*#__PURE__*/jsx(AllowMicAccess, {})]
1848
1872
  }), isRecorderStatus(SCREEN_RECORDER_STATUS.acquiring_media) && /*#__PURE__*/jsx(Callout, {
1849
1873
  className: "mb-2 p-3",
1850
- "data-cy": "recorder-grant-permission-info-callout",
1874
+ "data-testid": "recorder-grant-permission-info-callout",
1851
1875
  style: "info",
1852
1876
  children: t("neetoMediaRecorder.record.grantPermissionMessage")
1853
1877
  }), shouldShowSafariExtensionCalloutToStartRecording && /*#__PURE__*/jsx(Callout, {
1854
1878
  className: "mx-auto mb-2 w-1/2 p-3",
1855
- "data-cy": "recorder-start-recording-info-callout",
1879
+ "data-testid": "recorder-start-recording-info-callout",
1856
1880
  style: "info",
1857
1881
  children: t("neetoMediaRecorder.record.clickToStartRecording")
1858
1882
  }), shouldShowTimeLimitWarning && /*#__PURE__*/jsx(Callout, {
1859
1883
  className: "mx-auto mb-2 w-1/2 p-3",
1860
- "data-cy": "recorder-time-limit-warning-callout",
1884
+ "data-testid": "recorder-time-limit-warning-callout",
1861
1885
  style: "warning",
1862
1886
  children: /*#__PURE__*/jsx(Typography, {
1863
1887
  component: "span",
@@ -1878,7 +1902,7 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1878
1902
  })
1879
1903
  }), isRecorderStatus(SCREEN_RECORDER_STATUS.media_acquired, SCREEN_RECORDER_STATUS.restarting) && /*#__PURE__*/jsxs("div", {
1880
1904
  className: "neeto-ui-rounded-lg mx-auto mb-8 flex w-full max-w-4xl flex-col items-center justify-center p-12",
1881
- "data-cy": "recorder-countdown-wrapper",
1905
+ "data-testid": "recorder-countdown-wrapper",
1882
1906
  children: [/*#__PURE__*/jsx("div", {
1883
1907
  className: "relative mb-8",
1884
1908
  children: /*#__PURE__*/jsxs("div", {