@bigbinary/neeto-media-recorder 2.1.6 → 2.3.0

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/index.js CHANGED
@@ -2,7 +2,7 @@ import { shallow } from 'zustand/shallow';
2
2
  import { useState, useEffect, forwardRef, useImperativeHandle, useRef } from 'react';
3
3
  import classNames from 'classnames';
4
4
  import { isNotEmpty, noop } from '@bigbinary/neeto-cist';
5
- import { SCREEN_RECORDER_STATUS, SCREEN_RECORDER_ERROR, IS_SAFARI_EXTENSION, UPLOAD_STATUS, ONE_MINUTE_IN_MILLISECONDS as ONE_MINUTE_IN_MILLISECONDS$1, ONE_SECOND_IN_MILLISECONDS as ONE_SECOND_IN_MILLISECONDS$1, IS_EXTENSION as IS_EXTENSION$1, SCREEN_RECORDER_EVENT, UPLOAD_EVENT } from '@bigbinary/neeto-media-recorder/constants';
5
+ import { SCREEN_RECORDER_STATUS, UPLOAD_STATUS, MIME_TYPE as MIME_TYPE$1, ONE_MINUTE_IN_MILLISECONDS as ONE_MINUTE_IN_MILLISECONDS$1, ONE_SECOND_IN_MILLISECONDS as ONE_SECOND_IN_MILLISECONDS$1, IS_EXTENSION as IS_EXTENSION$1, SCREEN_RECORDER_ERROR, IS_SAFARI_EXTENSION, SCREEN_RECORDER_EVENT, UPLOAD_EVENT } from '@bigbinary/neeto-media-recorder/constants';
6
6
  import { screenRecorder, multipartS3Uploader } from '@bigbinary/neeto-media-recorder/core';
7
7
  import PageLoader from '@bigbinary/neeto-molecules/PageLoader';
8
8
  import Alert from '@bigbinary/neetoui/Alert';
@@ -12,6 +12,8 @@ import Typography from '@bigbinary/neetoui/Typography';
12
12
  import { useTranslation, Trans } from 'react-i18next';
13
13
  import { useMutation } from '@tanstack/react-query';
14
14
  import axios from 'axios';
15
+ import platform from 'platform';
16
+ import { isNotNil, isEmpty } from 'ramda';
15
17
  import withT from '@bigbinary/neeto-commons-frontend/react-utils/withT';
16
18
  import Spinner from '@bigbinary/neetoui/Spinner';
17
19
  import { jsx, jsxs } from 'react/jsx-runtime';
@@ -19,8 +21,6 @@ import Computer from '@bigbinary/neeto-icons/Computer';
19
21
  import Delete from '@bigbinary/neeto-icons/Delete';
20
22
  import Pause from '@bigbinary/neeto-icons/Pause';
21
23
  import Unlock from '@bigbinary/neeto-icons/Unlock';
22
- import platform from 'platform';
23
- import { isNotNil, isEmpty } from 'ramda';
24
24
  import { copyToClipboard } from '@bigbinary/neeto-commons-frontend/utils/general';
25
25
  import Close from '@bigbinary/neeto-icons/Close';
26
26
  import Download from '@bigbinary/neeto-icons/Download';
@@ -512,11 +512,136 @@ function _defineProperty(obj, key, value) {
512
512
  return obj;
513
513
  }
514
514
 
