UNPKG

vnetwork-player

Version:

A React component custom player support video m3u8, mp4

3 lines (2 loc) 32.5 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=require("@tanstack/react-hotkeys");function l(){return(l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function o(e,t){return(o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function a(e,t){if(null==e)return{};var n,r,l={},o=Object.keys(e);for(r=0;r<o.length;r++)t.indexOf(n=o[r])>=0||(l[n]=e[n]);return l}var c=function(e){var t,r;function l(){var t;return(t=e.apply(this,arguments)||this).state={hasError:!1,message:""},t}r=e,(t=l).prototype=Object.create(r.prototype),t.prototype.constructor=t,o(t,r),l.getDerivedStateFromError=function(e){return{message:e.message,hasError:!0}};var a=l.prototype;return a.componentDidCatch=function(e,t){console.error("Uncaught error:",e,t)},a.render=function(){return this.state.hasError?n.createElement("div",{className:"video-container error-container"},n.createElement("img",{className:"error-image",src:"https://raw.githubusercontent.com/an678-mhg/tiktok-clone/main/public/error.png"}),n.createElement("h1",{className:"text-sm font-semibold error-message line-clamp-1"},n.createElement("span",{style:{color:"#fff"}},"Error: ")," ",this.state.message)):this.props.children},l}(t.Component),u=function(e){try{var t=new Date(0);t.setSeconds(e);var n=t.toISOString().slice(11,19);return n.startsWith("00:0")?n.slice(4):n.startsWith("00")?n.slice(3):8===n.length&&n.startsWith("0")?n.slice(1):n}catch(e){return"0:00"}},i=[{label:"0.25x",value:.25},{label:"0.5x",value:.5},{label:"0.75x",value:.75},{label:"1x",value:1},{label:"1.25x",value:1.25},{label:"1.5x",value:1.5},{label:"2x",value:2}],s=["fullscreenchange","mozfullscreenchange","webkitfullscreenchange","MSFullscreenChange"],m=function(e){return void 0===e&&(e=document),e.fullscreenElement||e.mozFullScreenElement||e.webkitFullscreenElement||e.msFullscreenElement||null},d=function(e){void 0===e&&(e=document),e.pictureInPictureElement&&e.exitPictureInPicture&&e.exitPictureInPicture().catch(console.error)},f={stallWindowMs:1e4,stallLimit:1,longStallMs:1500,switchCooldownMs:5e3,switchGraceMs:2e3,upgradeBufferSeconds:8,upgradeHealthyMs:8e3,checkIntervalMs:1e3},v=function(e,t){var n=null==t?void 0:t.liveSyncPosition;return"number"==typeof n&&Number.isFinite(n)?n:function(e){var t=e.seekable,n=t.length;if(!n)return null;var r=n-1,l=t.end(r),o=t.start(r);return Number.isFinite(l)?Math.max(o,l-.5):null}(e)},p=function(e,t){return!(!e||t<e.start||t>=e.end)},E=["children"];function g(e){var n=e.children,r=a(e,E);return t.createElement("svg",Object.assign({viewBox:"0 0 24 24",fill:"none",height:"1em",width:"1em","aria-hidden":"true",focusable:"false"},r),n)}function h(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M8 5.9c0-1.2 1.4-2 2.5-1.3l8.8 5.9c1 .7 1 2.1 0 2.8l-8.8 5.9C9.4 20 8 19.2 8 18z"}))}function b(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.6,d:"M4.5 9.5v-5h5m5 0h5v5m0 5v5h-5m-5 0h-5v-5"}))}function y(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M8.2 4.2c.7 0 1.2.5 1.2 1.2v3.2h3.2c.7 0 1.2.5 1.2 1.2s-.5 1.2-1.2 1.2H8.1c-.6 0-1.1-.5-1.1-1.1V5.4c0-.7.5-1.2 1.2-1.2m7.6 0c.7 0 1.2.5 1.2 1.2v4.5c0 .6-.5 1.1-1.1 1.1h-4.5c-.7 0-1.2-.5-1.2-1.2s.5-1.2 1.2-1.2h3.2V5.4c0-.7.5-1.2 1.2-1.2M7 14.1c0-.6.5-1.1 1.1-1.1h4.5c.7 0 1.2.5 1.2 1.2s-.5 1.2-1.2 1.2H9.4v3.2c0 .7-.5 1.2-1.2 1.2S7 19.3 7 18.6zm4.4-1.1h4.5c.6 0 1.1.5 1.1 1.1v4.5c0 .7-.5 1.2-1.2 1.2s-1.2-.5-1.2-1.2v-3.2h-3.2c-.7 0-1.2-.5-1.2-1.2s.5-1.2 1.2-1.2"}))}function S(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M6.2 5.2c0-.7.5-1.2 1.2-1.2h2.7c.7 0 1.2.5 1.2 1.2v13.6c0 .7-.5 1.2-1.2 1.2H7.4c-.7 0-1.2-.5-1.2-1.2zm6.5 0c0-.7.5-1.2 1.2-1.2h2.7c.7 0 1.2.5 1.2 1.2v13.6c0 .7-.5 1.2-1.2 1.2h-2.7c-.7 0-1.2-.5-1.2-1.2z"}))}function k(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M9.8 2.8a1.3 1.3 0 0 1 1.3-1.1h1.8a1.3 1.3 0 0 1 1.3 1.1l.3 1.8c.7.3 1.4.7 2 1.1l1.7-.6a1.3 1.3 0 0 1 1.6.6l.9 1.6a1.3 1.3 0 0 1-.3 1.7L19 10.2a8 8 0 0 1 0 2.4l1.4 1.2c.5.4.6 1.1.3 1.7l-.9 1.6c-.3.6-1 .8-1.6.6l-1.7-.6c-.6.5-1.3.8-2 1.1l-.3 1.8a1.3 1.3 0 0 1-1.3 1.1h-1.8A1.3 1.3 0 0 1 9.8 20l-.3-1.8c-.7-.3-1.4-.7-2-1.1l-1.7.6a1.3 1.3 0 0 1-1.6-.6l-.9-1.6a1.3 1.3 0 0 1 .3-1.7L5 12.6a8 8 0 0 1 0-2.4L3.6 9a1.3 1.3 0 0 1-.3-1.7l.9-1.6c.3-.6 1-.8 1.6-.6l1.7.6c.6-.5 1.3-.8 2-1.1zM12 15.7a3.7 3.7 0 1 0 0-7.4 3.7 3.7 0 0 0 0 7.4"}))}function N(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M4.2 8.5c-.7 0-1.2.5-1.2 1.2v4.6c0 .7.5 1.2 1.2 1.2h3l4.3 3.8c.9.8 2.3.2 2.3-1V5.7c0-1.2-1.4-1.8-2.3-1L7.2 8.5zM16.5 7.1a1.1 1.1 0 0 0-.2 1.5 5.3 5.3 0 0 1 0 6.8 1.1 1.1 0 0 0 .2 1.5c.5.4 1.2.3 1.6-.2a7.6 7.6 0 0 0 0-9.4 1.1 1.1 0 0 0-1.6-.2m3.2-2.4a1.1 1.1 0 0 0-.2 1.5 9.5 9.5 0 0 1 0 11.6 1.1 1.1 0 0 0 .2 1.5c.5.4 1.2.3 1.6-.2a11.8 11.8 0 0 0 0-14.2 1.1 1.1 0 0 0-1.6-.2"}))}function C(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M4.2 8.5c-.7 0-1.2.5-1.2 1.2v4.6c0 .7.5 1.2 1.2 1.2h3l4.3 3.8c.9.8 2.3.2 2.3-1V5.7c0-1.2-1.4-1.8-2.3-1L7.2 8.5zm13.2.2a1.2 1.2 0 0 0-1.7 1.7l1.6 1.6-1.6 1.6a1.2 1.2 0 0 0 1.7 1.7l1.6-1.6 1.6 1.6a1.2 1.2 0 0 0 1.7-1.7L20.7 12l1.6-1.6a1.2 1.2 0 0 0-1.7-1.7L19 10.3z"}))}function w(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M4.8 4h14.4C20.7 4 22 5.3 22 6.8v10.4c0 1.5-1.3 2.8-2.8 2.8H4.8A2.8 2.8 0 0 1 2 17.2V6.8C2 5.3 3.3 4 4.8 4m1 3.2c-.3 0-.6.3-.6.6v8.4c0 .3.3.6.6.6h5.9v-4.6c0-1.3 1-2.3 2.3-2.3h5.8V7.8c0-.3-.3-.6-.6-.6zm8.1 9.7h5.2c.4 0 .7-.3.7-.7v-3.9h-5.2c-.4 0-.7.3-.7.7z"}))}function M(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"m15.8 5.2-6.8 6.8 6.8 6.8"}))}function P(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"m8.2 5.2 6.8 6.8-6.8 6.8"}))}function L(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",d:"M12 3.5a9.5 9.5 0 0 0-8.7 13.3c.4.8 1.2 1.2 2 1.2h13.4c.8 0 1.6-.5 2-1.2A9.5 9.5 0 0 0 12 3.5m5.5 6.3-4.2 5a2.3 2.3 0 1 1-1.9-1.1l4.8-4.4c.8-.8 2 .4 1.3 1.2"}))}function x(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M4.7 4.5h14.6c1 0 1.7.8 1.7 1.7v11.6c0 1-.8 1.7-1.7 1.7H4.7c-1 0-1.7-.8-1.7-1.7V6.2c0-1 .8-1.7 1.7-1.7m2.5 4.2c-.7 0-1.2.5-1.2 1.2v4.2c0 .7.5 1.2 1.2 1.2s1.2-.5 1.2-1.2V13h2.4v1.1c0 .7.5 1.2 1.2 1.2s1.2-.5 1.2-1.2V9.9c0-.7-.5-1.2-1.2-1.2s-1.2.5-1.2 1.2V11H8.4V9.9c0-.7-.5-1.2-1.2-1.2m8.9 0c-.7 0-1.2.5-1.2 1.2v4.2c0 .7.5 1.2 1.2 1.2h1c1.8 0 3-1.3 3-3.3s-1.2-3.3-3-3.3zm1.2 2.2c.3 0 .5.4.5 1.1s-.2 1.1-.5 1.1h-.1v-2.2z"}))}function T(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"currentColor",fillRule:"evenodd",d:"M4.8 5h14.4C20.7 5 22 6.3 22 7.8v8.4c0 1.5-1.3 2.8-2.8 2.8H4.8A2.8 2.8 0 0 1 2 16.2V7.8C2 6.3 3.3 5 4.8 5M7.6 11.2h2.8a1.1 1.1 0 1 0 0-2.2H7.6A2.6 2.6 0 0 0 5 11.6v.8A2.6 2.6 0 0 0 7.6 15h2.8a1.1 1.1 0 1 0 0-2.2H7.6a.4.4 0 0 1-.4-.4v-.8c0-.2.2-.4.4-.4m7.2 0h2.6a1.1 1.1 0 1 0 0-2.2h-2.6a2.6 2.6 0 0 0-2.6 2.6v.8a2.6 2.6 0 0 0 2.6 2.6h2.6a1.1 1.1 0 1 0 0-2.2h-2.6a.4.4 0 0 1-.4-.4v-.8c0-.2.2-.4.4-.4"}))}function O(e){return t.createElement(g,Object.assign({},e),t.createElement("path",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"m5.2 12.2 4.3 4.2 9.3-9.3"}))}var z=function(e){var t=e.setSettingsType,r=e.currentQuality,l=e.currentSpeed,o=e.currentSubtitle,a=e.haveQuality,c=e.haveSubtitle;return n.createElement("div",{className:"opacity-animation settings-content scale-in-bl w-full",onClick:function(e){return e.stopPropagation()}},n.createElement("div",{onClick:function(){return t("playspeed")},className:"main-settings cursor-pointer "},n.createElement("div",{className:"main-settings-content"},n.createElement(L,{fontSize:20,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Play speed")),n.createElement("div",{className:"main-settings-content"},n.createElement("p",{className:"text-sm font-semibold line-clamp-1 mr-3"},l),n.createElement(P,{fontSize:20}))),a&&n.createElement("div",{onClick:function(){return t("quality")},className:"main-settings-content justify-between cursor-pointer p-2 "},n.createElement("div",{className:"main-settings-content"},n.createElement(x,{fontSize:22,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Quality")),n.createElement("div",{className:"main-settings-content"},n.createElement("p",{className:"text-sm font-semibold line-clamp-1 mr-3"},r),n.createElement(P,{fontSize:20}))),c&&n.createElement("div",{onClick:function(){return t("subtitle")},className:"main-settings-content justify-between cursor-pointer p-2"},n.createElement("div",{className:"main-settings-content"},n.createElement(T,{fontSize:22,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Subtitle")),n.createElement("div",{className:"main-settings-content"},n.createElement("p",{className:"text-sm font-semibold line-clamp-1 mr-3"},o),n.createElement(P,{fontSize:20}))))},j=function(e){var t=e.setSettingsType,r=e.currentPlaySpeed,l=e.handleChangePlaySpeed;return n.createElement("div",{className:"opacity-animation settings-content scale-in-bl w-full",onClick:function(e){return e.stopPropagation()}},n.createElement("div",{onClick:function(e){e.stopPropagation(),t("main")},className:"main-settings-content p-2 cursor-pointer"},n.createElement(M,{fontSize:20,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Play speed")),n.createElement("div",null,null==i?void 0:i.map((function(e,t){return n.createElement("div",{className:"p-2 text-sm font-semibold main-settings-content cursor-pointer",key:null==e?void 0:e.value,onClick:function(){return l(t,null==e?void 0:e.value)}},n.createElement("div",{className:"icon-20px mr-3"},r===t&&n.createElement(O,{fontSize:20})),n.createElement("p",null,null==e?void 0:e.label))}))))},I=function(e){var t,r=e.setSettingsType,l=e.source,o=e.currentSource,a=e.handleChangeSource,c=e.autoQuality,u=e.handleSelectAutoQuality,i=(null==l?void 0:l.length)>1;return n.createElement("div",{className:"overflow-y-auto opacity-animation settings-content scale-in-bl w-full",onClick:function(e){return e.stopPropagation()}},n.createElement("div",{onClick:function(e){e.stopPropagation(),r("main")},className:"main-settings-content p-2 cursor-pointer"},n.createElement(M,{fontSize:20,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Quality")),n.createElement("div",null,i&&n.createElement("div",{onClick:u,className:"p-2 text-sm font-semibold main-settings-content cursor-pointer"},n.createElement("div",{className:"icon-20px mr-3"},c&&n.createElement(O,{fontSize:20})),n.createElement("p",null,c?"Auto ("+(null==l||null==(t=l[o])?void 0:t.label)+")":"Auto")),null==l?void 0:l.map((function(e,t){return n.createElement("div",{onClick:function(){return a(t)},className:"p-2 text-sm font-semibold main-settings-content cursor-pointer",key:null==e?void 0:e.url},n.createElement("div",{className:"icon-20px mr-3"},!c&&o===t&&n.createElement(O,{fontSize:20})),n.createElement("p",null,null==e?void 0:e.label))}))))},A=function(e){var t=e.currentSubtitle,r=e.handleChangeSubtitle,l=e.setSettingsType,o=e.subtitle,a=e.handleTurnOffSubtitle;return n.createElement("div",{className:"overflow-y-auto opacity-animation settings-content scale-in-bl w-full",onClick:function(e){return e.stopPropagation()}},n.createElement("div",{onClick:function(e){e.stopPropagation(),l("main")},className:"main-settings-content p-2 cursor-pointer"},n.createElement(M,{fontSize:20,className:"mr-3"}),n.createElement("p",{className:"text-sm font-semibold"},"Subtitle")),n.createElement("div",null,n.createElement("div",{onClick:a,className:"p-2 text-sm font-semibold main-settings-content cursor-pointer"},n.createElement("div",{className:"icon-20px mr-3"},null===t&&n.createElement(O,{fontSize:20})),n.createElement("p",null,"Off")),null==o?void 0:o.map((function(e,l){return n.createElement("div",{onClick:function(){return r(l)},className:"p-2 text-sm font-semibold main-settings-content cursor-pointer",key:null==e?void 0:e.url},n.createElement("div",{className:"icon-20px mr-3"},t===l&&n.createElement(O,{fontSize:20})),n.createElement("p",null,null==e?void 0:e.lang))}))))},D=function(){return n.createElement("svg",{viewBox:"25 25 50 50",className:"loading"},n.createElement("circle",{cx:"50",cy:"50",r:"20"}))},F=function(e){var r=e.value,l=e.onChange,o=e.min,a=void 0===o?0:o,c=e.max,u=void 0===c?100:c,i=e.className,s=void 0===i?"":i,m=e.color,d=void 0===m?"#ef4444":m,f=e.trackColor,v=e.buffered,p=void 0===v?[]:v,E=e.bufferedColor,g=void 0===E?"rgba(255, 255, 255, 0.75)":E,h=e.live,b=void 0!==h&&h,y=e.markers,S=void 0===y?[]:y,k=e.onDragEnd,N=e.onPreview,C=e.children,w=void 0===C?n.createElement(n.Fragment,null):C,M=t.useRef(null),P=t.useState(!1),L=P[0],x=P[1],T=function(e){if(M.current&&!b){var t=M.current.getBoundingClientRect();return Math.min(Math.max((e-t.left)/t.width*(u-a)+a,a),u)}},O=function(e){var t=T(e);l(t)},z=function(e){L&&O(e)},j=function(){x(!1),k&&k(),document.body.style.userSelect="auto"},I=function(e){b||(x(!0),O(e)),document.body.style.userSelect="none"};t.useEffect((function(){if(L){var e=function(e){return z(e.clientX)},t=function(e){return z(e.touches[0].clientX)};return document.addEventListener("mousemove",e),document.addEventListener("touchmove",t),document.addEventListener("mouseup",j),document.addEventListener("touchend",j),function(){document.removeEventListener("mousemove",e),document.removeEventListener("touchmove",t),document.removeEventListener("mouseup",j),document.removeEventListener("touchend",j),k&&k()}}}),[L]);var A=u-a,D=Number.isFinite(A)&&A>0,F=D?(r-a)/A*100:0,R=!b&&D?S:[];return n.createElement("div",{ref:M,className:"progress-vnet "+s,onClick:function(e){return O(e.clientX)},onMouseDown:function(e){return I(e.clientX)},onTouchStart:function(e){return I(e.touches[0].clientX)},onMouseMove:function(e){return r=T(t=e.clientX),l=null==(n=M.current)?void 0:n.getBoundingClientRect(),void(N&&N(r,(t-(null==l?void 0:l.left))/(null==l?void 0:l.width)));var t,n,r,l},onMouseLeave:function(){N&&N(null,null),k&&k()}},n.createElement("div",{className:"progress-gray",style:f?{backgroundColor:f}:void 0},(!b&&D?p:[]).map((function(e,t){var r=Math.max(e.start,a),l=Math.min(e.end,u);return l<=r?null:n.createElement("div",{key:"buffered-"+t,className:"progress-buffered",style:{left:(r-a)/A*100+"%",width:(l-r)/A*100+"%",backgroundColor:g}})})),R.map((function(e){var t=Math.max(e.start,a),r=Math.min(e.end,u);return r<=t?null:n.createElement("div",{key:e.label+"-"+e.start+"-"+e.end,className:"progress-marker",style:{left:(t-a)/A*100+"%",width:(r-t)/A*100+"%",backgroundColor:e.color||d},onMouseEnter:function(){return N&&N(null,null)},onMouseMove:function(e){e.stopPropagation(),N&&N(null,null)},onMouseDown:function(e){return e.stopPropagation()},onTouchStart:function(e){return e.stopPropagation()}},n.createElement("span",{className:"progress-marker-tooltip"},e.label))})),n.createElement("div",{className:"progress-main",style:{width:b?"100%":F+"%",backgroundColor:d}})),w,!b&&n.createElement("div",{className:"progress-dot",style:{backgroundColor:d,left:"calc("+F+"% - 5px)"}}))},R=["color","trackColor","bufferedColor","subtitle","playerRef","className","poster","videoTitle","videoDescription","source","live","autoPlay","autoUnmuteDelay","startIntro","endIntro","introColor","startOutro","endOutro","outroColor","autoQualityConfig","Hls"],H=function(e){var o,c,E,g,M,P,L,x,T,O=e.color,H=e.trackColor,q=e.bufferedColor,V=e.subtitle,_=e.playerRef,Q=e.className,W=e.poster,B=e.videoTitle,U=e.videoDescription,X=e.source,J=e.live,G=e.autoPlay,Y=e.autoUnmuteDelay,K=e.startIntro,Z=e.endIntro,$=e.introColor,ee=e.startOutro,te=e.endOutro,ne=e.outroColor,re=e.autoQualityConfig,le=e.Hls,oe=a(e,R),ae=t.useRef(null);if(!X)throw ae.current&&(null==(T=ae.current)||T.destroy()),new Error("Missing src props");var ce=X,ue=t.useRef(null),ie=t.useRef(null),se=t.useRef(null),me=t.useState(0),de=me[0],fe=me[1],ve=t.useState([]),pe=ve[0],Ee=ve[1],ge=t.useState(!0),he=ge[0],be=ge[1],ye=t.useRef(he);ye.current=he;var Se=t.useRef(!1),ke=t.useState(3),Ne=ke[0],Ce=ke[1],we=t.useState(!0),Me=we[0],Pe=we[1],Le=t.useState(!1),xe=Le[0],Te=Le[1],Oe=t.useState(0),ze=Oe[0],je=Oe[1],Ie=t.useState(!1),Ae=Ie[0],De=Ie[1],Fe=t.useState((function(){return JSON.parse(localStorage.getItem("vnetwork-player-muted"))||!1})),Re=Fe[0],He=Fe[1],qe=t.useState(!0),Ve=qe[0],_e=qe[1],Qe=t.useState(!1),We=Qe[0],Be=Qe[1],Ue=t.useState("main"),Xe=Ue[0],Je=Ue[1],Ge=t.useState(0),Ye=Ge[0],Ke=Ge[1],Ze=t.useState((function(){return Number(localStorage.getItem("vnetwork-player-volume"))||100})),$e=Ze[0],et=Ze[1],tt=t.useState(!1),nt=tt[0],rt=tt[1],lt=t.useState({time:null,left:null}),ot=lt[0],at=lt[1],ct=t.useState(0),ut=ct[0],it=ct[1],st=t.useState([]),mt=st[0],dt=st[1],ft="string"==typeof ce?ce:null==ce||null==(o=ce.map((function(e){return null==e?void 0:e.url})))?void 0:o.join("|"),vt=O||"#ef4444",pt=$||"#f59e0b",Et=ne||"#8b5cf6",gt=_||ie,ht=Boolean(B||U),bt=J&&ut>2,yt=function(e,t){return"number"!=typeof e||"number"!=typeof t?null:{start:e,end:t,label:"Skip intro"}}(K,Z),St=function(e,t){return"number"!=typeof e||"number"!=typeof t?null:{start:e,end:t,label:"Skip outro"}}(ee,te),kt=p(yt,ze)?yt:p(St,ze)?St:null,Nt=null==(c=gt.current)?void 0:c.duration,Ct=!J&&"number"==typeof Nt&&Number.isFinite(Nt)?[yt,St].filter((function(e){return Boolean(e)})).map((function(e){return l({},e,{color:"Skip intro"===e.label?pt:Et})})):[],wt=function(){if(J&&gt.current){var e=v(gt.current,ae.current);it(null!==e?Math.max(0,e-gt.current.currentTime):0)}else it(0)},Mt=function(){Te((function(e){return!e}))},Pt=function(){var e;ue.current&&(e=ue.current,d(),m()?function(e){void 0===e&&(e=document);var t=e.exitFullscreen||e.mozCancelFullScreen||e.webkitExitFullscreen||e.msExitFullscreen;null==t||t.call(e)}():function(e){var t=e.requestFullscreen||e.mozRequestFullScreen||e.webkitRequestFullscreen||e.msRequestFullscreen;null==t||t.call(e)}(e))},Lt=function(){He((function(e){return!e})),localStorage.setItem("vnetwork-player-muted",JSON.stringify(!Re))},xt=function(e){var t;if(null!=gt&&gt.current)if(fe(e),null!=ae&&ae.current&&Se.current)ae.current.currentLevel=e;else{var n=null==gt||null==(t=gt.current)?void 0:t.querySelector("track");n&&n.remove();var r=gt.current.currentTime||ze;if(null!=ae&&ae.current){var l,o=null==ae?void 0:ae.current;o.startLevel=e,o.loadSource(null==pe||null==(l=pe[e])?void 0:l.url),o.startLoad()}else{var a,c;null==gt||null==(a=gt.current)||a.setAttribute("src",null==pe||null==(c=pe[e])?void 0:c.url)}je(r),null!==gt&&null!==(null==gt?void 0:gt.current)&&(gt.current.currentTime=r,gt.current.play())}},Tt=function(e){null!==gt&&null!==(null==gt?void 0:gt.current)&&(rt(!0),et(e),localStorage.setItem("vnetwork-player-volume",JSON.stringify(e)),gt.current.volume=e/100)},Ot=function(){at({time:null,left:null}),rt(!1)};return t.useEffect((function(){null!==gt&&null!==(null==gt?void 0:gt.current)&&(gt.current.volume=($e<=0?0:$e)/100)}),[$e]),t.useEffect((function(){if(J&&gt.current){var e=gt.current,t=function(){return wt()};e.addEventListener("progress",t),e.addEventListener("loadedmetadata",t);var n=window.setInterval(t,1e3);return t(),function(){e.removeEventListener("progress",t),e.removeEventListener("loadedmetadata",t),window.clearInterval(n)}}it(0)}),[J,ft,de]),t.useEffect((function(){if(gt.current){var e=gt.current,t="",n=function(){for(var n=e.buffered,r=[],l="",o=0;o<n.length;o++){var a=n.start(o),c=n.end(o);r.push({start:a,end:c}),l+=a.toFixed(1)+":"+c.toFixed(1)+";"}l!==t&&(t=l,dt(r))},r=function(){t="",dt([])};return e.addEventListener("progress",n),e.addEventListener("timeupdate",n),e.addEventListener("loadedmetadata",n),e.addEventListener("emptied",r),function(){e.removeEventListener("progress",n),e.removeEventListener("timeupdate",n),e.removeEventListener("loadedmetadata",n),e.removeEventListener("emptied",r)}}}),[ft,de]),t.useEffect((function(){if(he&&!Se.current&&!((null==pe?void 0:pe.length)<=1)&&gt.current){var e,t=l({},f,re),n=gt.current,r=[],o=0,a=Date.now(),c=function(e){o=Date.now(),r=[],xt(e)},u=function(){if(!n.seeking){var l=Date.now();o&&l-o<t.switchGraceMs||(a=l,r=[].concat(r.filter((function(e){return l-e<t.stallWindowMs})),[l]),de<=0||(r.length>=t.stallLimit?c(de-1):(e&&clearTimeout(e),e=setTimeout((function(){n.seeking||n.paused||n.readyState>=HTMLMediaElement.HAVE_FUTURE_DATA||c(de-1)}),t.longStallMs))))}},i=window.setInterval((function(){var e=Date.now();de>=pe.length-1||n.paused||n.seeking||o&&e-o<t.switchCooldownMs||e-a<t.upgradeHealthyMs||function(e){for(var t=e.buffered,n=e.currentTime,r=0;r<t.length;r++)if(t.start(r)<=n&&n<=t.end(r))return t.end(r)-n;return 0}(n)<t.upgradeBufferSeconds||c(de+1)}),t.checkIntervalMs);return n.addEventListener("waiting",u),function(){n.removeEventListener("waiting",u),window.clearInterval(i),e&&clearTimeout(e)}}}),[he,pe,de,re&&JSON.stringify(re)]),t.useEffect((function(){var e;if(!(!xe||!Me||We||nt||null!=ot&&ot.left))return e=setTimeout((function(){Pe(!1)}),3e3),function(){e&&clearTimeout(e)}}),[Me,xe,We,nt]),t.useEffect((function(){var e;return e=function(){De(Boolean(m()))},s.forEach((function(t){document.addEventListener(t,e)})),function(){s.forEach((function(t){document.removeEventListener(t,e)}))}}),[]),t.useEffect((function(){if(V&&V.length>0){var e,t,n,r;if(null===Ye)return;var l=null==gt||null==(e=gt.current)?void 0:e.querySelector("track");l&&l.remove();var o=document.createElement("track");o.src=null==V||null==(t=V[Ye])?void 0:t.url,o.label=null==V||null==(n=V[Ye])?void 0:n.lang,o.default=!0,null==gt||null==(r=gt.current)||r.appendChild(o)}}),[Ye,de]),t.useEffect((function(){var e,t,n,r,l;return"m3u8"===function(e){if(!e)return"";var t=function(e){var t;return null==(t=e.split("?"))?void 0:t[0]}(e),n=t.split("/").pop()||t,r=n.lastIndexOf(".");return-1===r?"":n.slice(r+1).toLowerCase()}("string"==typeof ce?ce:null==ce||null==(e=ce[0])?void 0:e.url)?function(){if(!le)throw Error("To use video type m3u8 try install `npm i hls.js` and pass props Hls");if(null!=gt&&gt.current){var e,t=le;if(!t.isSupported())throw Error("Not support hls");null!=ae&&ae.current&&(null==ae||null==(e=ae.current)||e.destroy()),ae.current=new t;var n,r=null==ae?void 0:ae.current;r.on(t.Events.MANIFEST_PARSED,(function(e,t){if("string"!=typeof ce)return Se.current=!1,Ee(ce);console.log((null==t?void 0:t.levels)||[]);var n=(null==t?void 0:t.levels)||[];Se.current=n.length>1,Ee(null==n?void 0:n.map((function(e){var t;return{label:(null==e?void 0:e.height)+"p",url:Array.isArray(null==e?void 0:e.url)?null==e||null==(t=e.url)?void 0:t[0]:(null==e?void 0:e.url)||""}}))),Se.current&&ye.current?(fe((function(e){return Math.max(0,Math.min(e,n.length-1))})),r.currentLevel=-1):(fe((null==n?void 0:n.length)-1),r.startLevel=(null==n?void 0:n.length)-1)})),r.on(t.Events.LEVEL_SWITCHED,(function(e,t){Se.current&&"number"==typeof(null==t?void 0:t.level)&&fe(t.level)})),r.attachMedia(null==gt?void 0:gt.current),r.loadSource("string"==typeof ce?ce:null==ce||null==(n=ce[de])?void 0:n.url),r.startLoad()}}():(null!=ae&&ae.current&&(null==ae||null==(t=ae.current)||t.destroy()),Se.current=!1,Ee("string"==typeof ce?[{label:"Default",url:ce}]:ce),"string"==typeof ce?null==gt||null==(n=gt.current)||n.setAttribute("src",ce):(fe((null==ce?void 0:ce.length)-1),null==gt||null==(r=gt.current)||r.setAttribute("src",null==ce||null==(l=ce[(null==ce?void 0:ce.length)-1])?void 0:l.url))),function(){var e;null!=ae&&ae.current&&(null==ae||null==(e=ae.current)||e.destroy(),ae.current=null)}}),[ft]),t.useEffect((function(){null!==gt&&null!==(null==gt?void 0:gt.current)&&(gt.current.muted=Re)}),[Re]),t.useEffect((function(){if(G&&gt.current){var e,t=gt.current,n=function(){t.muted=!0,He(!0),t.play().catch(console.error),"number"!=typeof Y||Y<0||(e=setTimeout((function(){gt.current&&(gt.current.muted=!1,He(!1))}),Y))};return t.muted=!0,He(!0),t.readyState>=HTMLMediaElement.HAVE_METADATA?n():t.addEventListener("loadedmetadata",n,{once:!0}),function(){t.removeEventListener("loadedmetadata",n),e&&clearTimeout(e)}}}),[G,Y,ft]),r.useHotkeys([{hotkey:"Space",callback:Mt},{hotkey:"ArrowLeft",callback:function(){gt.current&&(gt.current.currentTime-=5)}},{hotkey:"ArrowRight",callback:function(){gt.current&&(gt.current.currentTime+=5)}},{hotkey:"ArrowUp",callback:function(){return Tt(Math.min($e+5,100))}},{hotkey:"ArrowDown",callback:function(){return Tt(Math.max($e-5,0))}},{hotkey:"F",callback:Pt},{hotkey:"M",callback:Lt}],{ignoreInputs:!0,preventDefault:!0,stopPropagation:!1}),t.useEffect((function(){var e,t;xe||Pe(!0),xe?null==gt||null==(e=gt.current)||e.play():null==gt||null==(t=gt.current)||t.pause()}),[xe]),t.useEffect((function(){return function(){var e;null!=ae&&ae.current&&(null==ae||null==(e=ae.current)||e.destroy())}}),[]),n.createElement("div",{ref:ue,onMouseMove:function(){return Pe(!0)},onMouseLeave:function(){nt||We||Pe(!1)},onClick:function(){return Pe(!0)},className:"video-container"},n.createElement("video",Object.assign({ref:gt,className:"video "+(Q||""),poster:W||"",onPlay:function(){return Te(!0)},onPause:function(){return Te(!1)},onTimeUpdate:function(){var e;nt||(je((null==gt||null==(e=gt.current)?void 0:e.currentTime)||0),wt())},onCanPlay:function(){return _e(!1)},onWaiting:function(){return _e(!0)},onLoad:function(){return _e(!0)},onLoadedMetadata:function(){return _e(!0)}},oe)),Ve&&n.createElement("div",{className:"center-item-absolute"},n.createElement(D,null)),n.createElement("div",{onClick:function(e){e.stopPropagation(),e.target===e.currentTarget&&(Be(!1),Pe(!1))},style:{display:Me?"flex":"none"},className:"control-container opacity-animation"},!Ve&&n.createElement("div",{onClick:Mt,className:"center-item-absolute cursor-pointer"},n.createElement(xe?S:h,{fontSize:60})),ht&&n.createElement("div",{className:"video-meta-overlay"},B&&n.createElement("p",{className:"video-meta-title"},B),U&&n.createElement("p",{className:"video-meta-description"},U)),!J&&kt&&n.createElement("button",{type:"button",className:"skip-segment-button opacity-animation",onClick:function(e){e.stopPropagation(),kt&&gt.current&&(gt.current.currentTime=kt.end,je(kt.end),rt(!1))}},kt.label),We&&n.createElement("div",{onClick:function(e){e.stopPropagation(),e.target===e.currentTarget&&(Be(!1),Je("main"))},className:"settings-container"},n.createElement("div",{className:"w-full",onClick:function(e){return e.stopPropagation()},onMouseDown:function(e){return e.stopPropagation()},onPointerDown:function(e){return e.stopPropagation()}},"main"===Xe?n.createElement(z,{currentQuality:he&&(null==pe?void 0:pe.length)>1?"Auto ("+(null==pe||null==(E=pe[de])?void 0:E.label)+")":null==pe||null==(g=pe[de])?void 0:g.label,currentSpeed:null==i||null==(M=i[Ne])?void 0:M.label,setSettingsType:Je,currentSubtitle:"number"==typeof Ye?null==V||null==(P=V[Ye])?void 0:P.lang:"Off",haveSubtitle:Boolean(V),haveQuality:(null==ce?void 0:ce.length)>0}):"playspeed"===Xe?n.createElement(j,{handleChangePlaySpeed:function(e,t){Ce(e),null!==gt&&null!==(null==gt?void 0:gt.current)&&(gt.current.playbackRate=t),Be(!1),Je("main")},currentPlaySpeed:Ne,setSettingsType:Je}):"quality"===Xe?n.createElement(I,{handleChangeSource:function(e){null!=gt&&gt.current&&(de!==e||he)&&(be(!1),xt(e),Be(!1),Je("main"))},currentSource:de,setSettingsType:Je,source:pe,autoQuality:he,handleSelectAutoQuality:function(){be(!0),null!=ae&&ae.current&&Se.current&&(ae.current.currentLevel=-1),Be(!1),Je("main")}}):n.createElement(A,{currentSubtitle:Ye,setSettingsType:Je,handleChangeSubtitle:function(e){Ke(e),Be(!1),Je("main")},subtitle:V,handleTurnOffSubtitle:function(){var e;Ke(null);var t=null==gt||null==(e=gt.current)?void 0:e.querySelector("track");t&&t.remove(),Be(!1),Je("main")}}))),n.createElement("div",{onClick:function(e){return e.stopPropagation()},className:"w-full"},n.createElement(F,{onDragEnd:Ot,value:ze,onChange:function(e){null!==gt&&null!==(null==gt?void 0:gt.current)&&(rt(!0),je(e),se.current&&clearTimeout(se.current),se.current=setTimeout((function(){gt.current&&(gt.current.currentTime=e)}),100))},min:0,max:null==gt||null==(L=gt.current)?void 0:L.duration,markers:Ct,live:J,color:vt,trackColor:H,buffered:mt,bufferedColor:q,onPreview:function(e,t){at({time:e,left:t})},className:"tooltip-container"},!J&&Number(null==ot?void 0:ot.time)&&null!=ot&&ot.left?n.createElement("div",{style:{left:100*(null==ot?void 0:ot.left)+"%",top:-30},className:"tooltip"},n.createElement("p",null,u(Number(null==ot?void 0:ot.time)))):""),n.createElement("div",{onMouseDown:function(e){return e.stopPropagation()},className:"main-control-container"},n.createElement("div",{className:"main-settings-content"},n.createElement("div",{onClick:Mt,className:"cursor-pointer mr-3 main-settings-content tooltip-container"},n.createElement(xe?S:h,{fontSize:28}),n.createElement("div",{className:"tooltip opacity-animation"},"Play")),n.createElement("div",{className:"main-settings-content"},n.createElement("div",{className:"main-settings-content volume-container"},n.createElement("div",{onClick:Lt,className:"cursor-pointer mr-3 main-settings-content tooltip-container"},n.createElement(Re?C:N,{fontSize:25}),n.createElement("div",{className:"tooltip"},"Volume")),n.createElement(F,{onDragEnd:Ot,value:$e,onChange:Tt,min:0,max:100,live:!1,color:vt,className:"volume mr-3 width-animation"})),J?n.createElement("div",{onClick:function(){var e;if(bt&&gt.current){var t=gt.current,n=v(t,ae.current);if(null==(e=ae.current)||e.startLoad(),null===n)return t.play().catch(console.error),void Te(!0);t.currentTime=n,je(n),it(0),rt(!1),Te(!0),t.play().catch(console.error)}},"aria-disabled":!bt,className:"text-sm font-semibold live-button "+(bt?"cursor-pointer live-button-behind":"live-button-synced")},"Live"):n.createElement("div",{className:"time"},u(ze)," / ",u(null==gt||null==(x=gt.current)?void 0:x.duration)))),n.createElement("div",{className:"main-settings-content"},n.createElement("div",{className:"tooltip-container main-settings-content"},n.createElement(k,{onClick:function(){return Be(!We)},className:"cursor-pointer mr-3",fontSize:23}),n.createElement("div",{className:"tooltip"},"Settings")),n.createElement("div",{className:"tooltip-container main-settings-content"},n.createElement(w,{onClick:function(){var e,t;gt.current&&(e=document,t=gt.current,e.pictureInPictureEnabled||t.webkitSetPresentationMode||t.mozRequestPictureInPicture?e.pictureInPictureElement?d():e.pictureInPictureEnabled&&t.requestPictureInPicture?t.requestPictureInPicture().catch(console.error):t.webkitSetPresentationMode?t.webkitSetPresentationMode("picture-in-picture"===t.webkitPresentationMode?"inline":"picture-in-picture"):null==t.mozRequestPictureInPicture||t.mozRequestPictureInPicture().catch(console.error):console.warn("Picture-in-Picture không được hỗ trợ trong trình duyệt này."))},className:"cursor-pointer mr-3",fontSize:23}),n.createElement("div",{className:"tooltip"},"PIP")),n.createElement("div",{onClick:Pt,className:"cursor-pointer main-settings-content tooltip-container"},n.createElement(Ae?y:b,{fontSize:23}),n.createElement("div",{className:"tooltip"},"Fullscreen")))))))},q=function(e){var r=e.children,l=t.useState("undefined"!=typeof window),o=l[0],a=l[1];return t.useEffect((function(){a(!0)}),[]),o?r:n.createElement(n.Fragment,null)};exports.DEFAULT_AUTO_QUALITY_CONFIG=f,exports.default=function(e){return n.createElement("div",{id:"vnetwork-player"},n.createElement(c,null,n.createElement(q,null,n.createElement(H,Object.assign({},e)))))}; //# sourceMappingURL=vnetwork-player.cjs.production.min.js.map