@100mslive/roomkit-react 0.3.7 → 0.3.8-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,11 +38,11 @@ import {
38
38
  useRoomLayoutHeader,
39
39
  useSidepaneToggle,
40
40
  useTheme
41
- } from "./chunk-VKO5HF7B.js";
41
+ } from "./chunk-NDLMRKFR.js";
42
42
 
43
43
  // src/Prebuilt/layouts/HLSView.jsx
44
44
  init_define_process_env();
45
- import React15, { useCallback as useCallback2, useEffect as useEffect3, useRef, useState as useState4 } from "react";
45
+ import React15, { useCallback as useCallback3, useEffect as useEffect3, useRef, useState as useState4 } from "react";
46
46
  import { useFullscreen, useMedia as useMedia4, usePrevious, useToggle } from "react-use";
47
47
  import { HLSPlaybackState, HMSHLSPlayer, HMSHLSPlayerEvents as HMSHLSPlayerEvents2 } from "@100mslive/hls-player";
48
48
  import screenfull from "screenfull";
@@ -427,6 +427,15 @@ function getDurationFromSeconds2(timeInSeconds) {
427
427
  }
428
428
  return videoTimeStr;
429
429
  }
430
+ function getDuration(videoEl) {
431
+ if (isFinite(videoEl.duration)) {
432
+ return videoEl.duration;
433
+ }
434
+ if (videoEl.seekable.length > 0) {
435
+ return videoEl.seekable.end(0);
436
+ }
437
+ return 0;
438
+ }
430
439
 
431
440
  // src/Prebuilt/components/HMSVideo/VideoProgress.tsx