515
+ var ONE_SECOND_IN_MILLISECONDS = 1000;
516
+ var ONE_MINUTE_IN_MILLISECONDS = 60 * ONE_SECOND_IN_MILLISECONDS;
517
+ var ONE_HOUR_IN_MILLISECONDS = 60 * ONE_MINUTE_IN_MILLISECONDS;
518
+ var HAS_CHROME_NAMESPACE = (typeof chrome === "undefined" ? "undefined" : _typeof(chrome)) === "object";
519
+ var IS_EXTENSION = HAS_CHROME_NAMESPACE && isNotNil(chrome.extension);
520
+ platform.name === "Safari";
521
+ var MIME_TYPE = {
522
+ mp4: "video/mp4",
523
+ webmH264: "video/webm;codecs=h264"
524
+ };
525
+ // 2 hours
526
+
527
+ var getSupportedMimeType = function getSupportedMimeType(fallback) {
528
+ if (MediaRecorder.isTypeSupported(MIME_TYPE.mp4)) {
529
+ return MIME_TYPE.mp4;
530
+ } else if (MediaRecorder.isTypeSupported(MIME_TYPE.webmH264)) {
531
+ return MIME_TYPE.webmH264;
532
+ }
533
+ return fallback;
534
+ };
535
+
536
+ var formatTime = function formatTime(time) {
537
+ return Math.floor(time).toString().padStart(2, "0");
538
+ };
539
+ var getTimeString = function getTimeString(date) {
540
+ var hours = formatTime(Math.floor(date / ONE_HOUR_IN_MILLISECONDS));
541
+ var minutes = formatTime(date % ONE_HOUR_IN_MILLISECONDS / ONE_MINUTE_IN_MILLISECONDS$1);
542
+ var seconds = formatTime(date % ONE_MINUTE_IN_MILLISECONDS$1 / ONE_SECOND_IN_MILLISECONDS$1);
543
+ if (hours > 0) {
544
+ return "".concat(hours, ":").concat(minutes, ":").concat(seconds);
545
+ }
546
+ return "".concat(minutes, ":").concat(seconds);
547
+ };
548
+ var downloadRecordingBlob = function downloadRecordingBlob(blob, name) {
549
+ var blobUrl = URL.createObjectURL(blob);
550
+ var linkElement = document.createElement("a");
551
+ linkElement.href = blobUrl;
552
+ linkElement.download = name;
553
+ document.body.appendChild(linkElement);
554
+
555
+ // Dispatch click event on the link
556
+ // This is necessary as link.click() does not work on the latest firefox
557
+ linkElement.dispatchEvent(new MouseEvent("click", {
558
+ bubbles: true,
559
+ cancelable: true,
560
+ view: window
561
+ }));
562
+ document.body.removeChild(linkElement);
563
+ URL.revokeObjectURL(blobUrl);
564
+ };
565
+ var hasRecordingDiscarded = function hasRecordingDiscarded(_ref) {
566
+ var recorderStatus = _ref.recorderStatus,
567
+ uploadStatus = _ref.uploadStatus;
568
+ return recorderStatus === SCREEN_RECORDER_STATUS.stopped && uploadStatus === UPLOAD_STATUS.aborting;
569
+ };
570
+ var getRecorderTimeLimitInHumanFormat = function getRecorderTimeLimitInHumanFormat(timeInMs) {
571
+ var minutes = Math.floor(timeInMs / (1000 * 60));
572
+ var hours = Math.floor(minutes / 60);
573
+ if (hours < 1) {
574
+ return "".concat(minutes, " minutes");
575
+ }
576
+ return "".concat(hours, " hours");
577
+ };
578
+ var getDeviceInfo = /*#__PURE__*/function () {
579
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
580
+ var _yield$chrome$storage, _platform$os;
581
+ var isCameraEnabled;
582
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
583
+ while (1) switch (_context.prev = _context.next) {
584
+ case 0:
585
+ if (!IS_EXTENSION$1) {
586
+ _context.next = 15;
587
+ break;
588
+ }
589
+ _context.next = 3;
590
+ return chrome.storage.local.get("isCameraOn");
591
+ case 3:
592
+ _context.t2 = _yield$chrome$storage = _context.sent;
593
+ _context.t1 = _context.t2 === null;
594
+ if (_context.t1) {
595
+ _context.next = 7;
596
+ break;
597
+ }
598
+ _context.t1 = _yield$chrome$storage === void 0;
599
+ case 7:
600
+ if (!_context.t1) {
601
+ _context.next = 11;
602
+ break;
603
+ }
604
+ _context.t3 = void 0;
605
+ _context.next = 12;
606
+ break;
607
+ case 11:
608
+ _context.t3 = _yield$chrome$storage.isCameraOn;
609
+ case 12:
610
+ _context.t0 = _context.t3;
611
+ _context.next = 16;
612
+ break;
613
+ case 15:
614
+ _context.t0 = false;
615
+ case 16:
616
+ isCameraEnabled = _context.t0;
617
+ return _context.abrupt("return", {
618
+ os: (_platform$os = platform.os) === null || _platform$os === void 0 ? void 0 : _platform$os.toString(),
619
+ app: IS_EXTENSION$1 ? "chrome extension v".concat(chrome.runtime.getManifest().version) : "web",
620
+ browser: "".concat(platform.name, " v").concat(platform.version),
621
+ isCameraEnabled: isCameraEnabled,
622
+ isMicEnabled: !!screenRecorder.audioConfiguration,
623
+ displaySurface: screenRecorder.displaySurface
624
+ });
625
+ case 18:
626
+ case "end":
627
+ return _context.stop();
628
+ }
629
+ }, _callee);
630
+ }));
631
+ return function getDeviceInfo() {
632
+ return _ref2.apply(this, arguments);
633
+ };
634
+ }();
635
+ var isMp4Supported = function isMp4Supported() {
636
+ return getSupportedMimeType() === MIME_TYPE$1.mp4;
637
+ };
638
+
515
639
  var baseUrl = "/api/v1/recordings";
