@bigbinary/neeto-media-recorder 2.7.27 → 2.7.29-beta.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/index.js CHANGED
@@ -508,14 +508,44 @@ var UPLOAD_STATUS = {
508
508
  };
509
509
  var HAS_CHROME_NAMESPACE = (typeof chrome === "undefined" ? "undefined" : _typeof$1(chrome)) === "object";
510
510
  var IS_EXTENSION = HAS_CHROME_NAMESPACE && isNotNil(chrome.extension);
511
- platform.name === "Safari";
511
+ var IS_SAFARI = platform.name === "Safari";
512
+
513
+ // Firefox refuses to start a MediaRecorder on a stream that has both audio and
514
+ // video tracks unless the MIME string declares the audio codec too. Chromium
515
+ // and Safari accept the video-only form and silently pick Opus/AAC. We keep
516
+ // both variants and always prefer the codec-complete ones in
517
+ // getSupportedMimeType so a single code path works across browsers.
512
518
  var MIME_TYPE = {
513
519
  mp4: "video/mp4",
514
- webmH264: "video/webm;codecs=h264"
520
+ webmH264Opus: "video/webm;codecs=h264,opus",
521
+ webmH264: "video/webm;codecs=h264",
522
+ webmVp9Opus: "video/webm;codecs=vp9,opus",
523
+ webmVp9: "video/webm;codecs=vp9",
524
+ webmVp8Opus: "video/webm;codecs=vp8,opus",
525
+ webmVp8: "video/webm;codecs=vp8",
526
+ webm: "video/webm"
515
527
  };
516
528
 
529
+ // Picks the best MediaRecorder MIME type the current browser supports.
530
+ // Chromium produces H.264-in-WebM, Safari only produces MP4, and Firefox
531
+ // produces VP9/VP8-in-WebM. Returns null if none of the candidates are
532
+ // supported so callers can surface an "unsupported browser" state.
517
533
  var getSupportedMimeType = function getSupportedMimeType() {
518
- return MIME_TYPE.webmH264;
534
+ var _candidates$find;
535
+ if (typeof MediaRecorder === "undefined") return null;
536
+
537
+ // Safari only exposes a working MediaRecorder for MP4.
538
+ if (IS_SAFARI && MediaRecorder.isTypeSupported(MIME_TYPE.mp4)) {
539
+ return MIME_TYPE.mp4;
540
+ }
541
+
542
+ // Prefer types that declare the audio codec explicitly. Firefox requires
543
+ // this when the MediaStream has both audio and video tracks; Chromium and
544
+ // Safari are happy with either form.
545
+ var candidates = [MIME_TYPE.webmH264Opus, MIME_TYPE.webmVp9Opus, MIME_TYPE.webmVp8Opus, MIME_TYPE.webmH264, MIME_TYPE.webmVp9, MIME_TYPE.webmVp8, MIME_TYPE.webm, MIME_TYPE.mp4];
546
+ return (_candidates$find = candidates.find(function (type) {
547
+ return MediaRecorder.isTypeSupported(type);
548
+ })) !== null && _candidates$find !== void 0 ? _candidates$find : null;
519
549
  };
520
550
 
521
551
  var formatTime = function formatTime(time) {
@@ -1251,7 +1281,9 @@ var FailedToStart = withT(function (_ref) {
1251
1281
  var getAnalyser = function getAnalyser() {
1252
1282
  var _screenRecorder$getAu;
1253
1283
  var stream = (_screenRecorder$getAu = screenRecorder.getAudioStream) === null || _screenRecorder$getAu === void 0 ? void 0 : _screenRecorder$getAu.call(screenRecorder);
1254
- if (!stream) return null;
1284
+ if (!stream) {
1285
+ return null;
1286
+ }
1255
1287
  var ctx = new (window.AudioContext || window.webkitAudioContext)();
1256
1288
  var source = ctx.createMediaStreamSource(stream);
1257
1289
  var analyser = ctx.createAnalyser();
@@ -1337,8 +1369,7 @@ var useAudioIsCapturing = function useAudioIsCapturing(_ref) {
1337
1369
  useEffect(function () {
1338
1370
  if (!isMicOn || !timerStarted || disable) return noop;
1339
1371
  var analyserObj = null;
1340
- var rafId;
1341
- var loop = function loop() {
1372
+ var checkAudio = function checkAudio() {
1342
1373
  if (!analyserObj) analyserObj = getAnalyser();
1343
1374
  // if no stream yet or analyser failed, treat as silence
1344
1375
  var isSilent = !analyserObj ? true : function () {
@@ -1355,11 +1386,13 @@ var useAudioIsCapturing = function useAudioIsCapturing(_ref) {
1355
1386
  remainingRef.current = MIC_NOT_WORKING_SILENCE_TIMEOUT;
1356
1387
  if (!hasAudio) setHasAudio(true);
1357
1388
  }
1358
- rafId = requestAnimationFrame(loop);
1359
1389
  };
1360
- loop();
1390
+
1391
+ // Use interval polling instead of rAF so this keeps running in inactive tabs.
1392
+ checkAudio();
1393
+ var intervalId = setInterval(checkAudio, 1000);
1361
1394
  return function () {
1362
- cancelAnimationFrame(rafId);
1395
+ clearInterval(intervalId);
1363
1396
  clearTimer();
1364
1397
  if (analyserObj) {
1365
1398
  analyserObj.source.disconnect();
@@ -1648,7 +1681,7 @@ var useRecorderStore = screenRecorder.useRecorderStore,
1648
1681
  restartRecording = screenRecorder.restartRecording,
1649
1682
  discardRecording = screenRecorder.discardRecording;
1650
1683
  var globalProps = ((_window = window) === null || _window === void 0 ? void 0 : _window.globalProps) || {};
1651
- var MediaRecorder = function MediaRecorder(_ref, ref) {
1684
+ var MediaRecorder$1 = function MediaRecorder(_ref, ref) {
1652
1685
  var _ref$onUploadComplete = _ref.onUploadComplete,
1653
1686
  onUploadComplete = _ref$onUploadComplete === void 0 ? noop : _ref$onUploadComplete,
1654
1687
  _ref$onDiscard = _ref.onDiscard,
@@ -2073,7 +2106,7 @@ var MediaRecorder = function MediaRecorder(_ref, ref) {
2073
2106
  })]
2074
2107
  });
2075
2108
  };
2076
- var index = /*#__PURE__*/forwardRef(MediaRecorder);
2109
+ var index = /*#__PURE__*/forwardRef(MediaRecorder$1);
2077
2110
 
2078
2111
  export { index as MediaRecorder };
2079
2112
  //# sourceMappingURL=index.js.map