432
441
  var VideoProgress = ({
@@ -438,15 +447,15 @@ var VideoProgress = ({
438
447
  const [bufferProgress, setBufferProgress] = useState(0);
439
448
  const videoEl = hlsPlayer2 == null ? void 0 : hlsPlayer2.getVideoElement();
440
449
  const setProgress = useCallback(() => {
441
- var _a, _b;
450
+ var _a;
442
451
  if (!videoEl) {
443
452
  return;
444
453
  }
445
- const duration = isFinite(videoEl.duration) ? videoEl.duration : ((_a = videoEl.seekable) == null ? void 0 : _a.end(0)) || 0;
454
+ const duration = getDuration(videoEl);
446
455
  const videoProgress2 = Math.floor(getPercentage(videoEl.currentTime, duration));
447
456
  let bufferProgress2 = 0;
448
457
  if (videoEl.buffered.length > 0) {
449
- bufferProgress2 = Math.floor(getPercentage((_b = videoEl.buffered) == null ? void 0 : _b.end(0), duration));
458
+ bufferProgress2 = Math.floor(getPercentage((_a = videoEl.buffered) == null ? void 0 : _a.end(0), duration));
450
459
  }
451
460
  if (!isNaN(videoProgress2)) {
452
461
  setVideoProgress(videoProgress2);
@@ -465,6 +474,7 @@ var VideoProgress = ({
465
474
  if (!videoEl) {
466
475
  return;
467
476
  }
477
+ setProgress();
468
478
  videoEl.addEventListener("timeupdate", timeupdateHandler);
469
479
  return function cleanup() {
470
480
  videoEl == null ? void 0 : videoEl.removeEventListener("timeupdate", timeupdateHandler);
@@ -523,28 +533,36 @@ var VideoProgress = ({
523
533
 
524
534
  // src/Prebuilt/components/HMSVideo/VideoTime.tsx
525
535
  init_define_process_env();
526
- import React8, { useEffect as useEffect2, useState as useState2 } from "react";
536
+ import React8, { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
527
537
  import { HMSHLSPlayerEvents } from "@100mslive/hls-player";
528
538
  var VideoTime = () => {
529
539
  const { hlsPlayer: hlsPlayer2 } = useHMSPlayerContext();
530
- const [videoTime, setVideoTime] = useState2("");
531
- useEffect2(() => {
532
- const timeupdateHandler = (currentTime) => {
540
+ const [videoTime, setVideoTime] = useState2(getDurationFromSeconds2(0));
541
+ const updateTime = useCallback2(
542
+ (currentTime) => {
533
543
  const videoEl = hlsPlayer2 == null ? void 0 : hlsPlayer2.getVideoElement();
534
544
  if (videoEl) {
535
- const duration = isFinite(videoEl.duration) ? videoEl.duration : videoEl.seekable.end(0) || 0;
545
+ const duration = getDuration(videoEl);
536
546
  setVideoTime(getDurationFromSeconds2(duration - currentTime));
537
547
  } else {
538
548
  setVideoTime(getDurationFromSeconds2(currentTime));
539
549
  }
550
+ },
551
+ [hlsPlayer2]
552
+ );
553
+ useEffect2(() => {
554
+ const timeupdateHandler = (currentTime) => {
555
+ updateTime(currentTime);
540
556
  };
541
557
  if (hlsPlayer2) {
542
558
  hlsPlayer2.on(HMSHLSPlayerEvents.CURRENT_TIME, timeupdateHandler);
559
+ const videoEl = hlsPlayer2 == null ? void 0 : hlsPlayer2.getVideoElement();
560
+ updateTime(videoEl.currentTime);
543
561
  }
544
562
  return function cleanup() {
545
563
  hlsPlayer2 == null ? void 0 : hlsPlayer2.off(HMSHLSPlayerEvents.CURRENT_TIME, timeupdateHandler);
546
564
  };
547
- }, [hlsPlayer2]);
565
+ }, [hlsPlayer2, updateTime]);
548
566
  return hlsPlayer2 ? /* @__PURE__ */ React8.createElement(
549
567
  Text,
550
568
  {
@@ -1099,7 +1117,7 @@ var HLSView = () => {
1099
1117
  videoElem == null ? void 0 : videoElem.removeEventListener("ended", setStreamEndedCallback);
1100
1118
  };
1101
1119
  }, [hlsUrl]);
1102
- const handleQuality = useCallback2(
1120
+ const handleQuality = useCallback3(
1103
1121
  (quality) => {
1104
1122
  var _a2;
1105
1123
  if (hlsPlayer) {
@@ -1265,7 +1283,7 @@ var HLSView = () => {
1265
1283
  }
1266
1284
  };
1267
1285
  }, [controlsVisible, isFullScreen, seekProgress, qualityDropDownOpen]);
1268
- const onSeekTo = useCallback2(
1286
+ const onSeekTo = useCallback3(
1269
1287
  (seek) => {
1270
1288
  var _a2;
1271
1289
  match({ isLandscape, isMobile, seek }).with({ seek: -10, isMobile: false, isLandscape: false }, () => {
@@ -1287,7 +1305,7 @@ var HLSView = () => {
1287
1305
  },
1288
1306
  [hoverControlsVisible, isLandscape, isMobile]
1289
1307
  );
1290
- const onDoubleClickHandler = useCallback2(
1308
+ const onDoubleClickHandler = useCallback3(
1291
1309
  (event) => {
1292
1310
  var _a2;
1293
1311
  if (!(isMobile || isLandscape) || ((_a2 = hlsState == null ? void 0 : hlsState.variants[0]) == null ? void 0 : _a2.playlist_type) !== HLSPlaylistType.DVR) {
@@ -1314,7 +1332,7 @@ var HLSView = () => {
1314
1332
  },
1315
1333
  [hlsState == null ? void 0 : hlsState.variants, hoverControlsVisible, isLandscape, isMobile, onSeekTo]
1316
1334
  );
1317
- const onClickHandler = useCallback2(() => __async(void 0, null, function* () {
1335
+ const onClickHandler = useCallback3(() => __async(void 0, null, function* () {
1318
1336
  var _a2;
1319
1337
  match({ isMobile, isLandscape, playlist_type: (_a2 = hlsState == null ? void 0 : hlsState.variants[0]) == null ? void 0 : _a2.playlist_type }).with({ playlist_type: HLSPlaylistType.DVR, isMobile: false, isLandscape: false }, () => __async(void 0, null, function* () {
1320
1338
  if (isPaused) {
@@ -1332,7 +1350,7 @@ var HLSView = () => {
1332
1350
  }
1333
1351
  ).otherwise(() => null);
1334
1352
  }), [hlsState == null ? void 0 : hlsState.variants, isLandscape, isMobile, isPaused]);
1335
- const onHoverHandler = useCallback2(
1353
+ const onHoverHandler = useCallback3(
1336
1354
  (event) => {
1337
1355
  event.preventDefault();
1338
1356
  if (isMobile || isLandscape) {
@@ -1600,4 +1618,4 @@ var HLSView_default = HLSView;
1600
1618
  export {
1601
1619
  HLSView_default as default
1602
1620
  };
1603
- //# sourceMappingURL=HLSView-J76FQQDB.js.map
1621
+ //# sourceMappingURL=HLSView-CTZXD762.js.map