516
640
  var create = function create(deviceInfo) {
517
641
  return axios.post(baseUrl, {
518
642
  recording: {
519
- deviceInfo: deviceInfo
643
+ deviceInfo: deviceInfo,
644
+ isMp4: isMp4Supported()
520
645
  }
521
646
  });
522
647
  };
@@ -839,114 +964,6 @@ var useMultipartS3UploadStatus = function useMultipartS3UploadStatus() {
839
964
  };
840
965
  };
841
966
 
842
- var ONE_SECOND_IN_MILLISECONDS = 1000;
843
- var ONE_MINUTE_IN_MILLISECONDS = 60 * ONE_SECOND_IN_MILLISECONDS;
844
- var ONE_HOUR_IN_MILLISECONDS = 60 * ONE_MINUTE_IN_MILLISECONDS;
845
- var HAS_CHROME_NAMESPACE = (typeof chrome === "undefined" ? "undefined" : _typeof(chrome)) === "object";
846
- var IS_EXTENSION = HAS_CHROME_NAMESPACE && isNotNil(chrome.extension);
847
- platform.name === "Safari";
848
- // 2 hours
849
-
850
- var formatTime = function formatTime(time) {
851
- return Math.floor(time).toString().padStart(2, "0");
852
- };
853
- var getTimeString = function getTimeString(date) {
854
- var hours = formatTime(Math.floor(date / ONE_HOUR_IN_MILLISECONDS));
855
- var minutes = formatTime(date % ONE_HOUR_IN_MILLISECONDS / ONE_MINUTE_IN_MILLISECONDS$1);
856
- var seconds = formatTime(date % ONE_MINUTE_IN_MILLISECONDS$1 / ONE_SECOND_IN_MILLISECONDS$1);
857
- if (hours > 0) {
858
- return "".concat(hours, ":").concat(minutes, ":").concat(seconds);
859
- }
860
- return "".concat(minutes, ":").concat(seconds);
861
- };
862
- var downloadRecordingBlob = function downloadRecordingBlob(blob, name) {
863
- var blobUrl = URL.createObjectURL(blob);
864
- var linkElement = document.createElement("a");
865
- linkElement.href = blobUrl;
866
- linkElement.download = name;
867
- document.body.appendChild(linkElement);
868
-
869
- // Dispatch click event on the link
870
- // This is necessary as link.click() does not work on the latest firefox
871
- linkElement.dispatchEvent(new MouseEvent("click", {
872
- bubbles: true,
873
- cancelable: true,
874
- view: window
875
- }));
876
- document.body.removeChild(linkElement);
877
- URL.revokeObjectURL(blobUrl);
878
- };
879
- var hasRecordingDiscarded = function hasRecordingDiscarded(_ref) {
880
- var recorderStatus = _ref.recorderStatus,
881
- uploadStatus = _ref.uploadStatus;
882
- return recorderStatus === SCREEN_RECORDER_STATUS.stopped && uploadStatus === UPLOAD_STATUS.aborting;
883
- };
884
- var getRecorderTimeLimitInHumanFormat = function getRecorderTimeLimitInHumanFormat(timeInMs) {
885
- var minutes = Math.floor(timeInMs / (1000 * 60));
886
- var hours = Math.floor(minutes / 60);
887
- if (hours < 1) {
888
- return "".concat(minutes, " minutes");
889
- }
890
- return "".concat(hours, " hours");
891
- };
892
- var getDeviceInfo = /*#__PURE__*/function () {
893
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
894
- var _yield$chrome$storage, _platform$os;
895
- var isCameraEnabled;
896
- return _regeneratorRuntime.wrap(function _callee$(_context) {
897
- while (1) switch (_context.prev = _context.next) {
898
- case 0:
899
- if (!IS_EXTENSION$1) {
900
- _context.next = 15;
901
- break;
902
- }
903
- _context.next = 3;
904
- return chrome.storage.local.get("isCameraOn");
905
- case 3:
906
- _context.t2 = _yield$chrome$storage = _context.sent;
907
- _context.t1 = _context.t2 === null;
908
- if (_context.t1) {
909
- _context.next = 7;
910
- break;
911
- }
912
- _context.t1 = _yield$chrome$storage === void 0;
913
- case 7:
914
- if (!_context.t1) {
915
- _context.next = 11;
916
- break;
917
- }
918
- _context.t3 = void 0;
919
- _context.next = 12;
920
- break;
921
- case 11:
922
- _context.t3 = _yield$chrome$storage.isCameraOn;
923
- case 12:
924
- _context.t0 = _context.t3;
925
- _context.next = 16;
926
- break;
927
- case 15:
928
- _context.t0 = false;
929
- case 16:
930
- isCameraEnabled = _context.t0;
931
- return _context.abrupt("return", {
932
- os: (_platform$os = platform.os) === null || _platform$os === void 0 ? void 0 : _platform$os.toString(),
933
- app: IS_EXTENSION$1 ? "chrome extension v".concat(chrome.runtime.getManifest().version) : "web",
934
- browser: "".concat(platform.name, " v").concat(platform.version),
935
- isCameraEnabled: isCameraEnabled,
936
- isMicEnabled: !!screenRecorder.audioConfiguration,
937
- displaySurface: screenRecorder.displaySurface
938
- });
939
- case 18:
940
- case "end":
941
- return _context.stop();
942
- }
943
- }, _callee);
944
- }));
945
- return function getDeviceInfo() {
946
- return _ref2.apply(this, arguments);
947
- };
948
- }();
949
-
950
967
  var Timer = function Timer() {
951
968
  var _useTranslation = useTranslation(),
952
969
  t = _useTranslation.t;
@@ -1069,8 +1086,8 @@ var UploadingInProgress = function UploadingInProgress(_ref) {
1069
1086
  }), /*#__PURE__*/jsx(Button, {
1070
1087
  "data-cy": "recorder-download-webm-button",
1071
1088
  icon: Download,
1072
- label: t("neetoMediaRecorder.record.downloadWebm"),
1073
1089
  style: "tertiary",
1090
+ label: isMp4Supported() ? t("neetoMediaRecorder.record.downloadMp4") : t("neetoMediaRecorder.record.downloadWebm"),
1074
1091
  onClick: handleRecordingBlobDownload
1075
1092
  }), /*#__PURE__*/jsx(Button, {
1076
1093
  "data-cy": "recorder-discard-recording-button",
@@ -1208,7 +1225,7 @@ var useRecorderStore = screenRecorder.useRecorderStore,
1208
1225
  discardRecording = screenRecorder.discardRecording;
1209
1226
  var useMultipartS3UploadStore = multipartS3Uploader.useMultipartS3UploadStore;
1210
1227
  var globalProps = ((_window = window) === null || _window === void 0 ? void 0 : _window.globalProps) || {};
1211
- var MediaRecorder = function MediaRecorder(_ref, ref) {
1228
+ var MediaRecorder$1 = function MediaRecorder(_ref, ref) {
1212
1229
  var _ref$onUploadComplete = _ref.onUploadComplete,
1213
1230
  onUploadComplete = _ref$onUploadComplete === void 0 ? noop : _ref$onUploadComplete,
1214
1231
  _ref$onDiscard = _ref.onDiscard,
@@ -1544,7 +1561,7 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
1544
1561
  })]
1545
1562
  });
1546
1563
  };
1547
- var index = /*#__PURE__*/forwardRef(MediaRecorder);
1564
+ var index = /*#__PURE__*/forwardRef(MediaRecorder$1);
1548
1565
 
1549
1566
  export { index as MediaRecorder };
1550
1567
  //# sourceMappingURL=index.js.map