@3deye-toolkit/react-camera 0.0.7 → 0.0.8
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/dist/react-camera.d.ts +9 -6
- package/dist/react-camera.js +1 -1
- package/package.json +2 -2
package/dist/react-camera.d.ts
CHANGED
|
@@ -410,6 +410,13 @@ declare enum PlayerState {
|
|
|
410
410
|
Failed = "failed"
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
+
export declare interface PlayerWebRtcOptions {
|
|
414
|
+
enabled: boolean;
|
|
415
|
+
allowedIceCandidateProtocols?: ('udp' | 'tcp')[];
|
|
416
|
+
iceServers?: RTCIceServer[];
|
|
417
|
+
iceTransportPolicy?: RTCIceTransportPolicy;
|
|
418
|
+
}
|
|
419
|
+
|
|
413
420
|
export declare const PlayPauseControl: (() => JSX_2.Element) & {
|
|
414
421
|
displayName: string;
|
|
415
422
|
};
|
|
@@ -421,6 +428,7 @@ declare interface Props extends Omit<React_2.HTMLAttributes<HTMLDivElement>, 'on
|
|
|
421
428
|
onMouseDown?: (e: MouseEvent) => void;
|
|
422
429
|
onRequestClose?: () => void;
|
|
423
430
|
playerRef?: Ref<PlayerController>;
|
|
431
|
+
webRtcOptions?: PlayerWebRtcOptions;
|
|
424
432
|
}
|
|
425
433
|
|
|
426
434
|
declare interface Props_2 extends Omit<React_2.HTMLAttributes<HTMLDivElement>, 'onMouseDown'> {
|
|
@@ -431,12 +439,7 @@ declare interface Props_2 extends Omit<React_2.HTMLAttributes<HTMLDivElement>, '
|
|
|
431
439
|
controls: React_2.ReactNode;
|
|
432
440
|
onMouseDown?: (e: MouseEvent) => void;
|
|
433
441
|
hideCameraTitle?: boolean;
|
|
434
|
-
webRtcOptions?:
|
|
435
|
-
enabled: boolean;
|
|
436
|
-
allowedIceCandidateProtocols?: ('udp' | 'tcp')[];
|
|
437
|
-
iceServers?: RTCIceServer[];
|
|
438
|
-
iceTransportPolicy?: RTCIceTransportPolicy;
|
|
439
|
-
};
|
|
442
|
+
webRtcOptions?: PlayerWebRtcOptions;
|
|
440
443
|
controllerRef?: Ref<PlayerController>;
|
|
441
444
|
videoRef?: Ref<HTMLVideoElement>;
|
|
442
445
|
archivesStore: ArchivesStore;
|
package/dist/react-camera.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"i18next";import{of as t,from as i,Observable as s,EMPTY as r,timer as n,fromEvent as a,Subscription as o,fromEventPattern as l,switchMap as c,filter as d,timeout as h,take as u,TimeoutError as m,throwError as p,mergeMap as v,debounceTime as g,merge as f,map as y,pairwise as b,interval as R,concatMap as C,delay as w,Subject as T,noop as k}from"rxjs";import{jsx as P,jsxs as S,Fragment as M}from"react/jsx-runtime";import x,{forwardRef as I,useRef as E,useCallback as L,cloneElement as N,createContext as D,useState as O,Children as _,useEffect as A,useContext as z,useLayoutEffect as F,useMemo as Q,useImperativeHandle as V}from"react";import{AppContext as H,app as U}from"@3deye-toolkit/core";import{observer as B,useLocalObservable as $}from"mobx-react-lite";import W from"clsx";import j from"react-ink";import{useFloating as q,offset as Z,flip as Y,shift as G,arrow as J,autoUpdate as X,useInteractions as K,useRole as ee,useDismiss as te,FloatingPortal as ie,FloatingFocusManager as se,useHover as re}from"@floating-ui/react";import ne from"@seznam/compose-react-refs";import ae,{ErrorDetails as oe,ErrorTypes as le}from"hls.js";import{computed as ce,observe as de,makeObservable as he,observable as ue,action as me,runInAction as pe,reaction as ve,when as ge,makeAutoObservable as fe}from"mobx";import ye from"resize-observer-polyfill";import{switchMap as be,tap as Re,debounceTime as Ce,filter as we,startWith as Te,takeUntil as ke,take as Pe,map as Se,mergeMap as Me,mapTo as xe,distinctUntilChanged as Ie,audit as Ee,auditTime as Le,pairwise as Ne}from"rxjs/operators";import{decomposeTSR as De,identity as Oe,compose as _e,rotate as Ae,translate as ze,scale as Fe,inverse as Qe,applyToPoint as Ve,fromTwoMovingPoints as He,fromObject as Ue,applyToPoints as Be,toCSS as $e}from"transformation-matrix";import{useDrag as We,useGesture as je}from"@use-gesture/react";import{scaleLinear as qe,scaleLog as Ze}from"d3-scale";import Ye from"reconnecting-websocket";import{Controller as Ge,useSpring as Je,config as Xe,animated as Ke}from"@react-spring/web";import{retryBackoff as et}from"backoff-rxjs";var tt={playerTools:{fullScreen:"toggle full screen",resetRotation:"reset rotation",closePlayer:"close player",play:"play",pause:"pause",playbackRate:"set playback rate",snapshot:"capture video frame",volume:"volume",live:"live",goLive:"go live"},selectArea:"select area",button:{cancel:"Cancel"},videoResizeMode:{fit:"keep video's aspect ratio",stretch:"stretch video"},player:{playbackTimeoutError:"Error occured. No playback in the last {{count}} seconds",cameraIsOffline:"Camera is offline",cameraIsDisabled:"Camera is disabled",noPlayableStream:"No playable stream available",noVideoTrack:"No video track",genericError:"An error occured. Please try again later"},ptzControl:{zoomSpeed:"zoom speed",relative:"Relative",continuous:"Continuous",moveCameraHome:"move camera to home position",movementSpeed:"movement speed",setHome:"set as home"},ptzControls:{confirmSetHomePosition:"Are you sure you want to set the camera's home position to the current position?",cameraPtzHomeSet:"New home position is set",errorWhileUpdatingHomePositionDescription:"Sorry, camera PTZ failed to respond to the request.\nPlease make sure your have Internet connection and refresh your browser"}};const it={detection:{order:["querystring","htmlTag","navigator"],lookupQuerystring:"lang"},fallbackLng:"en",load:"all",interpolation:{escapeValue:!1}},st=e.createInstance(),rt=x.createContext(null);class nt extends Error{name;message;cause;constructor(e,t,i){super(t),this.name=e,this.message=t,this.cause=i}}function at(e,t=!1){const i=ce(e);return new s((e=>{const s=de(i,(({newValue:t})=>e.next(t)),t);return()=>s()}))}class ot{id;name;imageUrl;streamUrl;dashStreamUrl;address;archiveDuration;dvrWindowLength;stateUpdatedAt;raw;enabled;isMicEnabled;state;pin;webRtcUrl;isPtz;permissions;get isOnline(){return this.enabled&&"Started"===this.state}get supportsWebRTC(){return!!this.webRtcUrl}constructor(e){he(this,{name:ue,streamUrl:ue,dashStreamUrl:ue,enabled:ue,isMicEnabled:ue,state:ue,pin:ue,webRtcUrl:ue,permissions:ue,isOnline:ce,update:me}),this.update(e)}update=e=>{this.raw=e,this.id=e.id,this.name=e.name,this.isPtz=e.isPTZ,this.isMicEnabled=e.isMicEnabled,this.imageUrl=e.imageUrl,this.address=e.cameraAddress?JSON.parse(e.cameraAddress):null,this.streamUrl=e.streamUrl,this.dashStreamUrl=e.dashStreamUrl,this.enabled=e.enabled,this.state=this.raw.cameraState,this.dvrWindowLength=e.dvrWindowLength?1e3*e.dvrWindowLength:e.dvrWindowLength,this.archiveDuration=e.archiveDuration,this.pin=e.pin,this.webRtcUrl=e.webRtcUrl,this.permissions=e.permissions||0,this.stateUpdatedAt=new Date(e.cameraStateChangedTime)};can=e=>!!(this.permissions&e)}var lt;!function(e){e[e.View=1]="View",e[e.SaveClip=2]="SaveClip",e[e.Share=4]="Share",e[e.Ptz=8]="Ptz",e[e.EditSettings=16]="EditSettings",e[e.Timelapse=32]="Timelapse",e[e.Delete=64]="Delete"}(lt||(lt={}));class ct{cameraId;streamUrl;dashStreamUrl;startTime;endTime;length;isLive=!0;isDvr=!0;hasDvr=!0;rtmpStreamUrl;managed=!1;constructor(e){he(this,{startTime:ue,endTime:ue,setBounds:me}),this.streamUrl=e.streamUrl,this.dashStreamUrl=e.dashStreamUrl,this.startTime=e.startTime,this.endTime=e.endTime,this.length=e.length,this.cameraId=e.cameraId}setBounds=e=>{[this.startTime,this.endTime]=e}}const dt=!!navigator.platform&&/iPad|iPhone|iPod/.test(navigator.platform),ht=!!navigator.userAgent.match(/Version\/[\d.]+.*Safari/),ut=(e,t,i)=>Math.min(Math.max(e,t),i),mt=()=>{},pt=({forwardedRef:e,children:t,className:i,fullWidth:s,variant:r,type:n,title:a,placement:o,...l})=>{const c=W(i,"x-3deye-button",{"x-3deye-button--fullwidth":s},r?`x-3deye-button--${r}`:void 0),d=S("button",{ref:e,className:c,type:n||"button",...l,children:[t,l.disabled?null:P(j,{})]});return void 0===a?d:P(Xt,{label:a,placement:o,disabled:!a,children:d})};var vt=I(((e,t)=>P(pt,{forwardedRef:t,...e})));function gt(e){return I(((t,i)=>{const{size:s=24,color:r="currentColor",className:n,...a}=t,o=e.viewBox||"0 0 24 24",l=e.svg;return P("svg",{ref:i,preserveAspectRatio:"xMinYMin",className:W("icon",n),width:s,fill:r,viewBox:o,...a,children:l})}))}const ft=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M19 12h-2v3h-3v2h5v-5zM7 9h3V7H5v5h2V9zm14-6H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z"})]})});ft.displayName="AspectRatioIcon";var yt=ft;const bt=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});bt.displayName="CloseIcon";var Rt=bt;const Ct=gt({viewBox:"0 0 24 24",svg:P("path",{d:"M7,2l12,11.2l-5.8,0.5l3.3,7.3l-2.2,1l-3.2-7.4L7,18.5V2"})});Ct.displayName="CursorIcon";var wt=Ct;const Tt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M20 15.256v1.828A9 2 0 0 1 21 18a9 2 0 0 1-9 2 9 2 0 0 1-9-2 9 2 0 0 1 1-.914v-1.824A11 4 0 0 0 1 18a11 4 0 0 0 11 4 11 4 0 0 0 11-4 11 4 0 0 0-3-2.744z"}),P("path",{d:"M12 3 1 11.4l1.21 1.59L4 11.62V19h2v-8.9l6-4.58 6 4.58V19h2v-7.38l1.79 1.36L23 11.4 12 3z"}),P("path",{d:"m16 14-4 4-4-4 1.41-1.41L11 14.17v-4.15l2-.02v4.17l1.59-1.59z"})]})});Tt.displayName="HomeSaveIcon";var kt=Tt;const Pt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M12 3L1 11.4l1.21 1.59L4 11.62V21h16v-9.38l1.79 1.36L23 11.4zm6 16H6v-8.9l6-4.58 6 4.58z"})]})});Pt.displayName="HomeIcon";var St=Pt;const Mt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});Mt.displayName="PauseIcon";var xt=Mt;const It=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M8 5v14l11-7z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});It.displayName="PlayIcon";var Et=It;const Lt=gt({viewBox:"0 0 100 100",svg:P(M,{children:P("path",{d:"M87.783 47.898c-1.132-2.958-8.699-12.701-10.266-13.223-1.565-.521-4.872-.348-4.872-.348-1.479-16.616-5.132-18.442-7.654-20.269-2.523-1.826-2.263 5.395-2.263 5.395-.87-3.045-5.307-8.004-8.352-7.221-3.045.783-1.391 10.788-.956 13.57.437 2.785 4.35 6.785 5.827 8.96 1.479 2.174.697 4.088.697 4.088-1.218 1.741-1.044 6.119-1.044 6.119-3.043-.494-6.001 3.016-6.001 3.016-6.874-2.956-10.808-3.016-10.808-3.016-20.86.208-23.515 20.064-23.822 26.65-.745-.324-1.78-.315-3.116.737-3.071 2.419-.88 5.383-.88 5.383-.865-.238-1.722-4.225-1.722-4.225-1.963 4.198 1.606 7.065 1.606 7.065-1.33.285-3.53-1.206-3.53-1.206.208.281 1.585 2.426 4.26 5.227 3.376 3.532 8.355 2.771 10.81 2.676.088.018.163.01.233-.01l.071-.002.012-.03c.386-.172.692-.719 2.295-.182l2.06 1.296s18.203.169 21.053 0c1.546-.092-1.566-4.523-1.566-4.523 5.654-.349 8.699-2.437 8.699-2.437l8.735 7.129h9.164c1.801 0 .697-1.93.697-1.93l-8.593-7.809.956-1.652c3.306-.696 5.655-3.915 6.001-4.523.35-.609.089-5.132.089-5.132s.349.435 1.826-1.393c1.48-1.827-.173-4.697-.607-5.307-.434-.607-1.305-4.438-1.305-4.438s5.827-.348 7.22-1.044c1.389-.693 6.176-4.434 5.046-7.391z"})})});Lt.displayName="RabbitIcon";var Nt=Lt;const Dt=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M12.01 5.5L10 8h4l-1.99-2.5zM18 10v4l2.5-1.99L18 10zM6 10l-2.5 2.01L6 14v-4zm8 6h-4l2.01 2.5L14 16zm7-13H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z"})]})});Dt.displayName="SettingsOverscanIcon";var Ot=Dt;const _t=gt({viewBox:"0 0 79.375 79.375",svg:P(M,{children:P("path",{d:"M138.93 101.512c-16.578.124-32.548 6.13-47.309 17.925-7.317 5.847-15.399 14.393-17.77 18.788-1.58 2.931-3.668 7.757-6.367 14.712-7.457 19.225-11.997 29.033-16.8 36.297-1.638 2.476-1.781 2.231 1.748 2.99.613.133 1.285.26 1.984.383-1.634 3.885-5.948 9.571-11.436 13.088-1.138.73-4.443 2.638-7.345 4.242-5.362 2.964-7.66 4.377-9.285 5.713-1.765 1.45-4.48 4.224-4.786 4.891-.23.503-.304 1.445-.29 3.686.015 2.55.098 3.286.546 4.824 1.28 4.391 3.49 7.175 6.205 7.824 1.303.311 1.77.296 3.342-.107 3.624-.931 6.702-3.5 16.992-14.186 8.097-8.408 10.799-10.842 14.067-12.672.031-.017.064-.03.095-.047 1.093.759 2.373 1.422 3.221 1.602 2.71.574 28.721 2.944 47.403 4.318 8.207.604 16.372 1.208 18.142 1.342 1.77.134 10.736.21 19.924.17 13.044-.058 18.042.009 20.807-1.867-4.243 6.551-9.009 15.985-6.569 22.843 1.043 2.745 3.456 5.444 5.754 6.438 3.466 1.5 7.874-1.423 12.715-8.428 2.22-3.213 4.69-7.493 8.592-14.894 2.167-4.11 3.373-6.495 4.076-8.534l1.717-.51c.66 0 3.167-.885 5.047-1.782 4.06-1.939 9.627-5.707 15.574-10.543 2.402-1.954 7.135-5.996 9.199-7.846 18.116 13.509 29.936 25.039 32.766 32.033.311.77.629 1.4.705 1.4.433 0 4.516-4.066 6.2-6.175 4.187-5.243 6.403-10.354 6.403-14.76-1.252-15.979-37.802-28.468-28.124-33.08 3.282-1.563.627-3.716 11.572-3.293 7.862-.501 11.288-1.289 14.761-3.395 3.58-2.17 5.372-4.62 6.983-9.545 1.017-3.19.806-4.87.326-9.017 1.96-1.74 2.14-7.427-.22-9.6-1.625-1.913-4.807-3.627-8.503-4.576-8.376-2.15-24.507-1.09-32.883 2.162-1.493.58-2.487 1.192-4.244 2.615-2.451 1.986-5.58 4.847-8.601 7.868-1.114 1.113-1.585 1.613-2.075 2.52l-1.562-1.31c-.293-.296-1.923-1.951-3.621-3.677-16.038-16.305-32.66-28.14-48.71-34.682-10.253-4.18-20.42-6.223-30.366-6.148zm127.783 39.14c1.656-.08 3.338 1.31 3.51 3.819.104 1.518-.393 2.89-1.362 3.76-.361.324-.977.524-1.797.585-1.044.078-1.36-.003-1.95-.494-1.605-1.334-2.077-3.308-1.272-5.324.617-1.547 1.738-2.29 2.87-2.346z",transform:"scale(.26458)"})})});_t.displayName="TurtleIcon";var At=_t;const zt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"}),P("path",{fill:"none",d:"M0 0h24v24H0V0z"}),P("path",{d:"M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"})]})});zt.displayName="ZoomInIcon";var Ft=zt;const Qt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z"})]})});Qt.displayName="ZoomOutIcon";var Vt=Qt;const Ht=({opened:e,onOpenChange:t,children:i,target:s,placement:r,className:n,style:a,autoDismiss:o=!0,initialFocus:l,withArrow:c=!1})=>{const d=E(null),{x:h,y:u,refs:m,strategy:p,context:v,middlewareData:g,placement:f,update:y}=q({open:e,onOpenChange:t,middleware:[Z(5),Y(),G(),J({element:d})],placement:r,whileElementsMounted:(e,t,i)=>X(e,t,(()=>{0!==v.elements.domReference?.getBoundingClientRect().width?i():v.onOpenChange(!1)}),{animationFrame:!0})}),{getReferenceProps:b,getFloatingProps:R}=K([ee(v),te(v,{ancestorScroll:!0,enabled:o})]),C=L((e=>{d.current=e,y()}),[y]),w={top:"bottom",right:"left",bottom:"top",left:"right"}[f?.split("-")[0]??"top"]||"top",T=S("div",{...R({className:W("x-3deye-popover-container",n),ref:m.setFloating,style:{...a,position:p,top:u??0,left:h??0}}),children:[c&&P(Jt,{ref:C,width:24,height:8,placement:w,style:{position:"absolute",left:g.arrow?.x,top:g.arrow?.y,[w]:-7}}),i]});return S(M,{children:[N(s,b({ref:m.setReference,...s.props})),S(ie,{id:"x-3deye-floating-ui-root",children:[o&&e&&P(se,{context:v,modal:!1,order:["reference","content"],returnFocus:!1,initialFocus:l,children:T}),!o&&e&&T]})]})},Ut=(e,t,i,s)=>ut(Math.floor((e-t)/i*s),0,s-1),Bt=D({value:null,onPointerDown:mt,setCurrentValue:mt,state:{currentIdx:0,currentValue:null,options:[]}});class $t{currentIdx=0;options=[];get currentValue(){return this.options[this.currentIdx]}constructor(e=0){this.currentIdx=e,he(this,{currentIdx:ue,options:ue.ref,currentValue:ce,setCurrentIdx:me,setOptions:me})}setCurrentIdx=e=>{this.currentIdx=e};setOptions=e=>{this.options=e}}var Wt=B(x.forwardRef((({value:e,onChange:t,children:i,style:s},r)=>{const[n,a]=O(!1),o=E(null),l=_.map(i,(e=>e?.props.value))||[],c=$((()=>new $t(l.indexOf(e))));c.setOptions(l);const d=_.count(i);A((()=>{c.setCurrentIdx(l.indexOf(e))}),[e]),A((()=>{if(!n)return;const e=o.current?.getBoundingClientRect();if(!e)return;const i=({clientX:t})=>{c.setCurrentIdx(Ut(t,e.left,e.width,d))},s=()=>{a(!1),t(l[c.currentIdx])};return document.addEventListener("pointermove",i),document.addEventListener("pointerup",s),()=>{document.removeEventListener("pointermove",i),document.removeEventListener("pointerup",s)}}),[n,d]);return P(Bt.Provider,{value:{value:e,state:c,onPointerDown:e=>{const t=o.current;if(!t)return;const{left:i,width:s}=t.getBoundingClientRect(),r=Ut(e.clientX,i,s,d);r!==c.currentIdx&&c.setCurrentIdx(r),a(!0)},setCurrentValue:e=>{c.setCurrentIdx(l.indexOf(e))}},children:P("div",{className:"segmented-control-wrapper",style:s,ref:r,children:S("div",{role:"radiogroup",ref:o,className:"segmented-control",style:{"--indicator-offset":100*c.currentIdx+"%"},children:[P("div",{"aria-hidden":!0,className:W("segmented-control-indicator",{active:n}),style:{width:100/l.length+"%"},children:P("div",{className:"segmented-control-indicator-inner"})}),i]})})})})));const jt=B(I((({value:e,children:t},i)=>{const s=z(Bt);return P("button",{ref:i,role:"radio","aria-checked":s.state.currentValue===e,tabIndex:0,className:W("segmented-control-button",{current:s.state.currentValue===e}),onPointerDown:s.onPointerDown,onClick:()=>s.setCurrentValue(e),children:t})})));jt.displayName="SegmentedControlOption";var qt=jt;const Zt=e=>Math.round(e),Yt=I((({value:e,onChange:t,onChangeComplete:i,orientation:s="horizontal",disabled:r=!1,labelFormat:n=e=>`${e}`,style:a},o)=>{const l=E(null),c=E(null),[d,h]=O(!1),[u,m]=O(e);A((()=>{if(!d)return;const e=l.current;if(!e)return;let r=0,n=0;const a=e.getBoundingClientRect();if(!a||!a.width||!a.height)return void h(!1);const o=({clientX:e,clientY:i})=>{if(!c.current)return;let o=0;"horizontal"===s?(r=ut(e-a.x,0,a.width),o=r/a.width*100,c.current.style.transform=`translateX(${r}px)`):(n=a.height-ut(i-a.y,0,a.height),o=n/a.height*100,c.current.style.transform=`translateY(${-n}px)`),m(o),t?.(Zt(o))},u=({clientX:e,clientY:r})=>{if(h(!1),!c.current)return;const n="horizontal"===s?ut(e-a.x,0,a.width)/a.width*100:100*(1-ut(r-a.y,0,a.height)/a.height);c.current.style.transform="",m(n),t?.(Zt(n)),i?.(Zt(n))},p=()=>{if(h(!1),!c.current)return;const e="horizontal"===s?r/a.width*100:n/a.height*100;c.current.style.transform="",t?.(Zt(e)),i?.(Zt(e))};return document.addEventListener("pointercancel",p),document.addEventListener("pointermove",o),document.addEventListener("pointerup",u),()=>{document.removeEventListener("pointercancel",p),document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",u)}}),[d,s,t,i]);const p=L((e=>{if(!l.current||r)return;const{clientX:i,clientY:n}=e;e.preventDefault(),h(!0);const a=l.current.getBoundingClientRect();if(!a)return;if(!c.current)return;let o=0;if("horizontal"===s){const e=ut(i-a.x,0,a.width);o=e/a.width*100,c.current.style.transform=`translateX(${e}px)`}else{const e=a.height-ut(n-a.y,0,a.height);o=e/a.height*100,c.current.style.transform=`translateY(${-e}px)`}m(o),t?.(Zt(o))}),[r]),v=L((s=>{if(r)return;let n=null;"ArrowLeft"===s.code?n=Math.max(e-1,0):"ArrowRight"===s.code?n=Math.min(e+1,100):"ArrowDown"===s.code?n=Math.max(e-1,0):"ArrowUp"===s.code&&(n=Math.min(e+1,100)),null!==n&&(s.stopPropagation(),s.preventDefault(),t?.(n),i?.(n))}),[e,t,i,r]);return S("div",{ref:ne(o,l),tabIndex:0,onKeyDown:v,className:W("x-3deye-slider",s,{disabled:r}),onPointerDown:p,style:a,children:[P("div",{className:"x-3deye-slider__track",children:P("div",{className:"x-3deye-slider__bar",style:{width:"horizontal"===s?`${d?u:e}%`:void 0,height:"vertical"===s?`${d?u:e}%`:void 0}})}),P("div",{ref:c,className:W("x-3deye-slider__thumb",{active:d}),style:{touchAction:"none",userSelect:"none",position:"absolute",left:"horizontal"===s?d?0:`${e}%`:"auto",bottom:"vertical"===s?d?0:`${e}%`:"auto"},children:null!==n&&P("div",{className:"x-3deye-slider__label "+(d?"open":""),children:n(d?Zt(u):e)})})]})}));function Gt(e){return P("svg",{focusable:"false",role:"graphics-symbol",viewBox:"0 0 66 66",className:"spinner",...e,children:P("circle",{fill:"none",strokeWidth:3,cx:33,cy:33,r:30,stroke:"white"})})}Yt.displayName="Slider";const Jt=x.forwardRef((function({width:e,height:t,placement:i="top",style:s},r){const n=[0,"top"===i?t:0],a=[e,n[1]],o=[e/2,t-n[1]],l=[e/4,t*("top"===i?3:1)/4],c=[.325*e,t-n[1]],d=[e-c[0],c[1]],h=[e-l[0],l[1]],u=e=>e.join(","),m=`M ${u(n)} C ${u(l)} ${u(c)} ${u(o)} ${u(d)} ${u(h)} ${u(a)}`;return S("svg",{ref:r,role:"graphics-symbol",className:"tip",style:s,width:e,height:t,fill:"var(--tip-background, #fff)",children:[P("path",{className:"tip-body",d:`${m} Z`}),P("path",{className:"tip-border",d:m,stroke:"var(--tip-border, transparent)",strokeWidth:1})]})}));var Xt=({children:e,label:t,placement:i="bottom",disabled:s})=>{const[r,n]=O(!1),{x:a,y:o,refs:l,strategy:c,context:d}=q({placement:i,open:r,onOpenChange:n,middleware:[Z(5),Y(),G({padding:8})],whileElementsMounted:(e,t,i)=>X(e,t,i,{animationFrame:!0})}),{getReferenceProps:h,getFloatingProps:u}=K([re(d,{enabled:!s}),ee(d,{role:"tooltip"}),te(d,{referencePress:!0})]);return S(M,{children:[N(e,h({ref:ne(l.setReference,e.ref),...e.props})),P(ie,{id:"x-3deye-floating-ui-root",children:r&&P("div",{...u({ref:l.setFloating,className:"x-3deye-tooltip",style:{position:c,top:o??0,left:a??0}}),children:t})})]})};const Kt=120;function ei({angle:e,onChange:t}){const i=E(e);i.current=e;const s=Array.from({length:40}).map(((t,i)=>{const s=Math.PI/20;let r=Math.max(0,s*i+e+2*Math.PI);for(;r>2*Math.PI;)r-=2*Math.PI;return[i,Math.sin(r)/2,r>=0&&r<=Math.PI/2?(Math.PI/2-r)/Math.PI*2:r>=1.5*Math.PI&&r<=2*Math.PI?(r-1.5*Math.PI)/Math.PI*2:0,!!(0===i||e>=0&&s*i>=2*Math.PI-e||e<0&&s*i<-e)]})).filter((e=>e[2])),r=We((({first:e,movement:[s,r],memo:n})=>{if(e)return{a:i.current};const{a:a}=n;return t(a+r/Kt*2),{a:a}}));return P("div",{style:{touchAction:"none",position:"relative",height:Kt},...r(),children:s.map((([e,t,i,s],r)=>{const n=e%5==0;return P("div",{style:{position:"absolute",width:0===e?30:n?24:20,height:2,background:s?"orange":"currentColor",opacity:i,translate:`${0===e?-5:n?-2:0}px ${60+t*Kt}px`}},r)}))})}function ti(){const[e,t]=O(void 0),[i,s]=O(!1),r=dt&&e instanceof HTMLVideoElement?"webkitEnterFullscreen"in e:document.fullscreenEnabled||Boolean(document.webkitFullscreenEnabled);const n=L((e=>{t(e||void 0)}),[]);A((()=>{const t=()=>{s(document.fullscreenElement===(e||document.documentElement))};return document.addEventListener("fullscreenchange",t),document.addEventListener("webkitfullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t),document.removeEventListener("webkitfullscreenchange",t)}}),[e]);return{ref:n,toggle:L((()=>{r&&(document.fullscreenElement!==(e||document.documentElement)?(e||document.documentElement).requestFullscreen():document.exitFullscreen())}),[e,i]),enabled:r,active:i}}const ii=x.forwardRef((({children:e,className:t,...i},s)=>P(vt,{ref:s,className:t=t?`x-3deye-player__control ${t}`:"x-3deye-player__control",...i,children:e})));ii.displayName="Control";var si=ii;const ri=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M 10 3.5 C 9.75 3.5 9.508724 3.5503906 9.2753906 3.6503906 C 9.0420573 3.7503906 8.8424479 3.8908854 8.6757812 4.0742188 L 7.3496094 5.5 L 4.3007812 5.5 C 3.8007813 5.5 3.3753906 5.6753906 3.0253906 6.0253906 C 2.6753906 6.3753906 2.5 6.8007812 2.5 7.3007812 L 2.5 18.699219 C 2.5 19.199219 2.6753906 19.624609 3.0253906 19.974609 C 3.3753906 20.324609 3.8007813 20.5 4.3007812 20.5 L 19.699219 20.5 C 20.199219 20.5 20.624609 20.324609 20.974609 19.974609 C 21.324609 19.624609 21.5 19.199219 21.5 18.699219 L 21.5 7.3007812 C 21.5 6.8007813 21.324609 6.3753906 20.974609 6.0253906 C 20.624609 5.6753906 20.199219 5.5 19.699219 5.5 L 16.650391 5.5 L 15.324219 4.0742188 C 15.157552 3.8908854 14.957943 3.7503906 14.724609 3.6503906 C 14.491276 3.5503906 14.25 3.5 14 3.5 L 10 3.5 z M 4.3007812 7 L 19.699219 7 C 19.782552 7 19.853443 7.029224 19.912109 7.0878906 C 19.970109 7.1458906 20 7.2174479 20 7.3007812 L 20 18.699219 C 20 18.782552 19.970109 18.853443 19.912109 18.912109 C 19.853443 18.970109 19.782552 19 19.699219 19 L 4.3007812 19 C 4.2174479 19 4.1458906 18.970109 4.0878906 18.912109 C 4.029224 18.853443 4 18.782552 4 18.699219 L 4 7.3007812 C 4 7.2174479 4.029224 7.1458906 4.0878906 7.0878906 C 4.1458906 7.029224 4.2174479 7 4.3007812 7 z M 12 8.875 C 10.85 8.875 9.8742188 9.2742187 9.0742188 10.074219 C 8.2742188 10.874219 7.875 11.85 7.875 13 C 7.875 14.15 8.2742187 15.125781 9.0742188 15.925781 C 9.8742188 16.725781 10.85 17.125 12 17.125 C 13.15 17.125 14.125781 16.725781 14.925781 15.925781 C 15.725781 15.125781 16.125 14.15 16.125 13 C 16.125 11.85 15.725781 10.874219 14.925781 10.074219 C 14.125781 9.2742188 13.15 8.875 12 8.875 z M 12 10.386719 A 2.6057522 2.6057522 0 0 1 14.605469 12.992188 A 2.6057522 2.6057522 0 0 1 12 15.599609 A 2.6057522 2.6057522 0 0 1 9.3945312 12.992188 A 2.6057522 2.6057522 0 0 1 12 10.386719 z "})]})});ri.displayName="CameraIcon";var ni=ri;const ai=gt({viewBox:"0 0 24 24",svg:P(M,{children:P("path",{d:"M12 13.05 6.925 18.125Q6.725 18.325 6.413 18.337Q6.1 18.35 5.875 18.125Q5.65 17.9 5.65 17.6Q5.65 17.3 5.875 17.075L10.95 12L5.875 6.925Q5.675 6.725 5.663 6.412Q5.65 6.1 5.875 5.875Q6.1 5.65 6.4 5.65Q6.7 5.65 6.925 5.875L12 10.95L17.075 5.875Q17.275 5.675 17.588 5.662Q17.9 5.65 18.125 5.875Q18.35 6.1 18.35 6.4Q18.35 6.7 18.125 6.925L13.05 12L18.125 17.075Q18.325 17.275 18.337 17.587Q18.35 17.9 18.125 18.125Q17.9 18.35 17.6 18.35Q17.3 18.35 17.075 18.125Z"})})});ai.displayName="CloseIcon";var oi=ai;const li=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M8.5 19v-3.5H5V14h5v5ZM5 10V8.5h3.5V5H10v5Zm9 9v-5h5v1.5h-3.5V19Zm0-9V5h1.5v3.5H19V10Z"})]})});li.displayName="FullscreenExitIcon";var ci=li;const di=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M5 19v-5h1.5v3.5H10V19Zm0-9V5h5v1.5H6.5V10Zm9 9v-1.5h3.5V14H19v5Zm3.5-9V6.5H14V5h5v5Z"})]})});di.displayName="FullscreenIcon";var hi=di;const ui=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M14.75 18.5Q14.125 18.5 13.688 18.062Q13.25 17.625 13.25 17V7Q13.25 6.375 13.688 5.938Q14.125 5.5 14.75 5.5H17Q17.625 5.5 18.062 5.938Q18.5 6.375 18.5 7V17Q18.5 17.625 18.062 18.062Q17.625 18.5 17 18.5ZM7 18.5Q6.375 18.5 5.938 18.062Q5.5 17.625 5.5 17V7Q5.5 6.375 5.938 5.938Q6.375 5.5 7 5.5H9.25Q9.875 5.5 10.312 5.938Q10.75 6.375 10.75 7V17Q10.75 17.625 10.312 18.062Q9.875 18.5 9.25 18.5ZM14.75 17H17V7H14.75ZM7 17H9.25V7H7ZM7 7V17ZM14.75 7V17Z"})]})});ui.displayName="PauseIcon";var mi=ui;const pi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M 8.739583,18.4955 Q 8.2525391,18.799994 7.7654953,18.526169 7.2791816,18.252344 7.2791816,17.674025 V 6.3259749 q 0,-0.578319 0.4863137,-0.852144 0.4870438,-0.273825 0.9740877,0.03067 l 8.91429,5.6889941 q 0.456376,0.304494 0.456376,0.806872 0,0.501648 -0.456376,0.806142 z M 8.80019,12.014969 Z m 0,4.625091 7.302007,-4.625091 L 8.80019,7.3906079 Z"})]})});pi.displayName="PlayIcon";var vi=pi;const gi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M18.95 21.6 16.45 19.125Q16.15 19.3 15.838 19.462Q15.525 19.625 15.2 19.775Q14.825 19.925 14.5 19.675Q14.175 19.425 14.175 19Q14.175 18.8 14.3 18.65Q14.425 18.5 14.6 18.4Q14.8 18.325 15 18.237Q15.2 18.15 15.375 18.05L11.8 14.45V16.6Q11.8 17.2 11.238 17.438Q10.675 17.675 10.25 17.25L7.5 14.5H4.7Q4.3 14.5 4.05 14.238Q3.8 13.975 3.8 13.6V10.4Q3.8 10.025 4.05 9.762Q4.3 9.5 4.7 9.5H6.825L2.525 5.2Q2.325 4.975 2.312 4.662Q2.3 4.35 2.525 4.125Q2.75 3.925 3.05 3.925Q3.35 3.925 3.575 4.125L20 20.55Q20.2 20.775 20.213 21.087Q20.225 21.4 20 21.6Q19.775 21.825 19.475 21.825Q19.175 21.825 18.95 21.6ZM15.2 4.175Q17.575 5.175 19.025 7.275Q20.475 9.375 20.475 11.975Q20.475 13.3 20.088 14.5Q19.7 15.7 18.975 16.725L17.9 15.65Q18.425 14.85 18.7 13.912Q18.975 12.975 18.975 11.975Q18.975 9.825 17.775 8.087Q16.575 6.35 14.6 5.55Q14.4 5.45 14.288 5.287Q14.175 5.125 14.175 4.925Q14.175 4.5 14.5 4.262Q14.825 4.025 15.2 4.175ZM9.3 11.975ZM15.925 13.675 14.175 11.925V8.3Q15.175 8.85 15.738 9.85Q16.3 10.85 16.3 12Q16.3 12.45 16.2 12.862Q16.1 13.275 15.925 13.675ZM11.8 9.525 9.625 7.375 10.25 6.75Q10.675 6.325 11.238 6.562Q11.8 6.8 11.8 7.4ZM10.3 15.15V12.95L8.325 11H5.3V13H8.15Z"})]})});gi.displayName="VolumeOffIcon";var fi=gi;const yi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M15.05 19.775Q14.675 19.925 14.363 19.675Q14.05 19.425 14.05 19Q14.05 18.8 14.163 18.65Q14.275 18.5 14.475 18.4Q16.45 17.6 17.65 15.863Q18.85 14.125 18.85 11.975Q18.85 9.825 17.65 8.087Q16.45 6.35 14.475 5.55Q14.25 5.45 14.15 5.287Q14.05 5.125 14.05 4.925Q14.05 4.5 14.363 4.262Q14.675 4.025 15.05 4.175Q17.45 5.175 18.9 7.275Q20.35 9.375 20.35 11.975Q20.35 14.575 18.9 16.675Q17.45 18.775 15.05 19.775ZM4.55 14.5Q4.175 14.5 3.913 14.238Q3.65 13.975 3.65 13.6V10.4Q3.65 10.025 3.913 9.762Q4.175 9.5 4.55 9.5H7.375L10.125 6.75Q10.55 6.325 11.1 6.562Q11.65 6.8 11.65 7.4V16.6Q11.65 17.2 11.1 17.438Q10.55 17.675 10.125 17.25L7.375 14.5ZM14.05 15.65V8.3Q15 8.825 15.575 9.825Q16.15 10.825 16.15 12Q16.15 13.175 15.575 14.15Q15 15.125 14.05 15.65ZM10.15 8.85 8 11H5.15V13H8L10.15 15.15ZM7.65 12Z"})]})});yi.displayName="VolumeUpIcon";var bi=yi;const Ri=({onClick:e})=>e?P(si,{className:"x-3deye-player__control-close",onClick:e,title:st.t("playerTools.closePlayer"),children:P(oi,{})}):null;Ri.displayName="CloseControl";var Ci=Ri;const wi=({toggle:e,active:t})=>P(si,{onClick:e??void 0,title:st.t("playerTools.fullScreen"),children:P(t?ci:hi,{})});wi.displayName="FullscreenControl";var Ti=wi;const ki=x.createContext(null),Pi=B((()=>{const e=z(ki);return P(si,{className:"x-3deye-player__control-playpause",onClick:e.togglePlayback,title:e.paused?st.t("playerTools.play"):st.t("playerTools.pause"),children:e.paused?P(vi,{}):P(mi,{})})}));Pi.displayName="PlayPauseControl";var Si=Pi;const Mi=[{value:.5,name:"0.5x"},{value:1,name:"1x"},{value:2,name:"2x"},{value:4,name:"4x"},{value:8,name:"8x"},{value:16,name:"16x"}],xi=B((()=>{const[e,t]=O(!1),i=z(ki);if("WebRTC"===i.mode)return null;let s=Mi.findIndex((e=>e.value===i.playbackRate));-1===s&&(s=1);const r=P(si,{className:"control-playbackrate",onClick:()=>t(!e),title:st.t("playerTools.playbackRate"),children:Mi[s].name});return P(Ht,{placement:"top",withArrow:!0,target:r,opened:e,onOpenChange:t,className:"popover-playbackrate",children:Array.from({length:Mi.length},((e,t)=>(t=Mi.length-1-t,P(vt,{onClick:()=>{return e=t,void i.setPlaybackRate(Mi[e].value);var e},style:{border:"2px solid "+(t===s?"rgba(255,255,255,0.5)":"transparent")},children:Mi[t].name},t))))})}));xi.displayName="PlaybackRateControl";var Ii=xi;const Ei=B((()=>{const e=z(ki);return P(si,{onClick:e.toggleResizeMode,title:"contain"===e.videoResizeMode?st.t("videoResizeMode.fit"):st.t("videoResizeMode.stretch"),children:"contain"===e.videoResizeMode?P(yt,{size:16}):P(Ot,{size:16})})}));Ei.displayName="ResizeModeControl";var Li=Ei;const Ni=()=>{const e=z(ki);return P(si,{onClick:()=>{const t=`${e.camera.name} ${(e.currentTime||new Date).toISOString().replace(/:/g,"-")}`;((e,t)=>{const i=document.createElement("canvas"),s=i.getContext("2d");if(!s)return;const{videoWidth:r,videoHeight:n}=e;i.width=r,i.height=n,s.drawImage(e,0,0,r,n);const a=i.toDataURL("image/jpeg"),o=document.createElement("a");o.href=a,o.download=`${t}.jpg`,document.body.appendChild(o),o.click(),o.remove()})(e.video,t)},title:st.t("playerTools.snapshot"),children:P(ni,{})})};var Di=Ni;Ni.displayName="SnapshotControl";const Oi=e=>{e.stopPropagation()},_i=B((()=>{const e=z(ki);return S(si,{className:"volume-control",title:st.t("playerTools.volume"),onClick:e.toggleMute,onWheel:t=>{const i=t.deltaY;i&&e.setVolume(ut(e.volume+(i<0?.1:-.1),0,1))},children:[e.muted?P(fi,{}):P(bi,{}),P("div",{onClick:Oi,className:"volume-range",children:P(Yt,{value:Math.round(100*e.volume),labelFormat:e=>`${e}%`,orientation:"vertical",onChange:t=>{e.setVolume(Number(t)/100)}})})]})}));_i.displayName="VolumeControl";var Ai=_i;const zi="x-3deye-player__controls--spaced",Fi="x-3deye-player__controls--compact",Qi="x-3deye-player__control--reflowed",Vi=e=>{if(!e)return;if(e.classList.contains(Fi)){e.classList.remove(Fi);for(const t of Array.from(e.children).filter((e=>e.classList.contains(Qi))))t instanceof HTMLElement&&(t.style.position="",t.style.bottom="",t.style.right="",t.classList.remove(Qi))}if(e.classList.contains(zi)){e.classList.remove(zi);for(const t of e.querySelectorAll(".before-spacer"))t.classList.remove("before-spacer")}if(e.scrollWidth-e.offsetWidth<=0){(e.querySelector(".spacer")?.clientWidth??0)>0&&e.classList.add(zi);for(const t of e.querySelectorAll(".spacer"))t.previousElementSibling?.classList.add("before-spacer");return}e.classList.add(Fi);const t=Array.from(e.children);let i=2,s=i;for(;e.scrollWidth-e.offsetWidth>0&&i<=t.length;){const e=t[t.length-i];e&&!e.classList.contains("spacer")?(e.style.position="absolute",e.style.bottom=8+38*(s-1)+"px",e.style.right="8px",e.classList.add(Qi),i++,s++):i++}};function Hi({style:e,children:t}){const i=E(null);return A((()=>{if(!i.current)return;const e=new MutationObserver((()=>Vi(i.current)));return e.observe(i.current,{childList:!0}),()=>e.disconnect()}),[]),A((()=>{const e=new ResizeObserver((()=>{Vi(i.current)})),t=i.current;return t&&e.observe(t),()=>e.disconnect()}),[]),F((()=>{Vi(i.current)})),P("div",{ref:i,className:"x-3deye-player__controls",style:e,children:t})}Hi.Spacer=()=>P("div",{className:"spacer"});const Ui=B((()=>{const e=z(ki),[t,i]=O(!1);if(!e.stats||!e.behavior)return null;const s=e=>{e.preventDefault(),i(!t)};if(!t)return P("details",{className:"x-3deye-player__stats",open:t,style:{pointerEvents:"auto"},children:P("summary",{onClick:s,children:"Stats"})});const r=e.stats,n=r.timestamp-r.startTime,a=r.bytesReceived/n,o=r.packetsReceived?Math.round(r.packetsLost/(r.packetsLost+r.packetsReceived)*100):0,{ttff:l}=e.behavior,c=l>0?`${(l/1e3).toFixed(2)} s`:"TBD";return S("details",{className:"x-3deye-player__stats",open:t,style:{pointerEvents:"auto"},children:[P("summary",{onClick:s,children:"Stats"}),S("dl",{children:[S("div",{children:[P("dt",{children:"frame width:"})," ",P("dd",{children:r.frameWidth||e.video.videoWidth})]}),S("div",{children:[P("dt",{children:"frame height:"})," ",P("dd",{children:r.frameHeight||e.video.videoHeight})]}),S("div",{children:[P("dt",{children:"bitrate:"}),S("dd",{children:[Math.round(8*r.bitrate)," kbit/s"]})]}),S("div",{children:[P("dt",{children:"average bitrate:"})," ",S("dd",{children:[Math.round(8*a)," kbit/s"]})]}),S("div",{children:[P("dt",{children:"elapsed time:"})," ",S("dd",{children:[Math.floor(n/1e3)," s"]})]}),S("div",{children:[P("dt",{children:"packets loss:"}),S("dd",{style:{color:o<10?"green":o<50?"yellow":"red"},children:[o,"%"]})]}),S("div",{children:[P("dt",{children:"packets received:"})," ",P("dd",{children:r.packetsReceived})]}),S("div",{children:[P("dt",{children:"packets lost:"})," ",P("dd",{children:r.packetsLost})]}),S("div",{children:[P("dt",{children:"frames received:"})," ",P("dd",{children:r.framesReceived})]}),S("div",{children:[P("dt",{children:"frames decoded:"})," ",P("dd",{children:r.framesDecoded})]}),S("div",{children:[P("dt",{children:"frames dropped:"})," ",P("dd",{children:r.framesDropped})]}),S("div",{children:[P("dt",{children:"round-trip time:"})," ",P("dd",{children:r.rtt})]}),S("div",{children:[P("dt",{children:"time to first frame:"})," ",P("dd",{children:c})]})]})]})}));Ui.displayName="PlayerStats";var Bi=Ui;const $i=B((()=>{const e=z(ki),[t,i]=O(!1);return S(Ht,{className:"x-3deye-player__camera-name-popover",opened:t,onOpenChange:i,placement:"bottom-start",autoDismiss:!1,withArrow:!0,target:P("div",{className:"x-3deye-player__camera-name",onClick:()=>i(!t),children:e.camera.name}),children:[S("div",{children:["id:"," ",P(vt,{style:{height:24},onClick:t=>{t.altKey?navigator.clipboard.writeText(JSON.stringify(e.camera.raw,null,2)):navigator.clipboard.writeText(e.camera.id.toString())},title:"copy to clipboard",children:e.camera.id})]}),S("div",{style:{lineHeight:"24px"},children:["provider: ",e.mode]}),P(Bi,{})]})}));$i.displayName="CameraName";var Wi,ji=$i;!function(e){e.Initial="initial",e.InitiallyPaused="initially-paused",e.Playing="playing",e.Paused="paused",e.Reconnecting="reconnecting",e.Stalled="stalled",e.Error="error",e.Failed="failed"}(Wi||(Wi={}));class qi extends nt{}const Zi=3e4;class Yi{player;video;hlsPlayer=null;live=!1;loading=!0;error=null;disposables=[];state=Wi.Initial;constructor(e,t,i){this.player=e,this.video=i,he(this,{hlsPlayer:ue.ref,goLive:!0,live:ue,loading:ue,error:ue,state:ue,seek:me,dispose:me}),this.live=t,this.disposables.push(at((()=>this.hlsPlayer),!0).pipe(be((e=>e?new s((t=>{e.on(ae.Events.ERROR,((e,i)=>{t.next(i)}))})):r))).subscribe((e=>{console.error(e),pe((()=>{e.details!==oe.BUFFER_ADD_CODEC_ERROR?e.type===le.NETWORK_ERROR&&[oe.FRAG_LOAD_ERROR,oe.MANIFEST_LOAD_ERROR].includes(e.details)&&403===e.response?.code?this.error=new qi("PLAYER_ERROR","HLS error",e):e.fatal&&(e.type===le.MEDIA_ERROR&&this.hlsPlayer&&this.hlsPlayer.recoverMediaError(),this.error=new qi("PLAYER_ERROR","HLS error",e)):this.error=new qi("PLAYER_ERROR","HLS error",e)}))}))),null===e.seekTime&&(this.live=!0),this.initDelayCompensation(),this.initPlayerState(),this.initLoadingTimeout(),this.reactToCamera(),this.catchUpAfterPause()}initDelayCompensation(){this.disposables.push(at((()=>this.live),!0).pipe(be((()=>this.live?at((()=>this.state),!0).pipe(be((e=>e!==Wi.Playing?r:n(5e3+5e3*Math.random(),3e4)))):r))).subscribe((()=>{const e=this.getDateRange(),{currentTime:t}=this.player;e&&t&&+e[1]-+t>6e4&&this.goLive()})))}initPlayerState(){this.disposables.push(this.player.progress$.pipe(Re((()=>{this.state===Wi.Playing||this.player.paused||pe((()=>{this.state=Wi.Playing}))})),Ce(2e3),we((()=>this.state===Wi.Playing))).subscribe((()=>{pe((()=>{this.state=Wi.Stalled}))}))),this.disposables.push(ve((()=>this.player.paused),(()=>{this.player.paused&&(this.state=Wi.Paused)})))}getPlayingFragment(){return this.hlsPlayer?.streamController?.fragPlaying??null}seek=e=>{if(!this.hlsPlayer)return;const t=this.getPlayingFragment();if(!t?.relurl)return void(this.player.seekTime=e);const i=+t.relurl.substring(0,t.relurl.length-3)-1e3*t.start;this.video.currentTime=(+e-i)/1e3,this.live=!1};getDateRange=()=>{if(!this.hlsPlayer)return null;const e=this.video.seekable;if(!e.length)return null;const t=e.start(0),i=e.end(e.length-1),s=this.getPlayingFragment();if(!s?.relurl)return null;const r=+s.relurl.substring(0,s.relurl.length-3)-1e3*s.start;return[new Date(1e3*t+r),new Date(1e3*i+r)]};goLive=()=>{this.seek(new Date),this.live=!0};getCurrentTime(){if(!this.hlsPlayer)return null;const e=this.getPlayingFragment();return e?.relurl?new Date(+e.relurl.substring(0,e.relurl.length-3)+1e3*(this.video.currentTime-e.start)):null}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(Zi)):r))).subscribe((()=>{pe((()=>{this.player.camera.isOnline?this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)}):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))}))),this.disposables.push(at((()=>this.state),!0).pipe(be((e=>e!==Wi.Stalled?r:n(Zi)))).subscribe((()=>{pe((()=>{this.player.camera.isOnline?this.error||(this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))})))}reactToCamera(){const{player:e}=this;this.disposables.push(ve((()=>({streamUrl:e.camera.streamUrl})),(({streamUrl:t})=>{pe((()=>{this.loading=!0})),this.hlsPlayer&&this.hlsPlayer.destroy(),t?(this.hlsPlayer=new ae,this.hlsPlayer.attachMedia(this.video),this.hlsPlayer.loadSource(t)):pe((()=>{e.camera.isOnline?this.error=new qi("NO_PLAYABLE_STREAM_ERROR","no playable stream"):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))}),{fireImmediately:!0}))}catchUpAfterPause(){this.disposables.push(a(this.video,"play").pipe(we((()=>this.live))).subscribe(this.goLive))}dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.hlsPlayer&&this.hlsPlayer.destroy(),this.hlsPlayer=null,this.player=null}}class Gi{player;video;live=!0;loading=!0;error=null;state=null;disposables=[];availabilityStartTime=-1;constructor(e,t){this.player=e,this.video=t,this.initLoadingTimeout(),this.reactToCamera(),this.catchUpAfterPause(),he(this,{loading:ue,error:ue})}goLive(){this.video.currentTime=this.video.seekable.end(0)}getCurrentTime(){return this.availabilityStartTime<0&&this.updateAvailabilityStartTime(),new Date(this.availabilityStartTime+1e3*this.video.currentTime)}updateAvailabilityStartTime(){this.video.seekable.length&&(this.availabilityStartTime=Date.now()-1e3*this.video.seekable.end(0))}getDateRange(){const{availabilityStartTime:e}=this;if(e<0)return null;if(!this.video.seekable.length)return null;return[new Date(e+1e3*this.video.seekable.start(0)),new Date(e+1e3*this.video.seekable.end(0))]}seek(e){this.live=!1,this.availabilityStartTime<0&&(this.updateAvailabilityStartTime(),this.availabilityStartTime<0)?this.player.seekTime=e:this.video.currentTime=(+e-+this.availabilityStartTime)/1e3}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(3e4)):r))).subscribe((()=>{pe((()=>{this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})}))})))}reactToCamera(){this.disposables.push(ve((()=>({streamUrl:this.player.camera.streamUrl})),(()=>{const e=this.player.camera,{streamUrl:t}=e.raw;pe((()=>{this.loading=!0})),this.availabilityStartTime=-1,this.video.src="",t?this.video.src=t:pe((()=>{this.player.camera.isOnline?this.error=new qi("NO_PLAYABLE_STREAM_ERROR","no playable stream"):this.error=new qi("CAMERA_OFFLINE_ERROR","camera offline")}))}),{fireImmediately:!0}))}catchUpAfterPause(){this.disposables.push(a(this.video,"play").pipe(we((()=>this.live))).subscribe((()=>{console.log("unpaused live HLS"),this.goLive()})))}dispose(){this.disposables.forEach((e=>{e instanceof o?e.closed||e.unsubscribe():e()}))}}class Ji{player;video;disposables=[];state=null;loading=!1;error=null;constructor(e,t){this.player=e,this.video=t,this.playNextChunkOnComplete(),this.reactToChunk(),this.initLoadingTimeout(),he(this,{loading:ue,error:ue})}seek=e=>{if(!this.player.chunk)return;const t=this.player.clip&&this.player.clip.isTimelapse?1e3*this.player.chunk.duration/(+this.player.chunk.endTime-+this.player.chunk.startTime):1,i=(+e-+this.player.chunk.startTime)/1e3*t;this.video.currentTime=i};getCurrentTime(){const e=this.player.chunk;if(!e)return null;const{clip:t}=this.player,i=t&&t.isTimelapse&&this.video.duration?(+e.endTime-+e.startTime)/this.video.duration:1e3;return new Date(+e.startTime+this.video.currentTime*i)}reactToChunk(){this.disposables.push(ve((()=>this.player.chunk),(e=>{if(!e)return this.video.pause(),this.video.removeAttribute("src"),void this.video.load();this.loading=!0,this.video.src=e.streamUrl,this.video.playbackRate=this.player.playbackRate}),{fireImmediately:!0}))}playNextChunkOnComplete(){this.disposables.push(this.player.ended$.subscribe((()=>{const{currentTime:e}=this.player;if(e)if(this.player.clip&&this.player.clip.isTimelapse){const{archives:t}=this.player.clip;if(t){const i=t.find((t=>t.startTime>=e));if(!i||i===this.player.chunk)return;return void this.player.changeMedia({time:i?.startTime,chunk:i})}}else this.player.changeMedia({time:new Date(+this.player.chunk.endTime+1)});else console.warn("Couldn't jump to the next chunk. Current player time is unknown")})))}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(3e4)):r))).subscribe((()=>{this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})})))}resetVideo(){const{video:e}=this;e.pause(),e.removeAttribute("src"),e.load()}dispose(){this.disposables.forEach((e=>{e instanceof o?e.closed||e.unsubscribe():e()})),this.resetVideo(),this.player=null}}const Xi=new Map;class Ki{url;connection;sessionId;keepAliveIntervalId=null;pluginsCount=0;constructor(e){this.url=e,he(this,{sessionId:ue,pluginsCount:ue,registerPlugin:me,deregisterPlugin:me}),this.init()}registerPlugin=()=>{this.pluginsCount++};deregisterPlugin=()=>{this.pluginsCount--};async init(){const{url:e}=this;this.connection=new Ye(e,"janus-protocol",{maxReconnectionDelay:3e4}),this.startKeepingAlive(),this.stopWhenNoLongerNeeded(),this.connection.addEventListener("message",(({data:e})=>{const t=JSON.parse(e);"error"===t.janus&&458===t.error.code&&this.createSession()})),await new Promise((e=>{const t=()=>{this.connection.removeEventListener("open",t),e(void 0)};this.connection.addEventListener("open",t)})),this.createSession()}stopWhenNoLongerNeeded(){at((()=>this.pluginsCount),!0).pipe(be((e=>e?r:n(1e4)))).subscribe((()=>{this.dispose()}))}dispose(){this.connection.close(),Xi.delete(this.url)}async createSession(){const e=this.randomString(12);this.connection.send(JSON.stringify({janus:"create",transaction:e}));const t=await new Promise(((t,i)=>{const s=r=>{const n=JSON.parse(r.data);if(n.transaction===e){if(this.connection.removeEventListener("message",s),"success"===n.janus)return t(n.data.id);i(n.janus.error)}};this.connection.addEventListener("message",s)}));pe((()=>{this.sessionId=t}))}startKeepingAlive(){ge((()=>!!this.sessionId),(()=>{l((e=>this.connection.addEventListener("open",e)),(e=>this.connection.removeEventListener("open",e))).pipe(Te(null),be((()=>n(0,3e4).pipe(ke(l((e=>this.connection.addEventListener("close",e)),(e=>this.connection.removeEventListener("close",e)))))))).subscribe(this.keepAlive)}))}keepAlive=()=>{this.connection.send(JSON.stringify({janus:"keepalive",session_id:this.sessionId,transaction:this.randomString(12)}))};randomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let i="";for(let s=0;s<e;s++){const e=Math.floor(62*Math.random());i+=t.substring(e,e+1)}return i}}class es extends nt{}class ts{server;pc=null;pluginHandleId;stream=null;stats=null;error=null;disposables=[];cameraId;pin;connectionState=null;disposeDelayedStream;startTransaction;statsRequest=null;options={allowedIceCandidateProtocols:["udp","tcp"],iceServers:[{urls:"stun:stun.3deye.me:80"},{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all"};constructor(e,t,i,s){he(this,{pc:ue.ref,pluginHandleId:ue,stream:ue.ref,stats:ue.ref,error:ue.ref,connectionState:ue,onmessage:me,setStream:me,updateStats:me,dispose:me}),Object.assign(this.options,s),this.server=function(e){if(Xi.has(e)){const t=Xi.get(e);if(!t)throw new Error("Couldn't get server");return t}const t=new Ki(e);return Xi.set(e,t),t}(e),this.server.registerPlugin(),this.cameraId=t,this.pin=i,this.autoAttachPlugin(),this.autoCollectStats(),this.initConnectionState(),this.initTrack(),this.disposables.push(ve((()=>this.pluginHandleId),this.onInit,{fireImmediately:!0})),this.disposables.push(ge((()=>!!this.server.sessionId),(()=>this.disposables.push(l((e=>this.server.connection.addEventListener("message",e)),(e=>this.server.connection.removeEventListener("message",e)),(e=>e)).subscribe(this.onmessage)))))}onInit=e=>{if(!e)return;const{cameraId:t,pin:i}=this;this.pc&&(this.disposeDelayedStream&&(this.disposeDelayedStream(),this.disposeDelayedStream=null),this.safeCloseRTCPeerConnection(this.pc)),this.pc=new RTCPeerConnection({iceServers:this.options.iceServers,bundlePolicy:"max-bundle",iceTransportPolicy:this.options.iceTransportPolicy}),this.server.connection.send(JSON.stringify({janus:"message",handle_id:e,session_id:this.server.sessionId,body:{request:"watch",id:t,pin:i},transaction:this.server.randomString(12)}))};pause=()=>{this.server.connection.send(JSON.stringify({janus:"message",handle_id:this.pluginHandleId,session_id:this.server.sessionId,body:{request:"pause",id:this.cameraId},transaction:this.server.randomString(12)}))};resume=()=>{this.server.connection.send(JSON.stringify({janus:"message",handle_id:this.pluginHandleId,session_id:this.server.sessionId,body:{request:"start",id:this.cameraId},transaction:this.server.randomString(12)}))};onmessage=({data:e})=>{const{pluginHandleId:t}=this;if(!t)return;const i=JSON.parse(e);return"error"===i.janus&&i.transaction===this.startTransaction?(this.error=new es("STREAMING_ERROR",i.error.reason,i.error),console.error(i.error)):"sender"in i&&i.sender===t?"hangup"===i.janus?("ICE FAILED"===i.reason.toUpperCase()?this.error=new es("ICE_FAILED",i.reason,i):"CLOSE PC"===i.reason.toUpperCase()?this.error=new es("CLOSE_PC",i.reason,i):this.error=new es("STREAMING_ERROR",i.reason,i),console.error(i.reason)):"event"===i.janus&&i.plugindata?.data&&"error"in i.plugindata.data?(this.error=new es("STREAMING_ERROR",i.plugindata.data.error.reason,i.plugindata.data.error),console.error(i.plugindata.data)):void("jsep"in i&&this.onremotedescription(new RTCSessionDescription(i.jsep))):void 0};async onremotedescription(e){const{pluginHandleId:t}=this,i=this.pc;if(!e.sdp||!i)return;const s=[];if(1===this.options.allowedIceCandidateProtocols.length){const t=this.options.allowedIceCandidateProtocols[0],i=e.sdp.split("\r\n");let r="video";const n={video:[],audio:[]};for(const e of i)e.startsWith("a=mid:audio")?r="audio":e.startsWith("a=mid:video")?r="video":e.startsWith("a=candidate")&&n[r].push(e);const a=i.filter((e=>!(e.startsWith("a=candidate")||e.startsWith("a=end-of-candidates")))),o=e=>e.split(/\s+/)[2]===t,l={video:n.video.filter(o),audio:n.audio.filter(o)};e=new RTCSessionDescription({type:"offer",sdp:[...a].join("\r\n")});let c={audio:[],video:[]};l.video.length?c=l:(console.warn(`no video ${t.toUpperCase()} candidates found. Falling back to all candidates`),c=n);for(const e in c)if(Object.hasOwn(c,e))for(const t of c[e])s.push(new RTCIceCandidate({candidate:t.replace(/^a=/,""),sdpMLineIndex:0,sdpMid:e}))}try{await i.setRemoteDescription(e),s.length>1&&([s[0],s[1]]=[s[1],s[0]]),await Promise.allSettled(s.map((e=>i.addIceCandidate(e))));const r=await i.createAnswer();await i.setLocalDescription(r);const n={type:r.type,sdp:r.sdp};this.startTransaction=this.server.randomString(12),this.server.connection.send(JSON.stringify({janus:"message",handle_id:t,session_id:this.server.sessionId,body:{request:"start"},jsep:n,transaction:this.startTransaction}))}catch(e){return console.error(e),void pe((()=>{e instanceof Error&&e.message.toLowerCase().includes("failed to set remote offer sdp")?this.error=new es("SDP_OFFER_FAILED",e.message,e):e instanceof Error&&e.message.toLowerCase().includes("failed to set local answer sdp")?this.error=new es("SDP_ANSWER_FAILED",e.message,e):this.error=new es("STREAMING_ERROR",e instanceof Error?e.message:e,e)}))}i.addEventListener("icecandidate",(e=>{e.candidate&&this.server.connection.send(JSON.stringify({janus:"trickle",candidate:e.candidate,handle_id:t,session_id:this.server.sessionId,transaction:this.server.randomString(12)}))}))}setStream=e=>{this.disposeDelayedStream&&this.disposeDelayedStream(),null!==e?this.disposeDelayedStream=ge((()=>"completed"===this.connectionState||"connected"===this.connectionState),(()=>{this.stream=e})):this.stream=null};autoAttachPlugin(){this.disposables.push(at((()=>this.server?this.server.sessionId:null),!0).pipe(we(Boolean),be((()=>{const e=this.server.randomString(12);return this.server.connection.send(JSON.stringify({janus:"attach",plugin:"janus.plugin.streaming",transaction:e,session_id:this.server.sessionId})),l((e=>this.server.connection.addEventListener("message",e)),(e=>this.server.connection.removeEventListener("message",e)),(({data:e})=>JSON.parse(e))).pipe(we((t=>"transaction"in t&&t.transaction===e)),Pe(1))}))).subscribe((e=>{pe((()=>{switch(e.janus){case"success":this.pluginHandleId=e.data.id;break;case"error":this.error=new es("PLUGIN_INIT_ERROR",e.error.reason,e);break;default:console.error("unexpected message",e)}}))})))}initConnectionState=()=>{this.disposables.push(at((()=>this.pc),!0).pipe(be((e=>null===e?t(null):a(e,"iceconnectionstatechange").pipe(Te(null),Se((()=>e.iceConnectionState)))))).subscribe((e=>{pe((()=>{this.connectionState=e}))})))};initTrack=()=>{this.disposables.push(at((()=>this.pc),!0).pipe(be((e=>null===e?t(null):l((t=>e.addEventListener("track",t)),(t=>e.removeEventListener("track",t)),(e=>e)).pipe(Te(null))))).subscribe((e=>{let t=null;null!==e&&(t=e.streams[0],e.track&&(e.track.onended=e=>{this.stream&&this.stream.removeTrack(e.target)})),this.setStream(t)})))};autoCollectStats=()=>{this.disposables.push(at((()=>this.stream),!0).pipe(be((e=>e?n(0,1e3).pipe(Me((()=>this.getStats()))):t(null)))).subscribe(this.updateStats))};updateStats=e=>{if(e){if(this.stats){const t=e.bytesReceived-this.stats.bytesReceived,i=e.timestamp-this.stats.timestamp;e.bitrate=t/i,e.startTime=this.stats.startTime}else e.startTime=e.timestamp;this.stats=e}else this.stats=null};async getStats(){if(!this.pc)return null;this.statsRequest=this.pc.getStats();const e=await this.statsRequest;this.statsRequest=null;const t={};return e.forEach((e=>{if("inbound-rtp"!==e.type||"video"!==e.kind&&"video"!==e.mediaType){if("track"===e.type){const{frameWidth:i,frameHeight:s,framesDropped:r,framesReceived:n}=e;Object.assign(t,{frameWidth:i,frameHeight:s,framesDropped:r,framesReceived:n})}else if("candidate-pair"===e.type)Object.assign(t,{rtt:1e3*e.currentRoundTripTime});else if("ssrc"===e.type){const i={};for(const t of e.values)for(const e of Object.keys(t))i[e]=t[e];const{framesDecoded:s,bytesReceived:r,packetsLost:n,packetsReceived:a,googFrameHeightReceived:o,googFrameWidthReceived:l}=i;Object.assign(t,{frameWidth:+l,frameHeight:+o,framesDecoded:s,bytesReceived:r,packetsLost:n,packetsReceived:a})}}else{const{bytesReceived:i,framesDecoded:s,packetsLost:r,packetsReceived:n,timestamp:a}=e;Object.assign(t,{bytesReceived:i,framesDecoded:s,packetsLost:r,packetsReceived:n,timestamp:a})}})),t}async safeCloseRTCPeerConnection(e){await this.statsRequest,e.close()}dispose=()=>{this.disposeDelayedStream&&(this.disposeDelayedStream(),this.disposeDelayedStream=null),this.pc&&this.safeCloseRTCPeerConnection(this.pc);for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.server.deregisterPlugin(),this.server.connection.send(JSON.stringify({janus:"detach",handle_id:this.pluginHandleId,session_id:this.server.sessionId,transaction:this.server.randomString(12)})),this.pc=null,this.stream=null,this.stats=null,this.error=null}}const is=1e4;class ss{player;options;streamingPlugin;disposables=[];state=null;setPlayerState(e){this.state=e}ttff=-1;live=!0;loading=!1;error=null;get streamingError(){return this.streamingPlugin?this.streamingPlugin.error:null}get stream(){return this.streamingPlugin?this.streamingPlugin.stream:null}getCurrentTime(){return this.state===Wi.Playing?new Date:null}constructor(e,t){this.player=e,this.options=t,he(this,{streamingPlugin:ue.ref,state:ue,setPlayerState:me,ttff:ue,streamingError:ce,stream:ce,loading:ue,error:ue,dispose:me}),this.player=e,RTCPeerConnection?this.disposables.push(this.reactToStream(),...this.initPauseAndResume(),this.reconnectWhenNeeded(),this.fallbackToDvrOnFirstFrameTimeout(),this.fallBackToDvrOnConnectionProblems(),this.initTransitionToReconnecting(),this.setInitialIndication(),this.updateIndicationOnPlaying(),this.updateIndicationOnReconnecting(),this.initFromErrorToPlaying(),this.initFromInitialToPlaying(),this.reactToStreamingError(),this.initTtff(),this.initStats(),this.reactToCamera()):this.state=Wi.Failed}reconnectWhenNeeded(){return at((()=>this.state),!0).pipe(c((e=>{if(e!==Wi.Reconnecting)return r;this.streamingPlugin&&this.streamingPlugin.dispose();const{webRtcUrl:t,id:i,pin:s}=this.player.camera;return pe((()=>{this.streamingPlugin=new ts(t,i,s,this.options)})),at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),h(3e4)):r)),u(1))}))).subscribe({next:()=>{this.setPlayerState(Wi.Playing)},error:e=>{if(e instanceof m)return console.error("player",this.player.id,"cam",this.player.camera.id,"no frames in 30s after reconnect"),void(this.streamingPlugin?.pc&&["connected","new"].includes(this.streamingPlugin.pc.iceConnectionState)?(console.warn("player",this.player.id,"cam",this.player.camera.id,"fallback to DVR"),this.state=Wi.Stalled):console.warn("player",this.player.id,"cam",this.player.camera.id,"waiting for reconnect"));pe((()=>{this.setPlayerState(Wi.Error),this.error=e})),console.error(e)}})}fallbackToDvrOnFirstFrameTimeout(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),h(is)):r)),u(1))))).subscribe({error:e=>{if(e instanceof m)return console.error("player",this.player.id,"cam",this.player.camera.id,"no frames in 10s. Fallback to DVR"),void this.setPlayerState(Wi.Stalled);pe((()=>{this.setPlayerState(Wi.Error),this.error=e})),console.error(e)}})}fallBackToDvrOnConnectionProblems(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.streamingPlugin?.connectionState),!0).pipe(c((e=>e&&"connected"!==e&&"new"!==e?"failed"===e?p((()=>new qi("CONNECTION_FAILED_ERROR","Connection failed"))):n(2e4).pipe(v((()=>p((()=>new qi("CONNECTION_TIMEOUT_ERROR","Connection timeout")))))):r)))))).subscribe({error:e=>e instanceof qi&&"CONNECTION_TIMEOUT_ERROR"===e.name?(console.error("player",this.player.id,"cam",this.player.camera.id,"no connection established in 20s. Fallback to DVR"),void this.setPlayerState(Wi.Stalled)):e instanceof qi&&"CONNECTION_FAILED_ERROR"===e.name?(console.error("player",this.player.id,"cam",this.player.camera.id,"Connection failed"),void this.setPlayerState(Wi.Stalled)):(pe((()=>{this.state=Wi.Error,this.error=e})),void console.error(e))})}initTransitionToReconnecting(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Playing?r:at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),g(is))))).subscribe((()=>{console.log("player",this.player.id,"cam",this.player.camera.id,"no new frames in 10000s"),this.setPlayerState(Wi.Reconnecting)}))}setInitialIndication(){return ve((()=>this.state),(e=>{e===Wi.Initial&&pe((()=>{this.loading=!0,this.error=null}))}))}updateIndicationOnPlaying(){return ve((()=>this.state),(e=>{e===Wi.Playing&&pe((()=>{this.loading=!1,this.error=null}))}))}updateIndicationOnReconnecting(){return ve((()=>this.state),(e=>{e===Wi.Reconnecting&&pe((()=>{this.loading=!0}))}))}reactToStreamingError(){return ve((()=>this.streamingError),(e=>{if(!e)return;console.error(e);if("PLUGIN_INIT_ERROR"===e.name||"ERROR_PROCESSING_SDP"===e.name||"ICE_FAILED"===e.name||"SDP_OFFER_FAILED"===e.name||"CLOSE_PC"===e.name||"SDP_ANSWER_FAILED"===e.name)return console.warn("player",this.player.id,"cam",this.player.camera.id,"fallback to DVR"),this.error=new qi("STREAMING_ERROR",e.message,e),void this.setPlayerState(Wi.Stalled);pe((()=>{this.error=new qi("STREAMING_ERROR",e.message,e),this.state=Wi.Error}))}))}initTtff(){const e=Date.now();return at((()=>this.state),!0).pipe(d((e=>e===Wi.Playing)),u(1)).subscribe((()=>{this.ttff=Date.now()-e}))}initFromErrorToPlaying(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Error?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?this.streamingPlugin.stats?.framesDecoded:null)):r)),d(Boolean),u(1))))).subscribe((()=>{this.setPlayerState(Wi.Playing)}))}initFromInitialToPlaying(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null)):r)),d(Boolean),u(1))))).subscribe((()=>{this.setPlayerState(Wi.Playing)}))}initPauseAndResume(){return[at((()=>this.state),!0).pipe(d((e=>e===Wi.Playing||e===Wi.Paused))).subscribe((e=>{e===Wi.Playing?this.streamingPlugin?.resume():this.streamingPlugin?.pause()})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Playing?r:at((()=>this.player.paused)).pipe(d(Boolean))))).subscribe((()=>{this.setPlayerState(Wi.Paused)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Paused?r:at((()=>this.player.paused)).pipe(d((e=>!e)))))).subscribe((()=>{this.setPlayerState(Wi.Playing)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.player.paused)).pipe(d((e=>e)))))).subscribe((()=>{this.streamingPlugin?.dispose(),this.loading=!1,this.setPlayerState(Wi.InitiallyPaused)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.InitiallyPaused?r:at((()=>this.player.paused)).pipe(d((e=>!e)))))).subscribe(this.transitionToInitialState)]}reactToCamera(){return ve((()=>({id:this.player.camera.id,url:this.player.camera.webRtcUrl,pin:this.player.camera.pin,isOnline:this.player.camera.isOnline,enabled:this.player.camera.enabled})),(({id:e,isOnline:t},i)=>{this.streamingPlugin&&this.streamingPlugin.dispose(),pe((()=>{t?this.player.paused&&e===i?.id?this.state=Wi.InitiallyPaused:this.transitionToInitialState():(this.error=new qi("CAMERA_OFFLINE_ERROR","Camera is offline"),this.state=Wi.Error,this.streamingPlugin=null)}))}),{fireImmediately:!0})}reactToStream(){return ve((()=>this.stream),(e=>{pe((()=>{if(!e){if(this.state===Wi.Reconnecting)return;return void(this.player.stream=null)}this.player.stream=e;const t=e.getVideoTracks();t&&0!==t.length||(console.warn("player",this.player.id,"cam",this.player.camera.id,"no video",t),this.error=new qi("NO_VIDEO_TRACK_ERROR","No video track"),this.state=Wi.Error)}))}))}initStats(){return ve((()=>this.streamingPlugin?this.streamingPlugin.stats:null),(e=>{this.player.stats=e}))}transitionToInitialState=()=>{const{webRtcUrl:e,id:t,pin:i}=this.player.camera;pe((()=>{this.streamingPlugin&&this.streamingPlugin.dispose(),this.streamingPlugin=new ts(e,t,i,this.options),this.state=Wi.Initial}))};dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.player.stream&&(this.player.stream=null),this.streamingPlugin&&this.streamingPlugin.dispose(),this.streamingPlugin=null,this.player.stats=null,this.player=null}}const rs=(()=>{let e=0;return()=>++e})();class ns{id=rs();disposables=[];liveChunk;currentTime=null;targetTime=null;chunk=null;paused=!1;error=null;get loading(){return this.behavior?.loading??!1}playbackRate=1;volume=1;muted=!0;videoResizeMode="fill";camera;stats=null;mode=null;behavior=null;transform=null;isRotating=!1;setTransform=(e,t=!1)=>{const{translate:{tx:i,ty:s},rotation:{angle:r},scale:{sx:n}}=De(e??Oe());this.isRotating=!1,this.animationController.start({scale:n,x:i,y:s,angle:r,immediate:!t})};resetTransform=()=>{this.isRotating=!1,this.setTransform(Oe())};animationController=new Ge({scale:1,x:0,y:0,angle:0,onChange:e=>{pe((()=>{if(this.isRotating){const t=this.transform??Oe(),{rotation:{angle:i}}=De(t);this.transform=_e(Ae(e.value.angle-i,this.width/2,this.height/2),t)}else this.transform=_e(ze(e.value.x,e.value.y),Fe(e.value.scale,e.value.scale),Ae(e.value.angle))}))}});width=0;height=0;chunkRequest=null;loopRange=null;loopRangeEnabled=!1;restoreFromDvrEnabled=!1;pendingBehavior=null;video;clip;startTime=null;endTime=null;stream=null;canSeek=!1;canSeek$;progress$;muted$;volume$;ended$;archivesStore;behaviors;seekTime;constructor({camera:e,startTime:t,endTime:i,clip:s,archivesStore:r,behaviors:n}){fe(this,{behavior:ue.ref,camera:ue.ref,chunk:ue.ref,chunkRequest:ue.ref,liveChunk:ue.ref,loopRange:ue.ref}),this.camera=e,this.startTime=t||null,this.endTime=i||null,this.clip=s,this.archivesStore=r,this.behaviors=n,s?(this.loopRange={start:s.startTime,end:s.endTime},this.loopRangeEnabled=!0):this.loopRange=null,this.disposables.push(ve((()=>this.behavior?.error),(()=>{this.error=this.behavior?.error??null})))}attach(e,{canSeek$:t,progress$:i,muted$:s,volume$:r,ended$:n}){this.video=e,this.canSeek$=t,this.progress$=i,this.ended$=n,this.muted$=s,this.volume$=r,this.reactToVolumeChange(),this.initPlayerBehavior(),this.seekAfterReady(),this.stopLoadingOnError(),this.initChunkRequest(),this.initLiveChunkUpdate(),this.initCurrentTime(),this.initSameChunkRequestFix(),this.setupLiveChunk(),this.replaceErrorMessageOnOffline(),this.disposables.push(this.canSeek$.subscribe((()=>{this.canSeek=!0}))),this.disposables.push(ve((()=>({camera:this.camera,startTime:this.startTime})),(({startTime:e})=>{pe((()=>{this.chunk&&this.chunk.cameraId!==this.camera.id&&(this.chunk=null,this.currentTime=null),this.chunkRequest=null,this.setupLiveChunk(),e?this.changeMedia({time:e}):this.goLive()}))}))),this.clip||this.startTime||this.mode||this.goLive(),!this.clip&&this.startTime&&this.changeMedia({time:this.startTime}),this.initPlayableRange(),this.initUpgradeToWebRtcWhenCameraIsBackOnline(),this.initUpgradeToWebRtcAfterFallbackToDvr(),this.initFallbackToDVR()}seek=e=>{"WebRTC"!==this.mode?this.behavior&&this.behavior.seek?this.behavior.seek(e):console.warn("incorrect call of seek"):console.warn("cannot seek in live mode")};seekAfterReady(){this.disposables.push(this.canSeek$.pipe(c((()=>f(t(null),this.progress$.pipe(u(1)))))).pipe(y((()=>this.seekTime)),d(Boolean)).subscribe((e=>{this.seekTime=null,this.seek(e)})))}stopLoadingOnError(){this.disposables.push(ve((()=>this.error),(e=>{e&&this.behavior&&(this.behavior.loading=!1)})))}replaceErrorMessageOnOffline(){this.disposables.push(at((()=>this.error),!0).pipe(c((e=>e?at((()=>this.camera.isOnline),!1).pipe(d((e=>!e))):r))).subscribe((()=>{this.error instanceof qi&&"CAMERA_OFFLINE_ERROR"===this.error.name||(this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline"))})))}changeMedia=({time:e,chunk:t,backward:i=!1})=>{if(this.restoreFromDvrEnabled=!1,this.targetTime=e??null,this.loopRange&&e>=this.loopRange.end&&(this.loopRangeEnabled=!1),this.loopRange&&e<this.loopRange.end&&(this.loopRangeEnabled=!0),!t&&this.chunk&&this.chunk.startTime<=e&&(this.chunk.endTime>=e||this.chunk.isLive)&&(t=this.chunk),!t)return this.chunkRequest={time:e,backward:i},this.canSeek=!1,void(this.mode="archive");if(t){if(this.chunkRequest=null,this.paused&&(this.paused=!1),"WebRTC"!==this.mode&&t===this.chunk&&this.canSeek)return this.seek(e);this.canSeek=!1,this.error=null,this.mode=t.isLive?"DVR":"archive",this.chunk=t,this.seekTime=e}};initCurrentTime(){this.disposables.push(this.progress$.pipe(d((()=>!this.seekTime&&!this.chunkRequest)),d((()=>!this.paused))).subscribe((()=>{if(!this.behavior)return;const e=this.behavior.getCurrentTime();e&&pe((()=>{this.behavior&&(this.behavior.loading=!1),this.error=null,this.currentTime=e,this.targetTime=null}))})))}initPlayableRange(){this.disposables.push(at((()=>({enabled:this.loopRangeEnabled,paused:this.paused,startTime:this.loopRange?.start,endTime:this.loopRange?.end})),!0).pipe(c((({enabled:e,paused:t,startTime:i,endTime:s})=>e&&!t&&s&&i?at((()=>this.currentTime),!0).pipe(b(),d((([e,t])=>null!==e&&null!==t&&e<s&&t>=s))):r))).subscribe((()=>{this.loopRange&&this.changeMedia({time:this.loopRange.start})})))}initSameChunkRequestFix(){this.disposables.push(this.progress$.pipe(d((()=>!this.chunkRequest&&!!this.seekTime&&!this.chunk?.isLive))).subscribe((()=>{this.seekTime&&this.chunk&&this.chunk.startTime<=this.seekTime&&this.chunk.endTime>=this.seekTime&&(this.seek(this.seekTime),this.seekTime=null)})))}initLiveChunkUpdate(){this.disposables.push(at((()=>this.liveChunk),!0).pipe(c((e=>e?R(250):r))).subscribe((()=>{pe((()=>{if("DVR"===this.mode&&this.behavior&&"function"==typeof this.behavior.getDateRange&&this.liveChunk){const e=this.behavior.getDateRange();if(!e)return;this.liveChunk.setBounds(e)}"DVR"!==this.mode&&this.liveChunk&&!this.liveChunk.managed&&this.liveChunk.setBounds([new Date(Date.now()-1e3*this.camera.raw.dvrWindowLength),new Date])}))})))}initChunkRequest(){this.disposables.push(at((()=>this.chunkRequest),!0).pipe(c((e=>{if(null===e)return r;const{time:i,backward:s}=e;if(this.clip?.isTimelapse&&this.clip.archives){const{archives:e}=this.clip,r=e.find((e=>e.startTime<=i&&e.endTime>=i));if(r)return t({chunk:r,time:i,backward:s});if(s){const r=e.find((e=>e.endTime<i));return t(r?{chunk:r,time:i,backward:s}:{chunk:null,time:i,backward:s})}const n=e.find((e=>e.startTime>i));return t(n?{chunk:n,time:i,backward:s}:{chunk:null,time:i,backward:s})}const n=this.camera.id,a=this.archivesStore.getChunks({cameraId:this.camera.id,from:i,to:i})[0];if(a)return t({chunk:a,time:i,backward:s});return(s?this.archivesStore.fetchPrevChunk({cameraId:n,time:i}):this.archivesStore.fetchNextChunk({cameraId:n,time:i})).pipe(y((e=>e?s?i<=e.endTime?{chunk:e,time:i,backward:s}:{chunk:e,time:new Date(+e.endTime-5e3),backward:s}:{chunk:e,time:new Date(Math.max(+e.startTime,+i)),backward:s}:this.liveChunk&&this.liveChunk.startTime<i?{chunk:this.liveChunk,time:i,backward:s}:{chunk:null,time:i,backward:s})))}))).subscribe((({chunk:e,time:t,backward:i})=>{pe((()=>{if(!e){if(i||!this.liveChunk)return void(this.chunkRequest=null);e=this.liveChunk}this.currentTime=e.startTime,this.changeMedia({chunk:e,time:t})}))})))}setupLiveChunk(){const{camera:e}=this;e.streamUrl&&e.raw.dvrWindowLength?this.liveChunk?.cameraId!==e.id&&pe((()=>{this.liveChunk=new ct({cameraId:e.id,endTime:new Date,startTime:new Date(Date.now()-e.dvrWindowLength),streamUrl:e.streamUrl,dashStreamUrl:e.dashStreamUrl,length:e.dvrWindowLength})})):this.liveChunk=null}initPlayerBehavior(){this.disposables.push(at((()=>this.mode),!0).pipe(C((async e=>{if(this.behavior){const e=this.behavior;pe((()=>{this.behavior=null})),await e.dispose()}return e}))).subscribe((e=>{e&&pe((()=>{if("WebRTC"===e&&this.pendingBehavior)return this.behavior=this.pendingBehavior,void(this.pendingBehavior=null);const t=this.behaviors[e];this.behavior=t?t(this):null}))})))}seekBackward=e=>{if(!this.currentTime&&this.targetTime)return;!this.currentTime&&this.behavior?.live&&this.changeMedia({time:new Date(Date.now()-e),backward:!0});const t=this.targetTime||this.currentTime;if(!t)return;const i=new Date(+t-e);this.changeMedia({time:i,backward:!0})};seekForward=e=>{if(!this.currentTime&&this.targetTime)return;const t=this.targetTime||this.currentTime;if(!t)return;const i=new Date(+t+e);this.liveChunk&&i>this.liveChunk.endTime?this.goLive():this.changeMedia({time:i,backward:!1})};goLive=()=>{this.seekTime=null,this.playbackRate=1,this.paused=!1,this.behaviors.WebRTC?this.mode="WebRTC":"DVR"===this.mode?this.behavior?.goLive?.():(this.mode="DVR",this.chunk=this.liveChunk||null)};setCamera=e=>{this.camera=e};setCameraAndStartTime=(e,t)=>{this.camera=e,this.startTime=t};toggleResizeMode=()=>{"contain"!==this.videoResizeMode?this.videoResizeMode="contain":this.videoResizeMode="fill"};setVideoResizeMode=e=>{this.videoResizeMode=e};toggleMute=()=>{this.muted=!this.muted};setStartTime=e=>{this.startTime=e};setVolume=e=>{this.volume=e};setPlaybackRate=e=>{this.playbackRate=e};reactToVolumeChange(){this.disposables.push(this.volume$.subscribe(this.setVolume))}togglePlayback=()=>{this.paused=!this.paused};play=()=>{this.paused=!1};pause=()=>{this.paused=!0};detach=()=>{this.behavior&&(this.behavior.dispose(),this.behavior=null);for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.video=null};initUpgradeToWebRtcWhenCameraIsBackOnline(){this.behaviors.WebRTC&&this.disposables.push(at((()=>!this.paused&&"DVR"===this.mode&&this.behavior?.live),!0).pipe(c((e=>e?at((()=>this.camera.isOnline)).pipe(c((e=>e?(this.goLive(),r):r))):r))).subscribe())}initFallbackToDVR=()=>{this.disposables.push(at((()=>this.behavior),!0).pipe(c((e=>"WebRTC"===this.mode&&e?at((()=>e.state),!0).pipe(d((e=>e===Wi.Stalled||e===Wi.Failed))):r))).subscribe((e=>{pe((()=>{this.seekTime=null,this.mode="DVR",this.chunk=this.liveChunk||null,this.restoreFromDvrEnabled=e!==Wi.Failed}))})))};initUpgradeToWebRtcAfterFallbackToDvr(){if(!this.behaviors.WebRTC)return;let e=null;this.disposables.push(at((()=>({enabled:this.restoreFromDvrEnabled,mode:this.mode,paused:this.paused}))).pipe(c((({mode:i,enabled:s,paused:n})=>"DVR"!==i||!s||n?(e&&(e.dispose(),e=null),r):t(null).pipe(w(1e4),c((()=>{if(!this.behaviors.WebRTC)return r;e&&(e.dispose(),e=null),e=this.behaviors.WebRTC(this);const i=e;return at((()=>i.state),!0).pipe(v((()=>{const{state:s}=i;if(!s)return r;if(s===Wi.Playing)return t(s);if([Wi.Error,Wi.Failed,Wi.Stalled].includes(s)){i.dispose(),e=null;const t=i.error;return p((()=>new Error(s,{cause:t})))}return r})),u(1))})),et({initialInterval:1e4,maxInterval:8e4,shouldRetry:e=>!(e instanceof Error&&e.message===Wi.Failed)}))))).subscribe({next:()=>{pe((()=>{this.seekTime=null,this.playbackRate=1,this.paused=!1,this.pendingBehavior=e,e=null,this.mode="WebRTC",this.restoreFromDvrEnabled=!1}))},error:t=>{console.error("Failed to upgrade to WebRTC after fallback to DVR",t),pe((()=>{e=null,this.restoreFromDvrEnabled=!1}))}}))}}class as{disposables=[];constructor(e,t){const i=f(a(e,"play").pipe(xe(!1)),a(e,"pause").pipe(xe(!0))),s=a(e,"volumechange").pipe(Se((()=>e.volume)),Ie()),n=a(e,"timeupdate"),o=f(a(e,ht?"loadeddata":"loadedmetadata"),a(e,"playing")),l=a(e,"ended"),c=a(e,"volumechange").pipe(Se((()=>e.muted)),Ie());t.attach(e,{canSeek$:o,ended$:l,progress$:n,volume$:s,muted$:c}),this.disposables.push(ve((()=>t.stream),(t=>{e.srcObject=t}))),this.disposables.push(ve((()=>t.volume),(t=>{e.volume=t}))),this.disposables.push(ve((()=>t.playbackRate),(t=>{e.playbackRate=t}))),this.disposables.push(a(e,"canplay").subscribe((()=>{e.playbackRate!==t.playbackRate&&(e.playbackRate=t.playbackRate)}))),this.disposables.push(a(e,"error").subscribe((()=>{e.error&&(console.error(e.error),t.error=new qi("MEDIA_ERROR",e.error.message,e.error))}))),this.disposables.push(a(e,"seeking").subscribe((()=>{pe((()=>{t.behavior&&(t.behavior.loading=!0)}))}))),this.disposables.push(a(e,"pause").subscribe((()=>{pe((()=>{t.behavior&&(t.behavior.loading=!1)}))})));const d=new T;let h=!1;this.disposables.push(f(at((()=>t.paused)),d).pipe(Ee((t=>(h=t,t&&e.paused||!t&&!e.paused?r:t?(e.pause(),r):e.play().catch((e=>console.error(e))))))).subscribe((e=>{e!==h&&d.next(e)}))),this.disposables.push(i.subscribe((e=>{(e&&!t.paused||!e&&t.paused)&&d.next(t.paused)}))),this.disposables.push(a(e,"seeked").subscribe((()=>{t.paused||d.next(!1)})))}dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e()}}const os=B((()=>{const e=z(ki),t=z(rt),{utc:i,hour12:s}=t?.account.preferences??{utc:!1,hour12:!1},r=Q((()=>{const e=new Intl.DateTimeFormat(st.language,{timeStyle:"medium",timeZone:i?"UTC":void 0,hour12:s||void 0,hourCycle:s?void 0:"h23"}),t=new Intl.DateTimeFormat(st.language,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZone:i?"UTC":void 0,hour12:s||void 0,hourCycle:s?void 0:"h23"});return s=>((e,t,i)=>i?e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate():e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate())(s,new Date,i)?e.format(s):t.format(s)}),[i,s]);return t&&"activeLayoutView"in t?e.behavior&&e.behavior instanceof ss?null:P("div",{className:W("x-3deye-player__current-time",{"x-3deye-player__current-time--synced":t.activeLayoutView?.synced?.players.includes(e)}),children:e.currentTime&&r(e.currentTime)}):null}));os.displayName="CurrentTimeIndicator";var ls=os;const cs=e=>{const t=Math.floor(e)%60;return`- ${(Math.floor(e)-t)/60}:${t<10?`0${t}`:t}`},ds=B((()=>{const e=z(ki);if(e.endTime)return null;if(!e.camera.isOnline)return null;if(e.error)return null;if(e.behavior?.live&&e.behavior.delay&&e.behavior.delay>1)return P(vt,{className:"x-3deye-delay-indicator",style:{pointerEvents:"auto"},onClick:e.behavior.goLive,children:cs(e.behavior.delay)});return!e.paused&&(e.behavior&&e.behavior instanceof ss)?P("div",{className:"x-3deye-live-indicator",children:st.t("playerTools.live")}):P(vt,{style:{pointerEvents:"auto"},className:"x-3deye-button--live",onClick:e.goLive,tabIndex:-1,children:st.t("playerTools.goLive")})}));ds.displayName="LiveIndicator";var hs=ds;const us=B((()=>{const e=E(null),t=z(ki),i=E(!1);return A((()=>{const t=e.current;if(!t)return;const i=()=>{t.style.display="none"};return t.addEventListener("animationend",i),()=>{t.removeEventListener("animationend",i)}}),[]),A((()=>{e.current&&(i.current?e.current.style.display="block":i.current=!0)})),P("div",{ref:e,className:"x-3deye-player__playback-indicator",children:t.paused?P(xt,{size:32,color:"rgba(255, 255, 255, 0.8)"}):P(Et,{size:32,color:"rgba(255, 255, 255, 0.8)"})})}));us.displayName="PlaybackIndicator";var ms=us;const ps=B((()=>{const e=z(ki);if(!e.error)return null;const t=e.error?"CONNECTION_TIMEOUT_ERROR"===e.error.name?st.t("player.playbackTimeoutError",{count:e.error.cause.count}):"CAMERA_OFFLINE_ERROR"===e.error.name?e.camera.enabled?st.t("player.cameraIsOffline"):st.t("player.cameraIsDisabled"):"NO_PLAYABLE_STREAM_ERROR"===e.error.name?st.t("player.noPlayableStream"):"NO_VIDEO_TRACK_ERROR"===e.error.name?st.t("player.noVideoTrack"):st.t("player.genericError"):null;return P("div",{style:{position:"absolute",top:0,left:0,bottom:0,right:0,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:P("span",{style:{backgroundColor:"rgba(0, 0, 0, 0.5)",padding:"8px 16px",fontSize:12},children:t})})}));function vs(e,t,i){return t<i?Math.max(Math.min(e,i),t):Math.max(Math.min(e,t),i)}function gs(e,t,i){e=Ue(e);const s=Be(e,[[0,0],[0,i],[t,0],[t,i]]),r=Math.min(...s.map((e=>e[0]))),n=Math.max(...s.map((e=>e[0]))),a=Math.min(...s.map((e=>e[1]))),o=Math.max(...s.map((e=>e[1]))),{scale:{sx:l},rotation:{angle:c}}=De(e);if(c<0)if(c>-Math.PI/2){const s=-Math.sin(c)*l*t;e.e=vs(e.e,t+r-n,0),e.f=vs(e.f,s-o+a+i,s)}else{const s=-Math.cos(c)*l*t;e.e=vs(e.e,s,t+r-n+s),e.f=vs(e.f,i,o-a)}if(c>0)if(c<Math.PI/2){const s=Math.sin(c)*l*i;e.e=vs(e.e,s-n+r+t,s),e.f=vs(e.f,i+a-o,0)}else{const s=-Math.cos(c)*l*i;e.e=vs(e.e,t,n-r),e.f=vs(e.f,i+a-o+s,s)}return 0===c&&(e.e=vs(e.e,(1-l)*t,0),e.f=vs(e.f,(1-l)*i,0)),e}const fs=B((({hideCameraTitle:e,width:t,height:i,onDoubleClick:s,onAuxClick:r,onMouseDown:n,children:a})=>{const o=z(ki),l=x.useRef(null),c=x.useRef(null),d=`zoom-slider-${o.id}`,h=200,u=136,m=()=>{const e=o.transform??Oe();if(!c.current)return;const t=c.current.querySelector(".x-3deye-player__zoomable");if(!t)return;t.style.transformOrigin="0 0";const{scale:{sx:i},translate:{tx:s,ty:r},rotation:{angle:n}}=De(e);if(0===n){const e=1/i,n=-s/(o.width/h)*e,a=-r/(o.height/u)*e;return void(t.style.transform=$e(_e(ze(n,a),Fe(e))))}const{width:a,height:l}=o,d=Be(e,[[0,0],[0,l],[a,0],[a,l]]),m=Math.min(...d.map((([e])=>e))),p=Math.max(...d.map((([e])=>e))),v=Math.min(...d.map((([e,t])=>t))),g=Math.max(...d.map((([e,t])=>t)));let f=0,y=0,b=1,R=[0,1],C=[0,1];if(n<0&&n>-Math.PI/2){const s=-Math.sin(n)*i*a;b=a/(a+Math.abs(a+m-p)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([0,a+m-p],R)(e.e),y=qe([s,s-g+v+l],C)(e.f),t.dataset.factorX=((a+m-p)/(R[1]-R[0])).toString(),t.dataset.factorY=((-g+v+l)/(C[1]-C[0])).toString()}if(n<0&&n<-Math.PI/2){const s=-Math.cos(n)*i*a;b=a/(a+Math.abs(a+m-p)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([s,a+m-p+s],R)(e.e),y=qe([g-v,l],C)(e.f),t.dataset.factorX=((a+m-p)/(R[1]-R[0])).toString(),t.dataset.factorY=((l-g+v)/(C[1]-C[0])).toString()}if(n>0&&n<Math.PI/2){const s=Math.sin(n)*i*l;b=l/(l+Math.abs(l+v-g)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([s,s-p+m+a],R)(e.e),y=qe([0,l+v-g],C)(e.f),t.dataset.factorX=((-p+m+a)/(R[1]-R[0])).toString(),t.dataset.factorY=((l+v-g)/(C[1]-C[0])).toString()}if(n>0&&n>Math.PI/2){const s=-Math.cos(n)*i*l;b=l/(l+Math.abs(l+v-g)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([p-m,a],R)(e.e),y=qe([s,l+v-g+s],C)(e.f),t.dataset.factorX=((a-p+m)/(R[1]-R[0])).toString(),t.dataset.factorY=((l+v-g)/(C[1]-C[0])).toString()}t.style.transform=$e(_e(ze(f,y),Fe(b)))};A((()=>ve((()=>({width:o.width,height:o.height})),(({width:e,height:t},{width:i,height:s})=>{if(!e||!t)return;if(!i||!s)return;if(i===e&&s===t)return;const r=o.transform??Oe(),{scale:n}=De(r);if(1===n.sx)return;const a=Qe(r),l=Ve(a,{x:i/2,y:s/2}),c=Ve(r,{x:l.x/i*e,y:l.y/s*t}),d=_e(ze(e/2-c.x,t/2-c.y),r);o.setTransform(d),m()}))),[]),je({onMouseDown:({event:e})=>{n(e)},onDrag:({movement:e,last:s,altKey:r,first:n,xy:a,memo:c,pinching:d,cancel:h})=>{if(d)return void h();const u=n?o.transform??Oe():c.matrix;if(r&&n){const{top:e,left:s}=l.current.getBoundingClientRect(),{rotation:{angle:r}}=De(u);return{startAngle:Math.atan2(a[1]-(e+i/2),a[0]-(s+t/2))-r,matrix:u}}if(void 0!==c?.startAngle){const{top:e,left:s}=l.current.getBoundingClientRect(),{rotation:{angle:r}}=De(u),n=Math.atan2(a[1]-(e+i/2),a[0]-(s+t/2)),d=_e(Ae(n-c.startAngle-r,t/2,i/2),u);return void o.setTransform(d)}const m=gs(_e(ze(...e),u),t,i);return o.setTransform(m),{matrix:u}},onPinch:({first:e,last:t,da:i,origin:s,memo:r})=>{if(t)return;const[n,a]=i;let[c,d]=s;const{top:h,left:u}=l.current.getBoundingClientRect();c-=u,d-=h;const m={x:c+n/2*Math.sin(a*Math.PI/180),y:d-n/2*Math.cos(a*Math.PI/180)},p={x:c-n/2*Math.sin(a*Math.PI/180),y:d+n/2*Math.cos(a*Math.PI/180)};if(e){return{prevP1:m,prevP2:p,prevMatrix:o.transform??Oe()}}const{prevP1:v,prevP2:g,prevMatrix:f}=r,y=He(v,g,m,p),b=_e(y,f);return o.setTransform(b),{prevP1:m,prevP2:p,prevMatrix:b}},onWheel:({last:e,event:s,memo:r})=>{if(e)return;const n=r??o.transform??Oe(),{top:a,left:c}=l.current.getBoundingClientRect(),d=s.clientX-c,h=s.clientY-a;let u=2**function(e){return-e.deltaY*(1===e.deltaMode?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}(s);const m=Math.sqrt(n.a**2+n.b**2);u*m<1&&(u=1/m),u*m>4&&(u=4/m);const p=gs(_e(Fe(u,u,d,h),n),t,i);return o.setTransform(p,!0),p}},{target:l,pinch:{pinchOnWheel:!1,scaleBounds:{min:.5,max:2}},wheel:{eventOptions:{passive:!1},preventDefault:!0}}),A((()=>ve((()=>o.transform),m)),[]);const p=We((({movement:e,first:t,memo:i,target:s})=>{if(t){const{rotation:{angle:e}}=De(o.transform??Oe());return{matrix:o.transform,angle:e}}const{matrix:r,angle:n}=i,a=gs(n?_e(ze(e[0]*+s.dataset.factorX,e[1]*+s.dataset.factorY),r):_e(r,ze(-e[0]*o.width/h,-e[1]*o.height/u)),o.width,o.height);return o.setTransform(a),{matrix:r,angle:n}})),{scale:{sx:v},rotation:{angle:g}}=De(o.transform??Oe());return S(M,{children:[S("div",{className:"x-3deye-player__overlay",children:[P("div",{ref:l,style:{position:"absolute",touchAction:"none",top:0,bottom:0,left:0,right:0},onDoubleClick:s||k,onAuxClick:r}),P(ms,{}),S("div",{className:"x-3deye-player__indicators",children:[e?null:P(ji,{}),P("div",{style:{flex:1}}),P(hs,{}),P(ls,{})]}),o.loading&&P(Gt,{style:{pointerEvents:"none",position:"absolute",top:"calc(50% - 33px)",left:"calc(50% - 33px)"}}),P(ps,{}),a]}),P(M,{children:S("div",{id:d,className:"x-3deye-player__zoom-slider",style:{color:"#fff8",display:1!==v||0!==g?"flex":"none",gap:8},children:[S("div",{ref:c,className:"x-3deye-player__zoom-preview",style:{width:204,height:140},tabIndex:-1,children:[P("div",{className:"zoom-value",children:`${v.toPrecision(3)}x`}),P("div",{className:"x-3deye-player__zoomable",...p(),style:{touchAction:"none"}})]}),P("div",{style:{height:136,paddingBlock:8,paddingLeft:8,marginLeft:-8},children:P(Yt,{orientation:"vertical",value:(v-1)/3*100,onChange:e=>{const t=1+e/100*3,i=o.transform??Oe(),s=o.width/2,r=o.height/2,n=Math.sqrt(i.a**2+i.b**2),a=gs(_e(Fe(t/n,t/n,s,r),i),o.width,o.height);o.setTransform(a)},labelFormat:null})}),S("div",{style:{paddingBottom:20,width:32,marginRight:-8},children:[P(ei,{angle:g,onChange:e=>{const s=o.transform??Oe(),{rotation:{angle:r}}=De(s),n=_e(Ae(e-r,t/2,i/2),s);o.setTransform(n)}}),S(vt,{disabled:!g,title:g?st.t("playerTools.resetRotation"):null,style:{position:"absolute",color:"currentColor",right:4,bottom:2,fontFamily:"Roboto Mono, monospace",letterSpacing:"-0.1em",paddingInline:0,paddingBlock:2,height:"fit-content",fontSize:"0.75rem"},onMouseDown:()=>{const e=o.transform??Oe(),{rotation:{angle:s}}=De(e),r=_e(Ae(-s,t/2,i/2),e),n=gs(r,t,i);o.setTransform(n,!0),o.isRotating=Math.abs(r.e-n.e)<1e-6&&Math.abs(r.f-n.f)<1e-6},children:[(180*g/Math.PI).toFixed(1),"°"]})]})]})})]})}));fs.displayName="PlayerOverlay";var ys=fs;const bs=60,Rs=B((({cameraId:e,disabled:t})=>{const i=z(rt),s=$((()=>({x:0,y:0,update(e,t){this.x=e,this.y=t}})));A((()=>{const t=at((()=>({x:s.x,y:s.y}))).pipe(Ie(((e,t)=>Math.round(100*e.x)===Math.round(t.x)&&Math.round(100*e.y)===Math.round(t.y))),Le(100),be((t=>t.x||t.y?i.api.cameras.MoveCameraContinuousStart({id:e},Math.round(100*t.x),Math.round(100*t.y),0,30):i.api.cameras.MoveCameraContinuousStop({id:e})))).subscribe();return()=>t.unsubscribe()}),[]);const[{x:r,y:n},a]=Je((()=>({x:0,y:0,config:Xe.wobbly}))),o=We((({down:e,movement:[t,i]})=>{if(t*t+i*i>bs*bs){const e=Math.sqrt(t*t+i*i);t=t/e*bs,i=i/e*bs}e?s.update(t/bs,-i/bs):s.update(0,0),a.start({x:e?t:0,y:e?i:0,immediate:e})}),{enabled:!t,pointer:{capture:!1}});return S("div",{style:{display:"grid",placeItems:"center",position:"relative",flex:1},children:[P("div",{style:{gridRow:"1 / 1",gridColumn:"1 / 1",width:120,height:120,borderRadius:"50%",background:"rgba(255, 255, 255, 0.25)"}}),P(Ke.div,{...o(),style:{x:r,y:n,width:50,height:50,background:"rgb(255 255 255 / 0.5)",touchAction:"none",borderRadius:"50%",gridRow:"1 / 1",gridColumn:"1 / 1"}})]})}));Rs.displayName="ContinuousPtzControls";var Cs=Rs;const ws=B((({cameraId:e,disabled:t})=>{const{api:i}=z(rt);return P(vt,{disabled:t,className:"x-3deye-button--icon",style:{width:36,height:36},title:st.t("ptzControl.moveCameraHome"),onPointerDown:()=>i.cameras.GoHomePtzCamera({id:e}).subscribe(),children:P(St,{})})}));ws.displayName="GoHome";var Ts=ws;const ks=Ze().domain([1,100]).range([0,100]),Ps=B((({movementSpeed:e,setMovementSpeed:t,disallowGoHome:i=!1,disabled:s,cameraId:r})=>{const{api:n}=z(rt),a=Math.floor(ks.invert(e));return S("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr) 24px",flex:1},children:[i?P("div",{style:{gridRow:2,gridColumn:2}}):P(vt,{disabled:s,onPointerDown:()=>n.cameras.GoHomePtzCamera({id:r}).subscribe(),className:"x-3deye-button--icon",style:{gridRow:2,gridColumn:2,justifySelf:"center",alignSelf:"center",width:36,height:36},title:st.t("ptzControl.moveCameraHome"),children:P(St,{size:24})}),Array.from(Array(8),((e,t)=>{const i=[0,1,2,7,3,6,5,4][t],o=t<3?0:t<5?1:2,l=t<4?t%3:(t+1)%3,c=i%2?[0,0]:[-1*(l-1),-1*(o-1)],d=`rotate(${45*i-135}deg)`,h=(l-1)*a,u=(o-1)*-a;return P(vt,{disabled:s,onPointerDown:()=>n.cameras.MoveCamera({id:r},h,u,0,0,0).subscribe(),className:"x-3deye-button--icon",style:{transform:`translate(${10*c[0]}px, ${10*c[1]}px)`,justifySelf:"center",alignSelf:"center",width:36,height:36},children:P(Et,{style:{transform:d},size:i%2?24:16})},t)})),S("div",{style:{gridColumn:"4",gridRow:"1 / span 3",position:"relative"},children:[P("div",{style:{position:"absolute",top:0,bottom:0,left:0,aspectRatio:"1/1",display:"flex",flexDirection:"column"},children:P(Yt,{orientation:"vertical",style:{flex:1,marginTop:10,marginBottom:10},disabled:s,value:e,onChange:t,labelFormat:e=>`${e}%`})}),P(Xt,{label:st.t("ptzControl.movementSpeed"),children:P("div",{style:{width:24,height:24,position:"absolute",bottom:-24,left:0},children:P(At,{})})})]})]})}));Ps.displayName="RelativePtzControls";var Ss=Ps;const Ms=B((({cameraId:e,disabled:t})=>{const{api:i,notification:s}=z(rt);return P(vt,{disabled:t,className:"x-3deye-button--icon",style:{width:36,height:36},title:st.t("ptzControl.setHome"),onClick:async()=>{confirm(st.t("ptzControls.confirmSetHomePosition"))&&i.cameras.SetHomePtzCamera({id:e}).subscribe((e=>{e.success?s.success(st.t("ptzControls.cameraPtzHomeSet")):(s.error(st.t("ptzControls.errorWhileUpdatingHomePositionDescription")),console.error(e.error))}))},children:P(kt,{})})}));Ms.displayName="SetHome";var xs=Ms;const Is=Ze().domain([1,100]).range([0,100]),Es=B((({cameraId:e,style:t,disabled:i,initialZoomSpeed:s=50,initialMovementSpeed:r=50,disallowHomePositionUpdate:n=!1,disallowGoHome:a=!1})=>{const{api:o}=z(rt),[l,c]=O(Ls.Relative),[d,h]=O(s),[u,m]=O(r),p=Math.floor(Is.invert(d));return S("div",{style:{display:"flex",flexDirection:"column",...t},children:[S("div",{style:{display:"flex",justifyContent:"space-between"},children:[P(vt,{disabled:i,onPointerDown:()=>o.cameras.MoveCamera({id:e},0,0,-p,0,0).subscribe(),className:"x-3deye-button--icon",style:{gridColumn:"1/1",justifySelf:"start"},children:P(Vt,{size:24})}),P(vt,{disabled:i,onPointerDown:()=>o.cameras.MoveCamera({id:e},0,0,p,0,0).subscribe(),className:"x-3deye-button--icon",style:{gridColumn:"2/3",justifySelf:"end"},children:P(Ft,{size:24})})]}),S("div",{style:{display:"flex",alignItems:"center"},children:[P(Xt,{label:st.t("ptzControl.zoomSpeed"),children:P("div",{children:P(At,{})})}),P(Yt,{style:{flex:1,marginLeft:10,marginRight:10},disabled:i,value:d,onChange:h,labelFormat:e=>`${e}%`}),P(Nt,{})]}),l===Ls.Relative?P(Ss,{cameraId:e,disabled:i,movementSpeed:u,setMovementSpeed:m,disallowGoHome:a}):P(Cs,{cameraId:e,disabled:i}),S("div",{style:{display:"flex",justifyContent:"space-between"},children:[n?P("div",{style:{width:24,height:24}}):P(xs,{cameraId:e,disabled:i}),l===Ls.Continuous&&!a&&P(Ts,{cameraId:e,disabled:i})]}),S(Wt,{value:l,onChange:c,children:[P(qt,{value:Ls.Relative,children:st.t("ptzControl.relative")}),P(qt,{value:Ls.Continuous,children:st.t("ptzControl.continuous")})]})]})}));var Ls;!function(e){e[e.Relative=0]="Relative",e[e.Continuous=1]="Continuous"}(Ls||(Ls={}));const Ns=B((({onRequestClose:e,fullscreenControl:t})=>S(Hi,{children:[P(Si,{}),P(Ai,{}),P(Ii,{}),P(Li,{}),P(Hi.Spacer,{}),P(Di,{}),t,P(Ci,{onClick:e})]})));Ns.displayName="ToolkitPlayerControls";var Ds=Ns;const Os=B((e=>{const t=z(H)??U;return P(rt.Provider,{value:t,children:P(Es,{...e})})}));Os.displayName="PtzControls";var _s=Os;const As=new URLSearchParams(location.search.toLowerCase()),zs=As.has("dash")||As.has("dvr"),Fs=B(x.forwardRef((({id:e,archivesStore:t,startTime:i,endTime:s,clip:r,camera:n,webRtcOptions:a,className:o,controls:l,onDoubleClick:c,onMouseDown:d,onAuxClick:h,hideCameraTitle:u,controllerRef:m,videoRef:p,...v},g)=>{const f=E(null),[y,b]=O(0),R=E(null),C=E(null),[w,T]=O((()=>new WeakRef(n))),k=E(null),[M]=O((()=>new ns({camera:n,startTime:i,endTime:s,clip:r,archivesStore:t,behaviors:{archive:e=>new Ji(e,R.current),DVR:e=>ae.isSupported()?new Yi(e,zs,R.current):new Gi(e,R.current),WebRTC:zs||!1===a?.enabled?null:e=>new ss(e,a)}})));V(m,(()=>M),[]),A((()=>{C.current=new as(R.current,M);const e=ht?at((()=>M.mode),!0).pipe(Ne()).subscribe((([e])=>{"WebRTC"===e&&(k.current={restoreAt:M.seekTime},M.detach(),b((e=>e+1)))})):void 0;return()=>{e?.unsubscribe(),C.current?.dispose(),C.current=null,M.detach()}}),[]);const{muted:x,paused:I}=M;A((()=>{k.current&&(C.current.dispose(),k.current.restoreAt&&M.setStartTime(k.current.restoreAt),C.current=new as(R.current,M),k.current=null)}),[y]),A((()=>{const e=new ye((e=>{for(const t of e){const e=t.contentRect.width,i=t.contentRect.height;pe((()=>{M.width=e,M.height=i}))}}));return e.observe(f.current),()=>{e.disconnect()}}),[]),A((()=>{if(w.deref()!==n)return M.setCameraAndStartTime(n,i||null),M.resetTransform(),void T(new WeakRef(n));M.setStartTime(i||null)}),[n,+(i||0)]);const N=L((e=>{e.currentTarget===e.target&&0===e.button&&d&&d(e)}),[d]);return S("div",{ref:ne(f,g),id:e||`player-${M.id}`,className:W(o,"x-3deye-player",{"x-3deye-player--paused":I}),...v,children:[P("div",{className:"x-3deye-player__zoomable-wrapper",children:P("div",{className:"x-3deye-player__zoomable",style:{transformOrigin:"0 0",transform:M.transform?$e(M.transform):void 0},children:P("video",{autoPlay:!0,crossOrigin:"anonymous",playsInline:!0,ref:ne(R,p),muted:x,style:(e=>{if("archive"!==M.mode||!ht||"fill"!==e.objectFit)return e;let t=1,i=1;const{width:s,height:r}=M,n=M.camera.raw.width||R.current?.videoWidth,a=M.camera.raw.height||R.current?.videoHeight;if(!(n&&a&&s&&r))return e;const o=n/a;s/r>o?(t=s/(r*o),i=1):(t=1,i=r/(s/o));const{objectFit:l,...c}=e;return{...c,objectFit:"contain",scale:`${t} ${i}`}})({objectFit:M.videoResizeMode})},y)})}),P(ki.Provider,{value:M,children:P(ys,{onDoubleClick:c,onAuxClick:h,onMouseDown:N,width:M.width,height:M.height,hideCameraTitle:u,children:l})})]})})));Fs.displayName="Player";const Qs=B(x.forwardRef(((e,t)=>{const i=z(H)??U,{ref:s,toggle:r,active:n,enabled:a}=ti(),{cameraId:o,startTime:l,onDoubleClick:c,onMouseDown:d,onRequestClose:h,playerRef:u,controls:m=P(Ds,{fullscreenControl:a?P(Ti,{active:n,toggle:r}):void 0,onRequestClose:h}),...p}=e;if(!i.cameras.loaded)return P("div",{ref:t,...p});const v=o?i.cameras.camerasById.get(o):null;if(!v)return console.warn("can't render player for unknown camera"),P("div",{ref:t,...p});const g={hideCameraTitle:!0,camera:v,controls:m,onDoubleClick:c,onMouseDown:d,startTime:l,controllerRef:u,...p},f=ne(t,ht?void 0:s),y=ht?s:void 0;return P(rt.Provider,{value:i,children:P(Fs,{ref:f,videoRef:y,archivesStore:i.archives,webRtcOptions:{enabled:!0},...g})})})));Qs.displayName="CameraPlayer";var Vs=Qs;function Hs(){const[e,t]=O(null);return{playerRef:L((e=>{t(e??null)}),[]),player:e}}const Us=e=>e.stopPropagation(),Bs=B((e=>{const t=E(null),i=$((()=>({current:null}))),s=$((()=>({dragging:!1}))),r=E(new T),n=L((e=>{e.persist(),e.stopPropagation(),r.current.next(e)}),[]),o=me((()=>{i.current=null,e.onRequestCancel()})),l=me((()=>{i.current=null,e.onClose()}));return A((()=>{const n=r.current.pipe(Me((r=>{const n=r.clientX,o=r.clientY;s.dragging=!0;const{top:l,left:c}=t.current.getBoundingClientRect();return a(document,"mousemove").pipe(Se((t=>{const i=n-c,s=o-l,r=t.clientX-n,a=t.clientY-o,d=(a>=0?s:s+a)/e.height,h=(r>=0?i:i+r)/e.width,u=d+Math.abs(a)/e.height,m=h+Math.abs(r)/e.width;return{top:ut(d,0,1),left:ut(h,0,1),bottom:ut(u,0,1),right:ut(m,0,1)}})),ke(a(document,"mouseup").pipe(Re((()=>{if(s.dragging=!1,!i.current)return;const t=(i.current.bottom-i.current.top)*(i.current.right-i.current.left);e.width*e.height*t<100?i.current=null:e.onSelect({Top:i.current.top,Left:i.current.left,Bottom:i.current.bottom,Right:i.current.right})})))))}))).subscribe((e=>{e&&(i.current=e)}));return()=>n.unsubscribe()}),[e.width,e.height]),A((()=>{if(i.current)return;const e=e=>{const t=e.target;/^(input|select|textarea)$/i.test(t.tagName)||"Escape"===e.code&&l()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}}),[null===i.current]),P("div",{ref:t,onMouseDown:n,style:{position:"absolute",top:0,left:0,width:e.width,height:e.height,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column"},children:i.current?P("div",{className:"box-selector",style:{position:"absolute",top:100*i.current.top+"%",left:100*i.current.left+"%",bottom:100*(1-i.current.bottom)+"%",right:100*(1-i.current.right)+"%"},children:s.dragging?null:P(vt,{className:"box-selector-close",onMouseDown:Us,onClick:l,style:{position:"absolute",top:-10,right:-10,padding:2,width:20,height:20,borderRadius:10},children:P(Rt,{size:16})})}):S("div",{className:"box-selector-select",children:[P("div",{children:st.t("selectArea")}),P("div",{className:"box-selector-preview",children:P("div",{className:"box-selector",children:P(wt,{size:16})})}),P(vt,{className:"box-selector-cancel",onClick:o,children:st.t("button.cancel")})]})})})),$s=B((({onSelect:e,onRequestCancel:t,onClose:i})=>{const s=z(ki);return P(Bs,{width:s.width,height:s.height,onSelect:e,onRequestCancel:t,onClose:i})}));$s.displayName="BoxSelector";var Ws=$s;(e=>{if(e&&Object.assign(it,e),st.isInitialized){if(it.resources)for(const e of Object.keys(it.resources))st.addResourceBundle(e,"translation",it.resources[e].translation,!0);else console.warn("i18n is already initialized");return t(st.t)}i(st.init(it))})({resources:{en:{translation:tt}}});export{Ws as BoxSelector,ot as Camera,Vs as CameraPlayer,Ci as CloseControl,si as Control,Hi as Controls,Ds as DefaultControls,Ti as FullscreenControl,Si as PlayPauseControl,Ii as PlaybackRateControl,Fs as Player,ki as PlayerContext,_s as PtzControls,Li as ResizeModeControl,Di as SnapshotControl,Ai as VolumeControl,Vs as default,ti as useFullscreen,Hs as usePlayerRef};
|
|
1
|
+
import e from"i18next";import{of as t,from as i,Observable as s,EMPTY as r,timer as n,fromEvent as a,Subscription as o,fromEventPattern as l,switchMap as c,filter as d,timeout as h,take as u,TimeoutError as m,throwError as p,mergeMap as v,debounceTime as g,merge as f,map as y,pairwise as b,interval as R,concatMap as C,delay as w,Subject as T,noop as k}from"rxjs";import{jsx as P,jsxs as S,Fragment as M}from"react/jsx-runtime";import x,{forwardRef as I,useRef as E,useCallback as L,cloneElement as N,createContext as D,useState as O,Children as _,useEffect as A,useContext as z,useLayoutEffect as F,useMemo as Q,useImperativeHandle as V}from"react";import{AppContext as H,app as U}from"@3deye-toolkit/core";import{observer as B,useLocalObservable as $}from"mobx-react-lite";import W from"clsx";import j from"react-ink";import{useFloating as q,offset as Z,flip as Y,shift as G,arrow as J,autoUpdate as X,useInteractions as K,useRole as ee,useDismiss as te,FloatingPortal as ie,FloatingFocusManager as se,useHover as re}from"@floating-ui/react";import ne from"@seznam/compose-react-refs";import ae,{ErrorDetails as oe,ErrorTypes as le}from"hls.js";import{computed as ce,observe as de,makeObservable as he,observable as ue,action as me,runInAction as pe,reaction as ve,when as ge,makeAutoObservable as fe}from"mobx";import ye from"resize-observer-polyfill";import{switchMap as be,tap as Re,debounceTime as Ce,filter as we,startWith as Te,takeUntil as ke,take as Pe,map as Se,mergeMap as Me,mapTo as xe,distinctUntilChanged as Ie,audit as Ee,auditTime as Le,pairwise as Ne}from"rxjs/operators";import{decomposeTSR as De,identity as Oe,compose as _e,rotate as Ae,translate as ze,scale as Fe,inverse as Qe,applyToPoint as Ve,fromTwoMovingPoints as He,fromObject as Ue,applyToPoints as Be,toCSS as $e}from"transformation-matrix";import{useDrag as We,useGesture as je}from"@use-gesture/react";import{scaleLinear as qe,scaleLog as Ze}from"d3-scale";import Ye from"reconnecting-websocket";import{Controller as Ge,useSpring as Je,config as Xe,animated as Ke}from"@react-spring/web";import{retryBackoff as et}from"backoff-rxjs";var tt={playerTools:{fullScreen:"toggle full screen",resetRotation:"reset rotation",closePlayer:"close player",play:"play",pause:"pause",playbackRate:"set playback rate",snapshot:"capture video frame",volume:"volume",live:"live",goLive:"go live"},selectArea:"select area",button:{cancel:"Cancel"},videoResizeMode:{fit:"keep video's aspect ratio",stretch:"stretch video"},player:{playbackTimeoutError:"Error occured. No playback in the last {{count}} seconds",cameraIsOffline:"Camera is offline",cameraIsDisabled:"Camera is disabled",noPlayableStream:"No playable stream available",noVideoTrack:"No video track",genericError:"An error occured. Please try again later"},ptzControl:{zoomSpeed:"zoom speed",relative:"Relative",continuous:"Continuous",moveCameraHome:"move camera to home position",movementSpeed:"movement speed",setHome:"set as home"},ptzControls:{confirmSetHomePosition:"Are you sure you want to set the camera's home position to the current position?",cameraPtzHomeSet:"New home position is set",errorWhileUpdatingHomePositionDescription:"Sorry, camera PTZ failed to respond to the request.\nPlease make sure your have Internet connection and refresh your browser"}};const it={detection:{order:["querystring","htmlTag","navigator"],lookupQuerystring:"lang"},fallbackLng:"en",load:"all",interpolation:{escapeValue:!1}},st=e.createInstance(),rt=x.createContext(null);class nt extends Error{name;message;cause;constructor(e,t,i){super(t),this.name=e,this.message=t,this.cause=i}}function at(e,t=!1){const i=ce(e);return new s((e=>{const s=de(i,(({newValue:t})=>e.next(t)),t);return()=>s()}))}class ot{id;name;imageUrl;streamUrl;dashStreamUrl;address;archiveDuration;dvrWindowLength;stateUpdatedAt;raw;enabled;isMicEnabled;state;pin;webRtcUrl;isPtz;permissions;get isOnline(){return this.enabled&&"Started"===this.state}get supportsWebRTC(){return!!this.webRtcUrl}constructor(e){he(this,{name:ue,streamUrl:ue,dashStreamUrl:ue,enabled:ue,isMicEnabled:ue,state:ue,pin:ue,webRtcUrl:ue,permissions:ue,isOnline:ce,update:me}),this.update(e)}update=e=>{this.raw=e,this.id=e.id,this.name=e.name,this.isPtz=e.isPTZ,this.isMicEnabled=e.isMicEnabled,this.imageUrl=e.imageUrl,this.address=e.cameraAddress?JSON.parse(e.cameraAddress):null,this.streamUrl=e.streamUrl,this.dashStreamUrl=e.dashStreamUrl,this.enabled=e.enabled,this.state=this.raw.cameraState,this.dvrWindowLength=e.dvrWindowLength?1e3*e.dvrWindowLength:e.dvrWindowLength,this.archiveDuration=e.archiveDuration,this.pin=e.pin,this.webRtcUrl=e.webRtcUrl,this.permissions=e.permissions||0,this.stateUpdatedAt=new Date(e.cameraStateChangedTime)};can=e=>!!(this.permissions&e)}var lt;!function(e){e[e.View=1]="View",e[e.SaveClip=2]="SaveClip",e[e.Share=4]="Share",e[e.Ptz=8]="Ptz",e[e.EditSettings=16]="EditSettings",e[e.Timelapse=32]="Timelapse",e[e.Delete=64]="Delete"}(lt||(lt={}));class ct{cameraId;streamUrl;dashStreamUrl;startTime;endTime;length;isLive=!0;isDvr=!0;hasDvr=!0;rtmpStreamUrl;managed=!1;constructor(e){he(this,{startTime:ue,endTime:ue,setBounds:me}),this.streamUrl=e.streamUrl,this.dashStreamUrl=e.dashStreamUrl,this.startTime=e.startTime,this.endTime=e.endTime,this.length=e.length,this.cameraId=e.cameraId}setBounds=e=>{[this.startTime,this.endTime]=e}}const dt=!!navigator.platform&&/iPad|iPhone|iPod/.test(navigator.platform),ht=!!navigator.userAgent.match(/Version\/[\d.]+.*Safari/),ut=(e,t,i)=>Math.min(Math.max(e,t),i),mt=()=>{},pt=({forwardedRef:e,children:t,className:i,fullWidth:s,variant:r,type:n,title:a,placement:o,...l})=>{const c=W(i,"x-3deye-button",{"x-3deye-button--fullwidth":s},r?`x-3deye-button--${r}`:void 0),d=S("button",{ref:e,className:c,type:n||"button",...l,children:[t,l.disabled?null:P(j,{})]});return void 0===a?d:P(Xt,{label:a,placement:o,disabled:!a,children:d})};var vt=I(((e,t)=>P(pt,{forwardedRef:t,...e})));function gt(e){return I(((t,i)=>{const{size:s=24,color:r="currentColor",className:n,...a}=t,o=e.viewBox||"0 0 24 24",l=e.svg;return P("svg",{ref:i,preserveAspectRatio:"xMinYMin",className:W("icon",n),width:s,fill:r,viewBox:o,...a,children:l})}))}const ft=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M19 12h-2v3h-3v2h5v-5zM7 9h3V7H5v5h2V9zm14-6H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z"})]})});ft.displayName="AspectRatioIcon";var yt=ft;const bt=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});bt.displayName="CloseIcon";var Rt=bt;const Ct=gt({viewBox:"0 0 24 24",svg:P("path",{d:"M7,2l12,11.2l-5.8,0.5l3.3,7.3l-2.2,1l-3.2-7.4L7,18.5V2"})});Ct.displayName="CursorIcon";var wt=Ct;const Tt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M20 15.256v1.828A9 2 0 0 1 21 18a9 2 0 0 1-9 2 9 2 0 0 1-9-2 9 2 0 0 1 1-.914v-1.824A11 4 0 0 0 1 18a11 4 0 0 0 11 4 11 4 0 0 0 11-4 11 4 0 0 0-3-2.744z"}),P("path",{d:"M12 3 1 11.4l1.21 1.59L4 11.62V19h2v-8.9l6-4.58 6 4.58V19h2v-7.38l1.79 1.36L23 11.4 12 3z"}),P("path",{d:"m16 14-4 4-4-4 1.41-1.41L11 14.17v-4.15l2-.02v4.17l1.59-1.59z"})]})});Tt.displayName="HomeSaveIcon";var kt=Tt;const Pt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M12 3L1 11.4l1.21 1.59L4 11.62V21h16v-9.38l1.79 1.36L23 11.4zm6 16H6v-8.9l6-4.58 6 4.58z"})]})});Pt.displayName="HomeIcon";var St=Pt;const Mt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M6 19h4V5H6v14zm8-14v14h4V5h-4z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});Mt.displayName="PauseIcon";var xt=Mt;const It=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M8 5v14l11-7z"}),P("path",{d:"M0 0h24v24H0z",fill:"none"})]})});It.displayName="PlayIcon";var Et=It;const Lt=gt({viewBox:"0 0 100 100",svg:P(M,{children:P("path",{d:"M87.783 47.898c-1.132-2.958-8.699-12.701-10.266-13.223-1.565-.521-4.872-.348-4.872-.348-1.479-16.616-5.132-18.442-7.654-20.269-2.523-1.826-2.263 5.395-2.263 5.395-.87-3.045-5.307-8.004-8.352-7.221-3.045.783-1.391 10.788-.956 13.57.437 2.785 4.35 6.785 5.827 8.96 1.479 2.174.697 4.088.697 4.088-1.218 1.741-1.044 6.119-1.044 6.119-3.043-.494-6.001 3.016-6.001 3.016-6.874-2.956-10.808-3.016-10.808-3.016-20.86.208-23.515 20.064-23.822 26.65-.745-.324-1.78-.315-3.116.737-3.071 2.419-.88 5.383-.88 5.383-.865-.238-1.722-4.225-1.722-4.225-1.963 4.198 1.606 7.065 1.606 7.065-1.33.285-3.53-1.206-3.53-1.206.208.281 1.585 2.426 4.26 5.227 3.376 3.532 8.355 2.771 10.81 2.676.088.018.163.01.233-.01l.071-.002.012-.03c.386-.172.692-.719 2.295-.182l2.06 1.296s18.203.169 21.053 0c1.546-.092-1.566-4.523-1.566-4.523 5.654-.349 8.699-2.437 8.699-2.437l8.735 7.129h9.164c1.801 0 .697-1.93.697-1.93l-8.593-7.809.956-1.652c3.306-.696 5.655-3.915 6.001-4.523.35-.609.089-5.132.089-5.132s.349.435 1.826-1.393c1.48-1.827-.173-4.697-.607-5.307-.434-.607-1.305-4.438-1.305-4.438s5.827-.348 7.22-1.044c1.389-.693 6.176-4.434 5.046-7.391z"})})});Lt.displayName="RabbitIcon";var Nt=Lt;const Dt=gt({viewBox:"0 0 24 24",svg:S("g",{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M12.01 5.5L10 8h4l-1.99-2.5zM18 10v4l2.5-1.99L18 10zM6 10l-2.5 2.01L6 14v-4zm8 6h-4l2.01 2.5L14 16zm7-13H3c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16.01H3V4.99h18v14.02z"})]})});Dt.displayName="SettingsOverscanIcon";var Ot=Dt;const _t=gt({viewBox:"0 0 79.375 79.375",svg:P(M,{children:P("path",{d:"M138.93 101.512c-16.578.124-32.548 6.13-47.309 17.925-7.317 5.847-15.399 14.393-17.77 18.788-1.58 2.931-3.668 7.757-6.367 14.712-7.457 19.225-11.997 29.033-16.8 36.297-1.638 2.476-1.781 2.231 1.748 2.99.613.133 1.285.26 1.984.383-1.634 3.885-5.948 9.571-11.436 13.088-1.138.73-4.443 2.638-7.345 4.242-5.362 2.964-7.66 4.377-9.285 5.713-1.765 1.45-4.48 4.224-4.786 4.891-.23.503-.304 1.445-.29 3.686.015 2.55.098 3.286.546 4.824 1.28 4.391 3.49 7.175 6.205 7.824 1.303.311 1.77.296 3.342-.107 3.624-.931 6.702-3.5 16.992-14.186 8.097-8.408 10.799-10.842 14.067-12.672.031-.017.064-.03.095-.047 1.093.759 2.373 1.422 3.221 1.602 2.71.574 28.721 2.944 47.403 4.318 8.207.604 16.372 1.208 18.142 1.342 1.77.134 10.736.21 19.924.17 13.044-.058 18.042.009 20.807-1.867-4.243 6.551-9.009 15.985-6.569 22.843 1.043 2.745 3.456 5.444 5.754 6.438 3.466 1.5 7.874-1.423 12.715-8.428 2.22-3.213 4.69-7.493 8.592-14.894 2.167-4.11 3.373-6.495 4.076-8.534l1.717-.51c.66 0 3.167-.885 5.047-1.782 4.06-1.939 9.627-5.707 15.574-10.543 2.402-1.954 7.135-5.996 9.199-7.846 18.116 13.509 29.936 25.039 32.766 32.033.311.77.629 1.4.705 1.4.433 0 4.516-4.066 6.2-6.175 4.187-5.243 6.403-10.354 6.403-14.76-1.252-15.979-37.802-28.468-28.124-33.08 3.282-1.563.627-3.716 11.572-3.293 7.862-.501 11.288-1.289 14.761-3.395 3.58-2.17 5.372-4.62 6.983-9.545 1.017-3.19.806-4.87.326-9.017 1.96-1.74 2.14-7.427-.22-9.6-1.625-1.913-4.807-3.627-8.503-4.576-8.376-2.15-24.507-1.09-32.883 2.162-1.493.58-2.487 1.192-4.244 2.615-2.451 1.986-5.58 4.847-8.601 7.868-1.114 1.113-1.585 1.613-2.075 2.52l-1.562-1.31c-.293-.296-1.923-1.951-3.621-3.677-16.038-16.305-32.66-28.14-48.71-34.682-10.253-4.18-20.42-6.223-30.366-6.148zm127.783 39.14c1.656-.08 3.338 1.31 3.51 3.819.104 1.518-.393 2.89-1.362 3.76-.361.324-.977.524-1.797.585-1.044.078-1.36-.003-1.95-.494-1.605-1.334-2.077-3.308-1.272-5.324.617-1.547 1.738-2.29 2.87-2.346z",transform:"scale(.26458)"})})});_t.displayName="TurtleIcon";var At=_t;const zt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"}),P("path",{fill:"none",d:"M0 0h24v24H0V0z"}),P("path",{d:"M12 10h-2v2H9v-2H7V9h2V7h1v2h2v1z"})]})});zt.displayName="ZoomInIcon";var Ft=zt;const Qt=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{d:"M0 0h24v24H0z",fill:"none"}),P("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14zM7 9h5v1H7z"})]})});Qt.displayName="ZoomOutIcon";var Vt=Qt;const Ht=({opened:e,onOpenChange:t,children:i,target:s,placement:r,className:n,style:a,autoDismiss:o=!0,initialFocus:l,withArrow:c=!1})=>{const d=E(null),{x:h,y:u,refs:m,strategy:p,context:v,middlewareData:g,placement:f,update:y}=q({open:e,onOpenChange:t,middleware:[Z(5),Y(),G(),J({element:d})],placement:r,whileElementsMounted:(e,t,i)=>X(e,t,(()=>{0!==v.elements.domReference?.getBoundingClientRect().width?i():v.onOpenChange(!1)}),{animationFrame:!0})}),{getReferenceProps:b,getFloatingProps:R}=K([ee(v),te(v,{ancestorScroll:!0,enabled:o})]),C=L((e=>{d.current=e,y()}),[y]),w={top:"bottom",right:"left",bottom:"top",left:"right"}[f?.split("-")[0]??"top"]||"top",T=S("div",{...R({className:W("x-3deye-popover-container",n),ref:m.setFloating,style:{...a,position:p,top:u??0,left:h??0}}),children:[c&&P(Jt,{ref:C,width:24,height:8,placement:w,style:{position:"absolute",left:g.arrow?.x,top:g.arrow?.y,[w]:-7}}),i]});return S(M,{children:[N(s,b({ref:m.setReference,...s.props})),S(ie,{id:"x-3deye-floating-ui-root",children:[o&&e&&P(se,{context:v,modal:!1,order:["reference","content"],returnFocus:!1,initialFocus:l,children:T}),!o&&e&&T]})]})},Ut=(e,t,i,s)=>ut(Math.floor((e-t)/i*s),0,s-1),Bt=D({value:null,onPointerDown:mt,setCurrentValue:mt,state:{currentIdx:0,currentValue:null,options:[]}});class $t{currentIdx=0;options=[];get currentValue(){return this.options[this.currentIdx]}constructor(e=0){this.currentIdx=e,he(this,{currentIdx:ue,options:ue.ref,currentValue:ce,setCurrentIdx:me,setOptions:me})}setCurrentIdx=e=>{this.currentIdx=e};setOptions=e=>{this.options=e}}var Wt=B(x.forwardRef((({value:e,onChange:t,children:i,style:s},r)=>{const[n,a]=O(!1),o=E(null),l=_.map(i,(e=>e?.props.value))||[],c=$((()=>new $t(l.indexOf(e))));c.setOptions(l);const d=_.count(i);A((()=>{c.setCurrentIdx(l.indexOf(e))}),[e]),A((()=>{if(!n)return;const e=o.current?.getBoundingClientRect();if(!e)return;const i=({clientX:t})=>{c.setCurrentIdx(Ut(t,e.left,e.width,d))},s=()=>{a(!1),t(l[c.currentIdx])};return document.addEventListener("pointermove",i),document.addEventListener("pointerup",s),()=>{document.removeEventListener("pointermove",i),document.removeEventListener("pointerup",s)}}),[n,d]);return P(Bt.Provider,{value:{value:e,state:c,onPointerDown:e=>{const t=o.current;if(!t)return;const{left:i,width:s}=t.getBoundingClientRect(),r=Ut(e.clientX,i,s,d);r!==c.currentIdx&&c.setCurrentIdx(r),a(!0)},setCurrentValue:e=>{c.setCurrentIdx(l.indexOf(e))}},children:P("div",{className:"segmented-control-wrapper",style:s,ref:r,children:S("div",{role:"radiogroup",ref:o,className:"segmented-control",style:{"--indicator-offset":100*c.currentIdx+"%"},children:[P("div",{"aria-hidden":!0,className:W("segmented-control-indicator",{active:n}),style:{width:100/l.length+"%"},children:P("div",{className:"segmented-control-indicator-inner"})}),i]})})})})));const jt=B(I((({value:e,children:t},i)=>{const s=z(Bt);return P("button",{ref:i,role:"radio","aria-checked":s.state.currentValue===e,tabIndex:0,className:W("segmented-control-button",{current:s.state.currentValue===e}),onPointerDown:s.onPointerDown,onClick:()=>s.setCurrentValue(e),children:t})})));jt.displayName="SegmentedControlOption";var qt=jt;const Zt=e=>Math.round(e),Yt=I((({value:e,onChange:t,onChangeComplete:i,orientation:s="horizontal",disabled:r=!1,labelFormat:n=e=>`${e}`,style:a},o)=>{const l=E(null),c=E(null),[d,h]=O(!1),[u,m]=O(e);A((()=>{if(!d)return;const e=l.current;if(!e)return;let r=0,n=0;const a=e.getBoundingClientRect();if(!a||!a.width||!a.height)return void h(!1);const o=({clientX:e,clientY:i})=>{if(!c.current)return;let o=0;"horizontal"===s?(r=ut(e-a.x,0,a.width),o=r/a.width*100,c.current.style.transform=`translateX(${r}px)`):(n=a.height-ut(i-a.y,0,a.height),o=n/a.height*100,c.current.style.transform=`translateY(${-n}px)`),m(o),t?.(Zt(o))},u=({clientX:e,clientY:r})=>{if(h(!1),!c.current)return;const n="horizontal"===s?ut(e-a.x,0,a.width)/a.width*100:100*(1-ut(r-a.y,0,a.height)/a.height);c.current.style.transform="",m(n),t?.(Zt(n)),i?.(Zt(n))},p=()=>{if(h(!1),!c.current)return;const e="horizontal"===s?r/a.width*100:n/a.height*100;c.current.style.transform="",t?.(Zt(e)),i?.(Zt(e))};return document.addEventListener("pointercancel",p),document.addEventListener("pointermove",o),document.addEventListener("pointerup",u),()=>{document.removeEventListener("pointercancel",p),document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",u)}}),[d,s,t,i]);const p=L((e=>{if(!l.current||r)return;const{clientX:i,clientY:n}=e;e.preventDefault(),h(!0);const a=l.current.getBoundingClientRect();if(!a)return;if(!c.current)return;let o=0;if("horizontal"===s){const e=ut(i-a.x,0,a.width);o=e/a.width*100,c.current.style.transform=`translateX(${e}px)`}else{const e=a.height-ut(n-a.y,0,a.height);o=e/a.height*100,c.current.style.transform=`translateY(${-e}px)`}m(o),t?.(Zt(o))}),[r]),v=L((s=>{if(r)return;let n=null;"ArrowLeft"===s.code?n=Math.max(e-1,0):"ArrowRight"===s.code?n=Math.min(e+1,100):"ArrowDown"===s.code?n=Math.max(e-1,0):"ArrowUp"===s.code&&(n=Math.min(e+1,100)),null!==n&&(s.stopPropagation(),s.preventDefault(),t?.(n),i?.(n))}),[e,t,i,r]);return S("div",{ref:ne(o,l),tabIndex:0,onKeyDown:v,className:W("x-3deye-slider",s,{disabled:r}),onPointerDown:p,style:a,children:[P("div",{className:"x-3deye-slider__track",children:P("div",{className:"x-3deye-slider__bar",style:{width:"horizontal"===s?`${d?u:e}%`:void 0,height:"vertical"===s?`${d?u:e}%`:void 0}})}),P("div",{ref:c,className:W("x-3deye-slider__thumb",{active:d}),style:{touchAction:"none",userSelect:"none",position:"absolute",left:"horizontal"===s?d?0:`${e}%`:"auto",bottom:"vertical"===s?d?0:`${e}%`:"auto"},children:null!==n&&P("div",{className:"x-3deye-slider__label "+(d?"open":""),children:n(d?Zt(u):e)})})]})}));function Gt(e){return P("svg",{focusable:"false",role:"graphics-symbol",viewBox:"0 0 66 66",className:"spinner",...e,children:P("circle",{fill:"none",strokeWidth:3,cx:33,cy:33,r:30,stroke:"white"})})}Yt.displayName="Slider";const Jt=x.forwardRef((function({width:e,height:t,placement:i="top",style:s},r){const n=[0,"top"===i?t:0],a=[e,n[1]],o=[e/2,t-n[1]],l=[e/4,t*("top"===i?3:1)/4],c=[.325*e,t-n[1]],d=[e-c[0],c[1]],h=[e-l[0],l[1]],u=e=>e.join(","),m=`M ${u(n)} C ${u(l)} ${u(c)} ${u(o)} ${u(d)} ${u(h)} ${u(a)}`;return S("svg",{ref:r,role:"graphics-symbol",className:"tip",style:s,width:e,height:t,fill:"var(--tip-background, #fff)",children:[P("path",{className:"tip-body",d:`${m} Z`}),P("path",{className:"tip-border",d:m,stroke:"var(--tip-border, transparent)",strokeWidth:1})]})}));var Xt=({children:e,label:t,placement:i="bottom",disabled:s})=>{const[r,n]=O(!1),{x:a,y:o,refs:l,strategy:c,context:d}=q({placement:i,open:r,onOpenChange:n,middleware:[Z(5),Y(),G({padding:8})],whileElementsMounted:(e,t,i)=>X(e,t,i,{animationFrame:!0})}),{getReferenceProps:h,getFloatingProps:u}=K([re(d,{enabled:!s}),ee(d,{role:"tooltip"}),te(d,{referencePress:!0})]);return S(M,{children:[N(e,h({ref:ne(l.setReference,e.ref),...e.props})),P(ie,{id:"x-3deye-floating-ui-root",children:r&&P("div",{...u({ref:l.setFloating,className:"x-3deye-tooltip",style:{position:c,top:o??0,left:a??0}}),children:t})})]})};const Kt=120;function ei({angle:e,onChange:t}){const i=E(e);i.current=e;const s=Array.from({length:40}).map(((t,i)=>{const s=Math.PI/20;let r=Math.max(0,s*i+e+2*Math.PI);for(;r>2*Math.PI;)r-=2*Math.PI;return[i,Math.sin(r)/2,r>=0&&r<=Math.PI/2?(Math.PI/2-r)/Math.PI*2:r>=1.5*Math.PI&&r<=2*Math.PI?(r-1.5*Math.PI)/Math.PI*2:0,!!(0===i||e>=0&&s*i>=2*Math.PI-e||e<0&&s*i<-e)]})).filter((e=>e[2])),r=We((({first:e,movement:[s,r],memo:n})=>{if(e)return{a:i.current};const{a:a}=n;return t(a+r/Kt*2),{a:a}}));return P("div",{style:{touchAction:"none",position:"relative",height:Kt},...r(),children:s.map((([e,t,i,s],r)=>{const n=e%5==0;return P("div",{style:{position:"absolute",width:0===e?30:n?24:20,height:2,background:s?"orange":"currentColor",opacity:i,translate:`${0===e?-5:n?-2:0}px ${60+t*Kt}px`}},r)}))})}function ti(){const[e,t]=O(void 0),[i,s]=O(!1),r=dt&&e instanceof HTMLVideoElement?"webkitEnterFullscreen"in e:document.fullscreenEnabled||Boolean(document.webkitFullscreenEnabled);const n=L((e=>{t(e||void 0)}),[]);A((()=>{const t=()=>{s(document.fullscreenElement===(e||document.documentElement))};return document.addEventListener("fullscreenchange",t),document.addEventListener("webkitfullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t),document.removeEventListener("webkitfullscreenchange",t)}}),[e]);return{ref:n,toggle:L((()=>{r&&(document.fullscreenElement!==(e||document.documentElement)?(e||document.documentElement).requestFullscreen():document.exitFullscreen())}),[e,i]),enabled:r,active:i}}const ii=x.forwardRef((({children:e,className:t,...i},s)=>P(vt,{ref:s,className:t=t?`x-3deye-player__control ${t}`:"x-3deye-player__control",...i,children:e})));ii.displayName="Control";var si=ii;const ri=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M 10 3.5 C 9.75 3.5 9.508724 3.5503906 9.2753906 3.6503906 C 9.0420573 3.7503906 8.8424479 3.8908854 8.6757812 4.0742188 L 7.3496094 5.5 L 4.3007812 5.5 C 3.8007813 5.5 3.3753906 5.6753906 3.0253906 6.0253906 C 2.6753906 6.3753906 2.5 6.8007812 2.5 7.3007812 L 2.5 18.699219 C 2.5 19.199219 2.6753906 19.624609 3.0253906 19.974609 C 3.3753906 20.324609 3.8007813 20.5 4.3007812 20.5 L 19.699219 20.5 C 20.199219 20.5 20.624609 20.324609 20.974609 19.974609 C 21.324609 19.624609 21.5 19.199219 21.5 18.699219 L 21.5 7.3007812 C 21.5 6.8007813 21.324609 6.3753906 20.974609 6.0253906 C 20.624609 5.6753906 20.199219 5.5 19.699219 5.5 L 16.650391 5.5 L 15.324219 4.0742188 C 15.157552 3.8908854 14.957943 3.7503906 14.724609 3.6503906 C 14.491276 3.5503906 14.25 3.5 14 3.5 L 10 3.5 z M 4.3007812 7 L 19.699219 7 C 19.782552 7 19.853443 7.029224 19.912109 7.0878906 C 19.970109 7.1458906 20 7.2174479 20 7.3007812 L 20 18.699219 C 20 18.782552 19.970109 18.853443 19.912109 18.912109 C 19.853443 18.970109 19.782552 19 19.699219 19 L 4.3007812 19 C 4.2174479 19 4.1458906 18.970109 4.0878906 18.912109 C 4.029224 18.853443 4 18.782552 4 18.699219 L 4 7.3007812 C 4 7.2174479 4.029224 7.1458906 4.0878906 7.0878906 C 4.1458906 7.029224 4.2174479 7 4.3007812 7 z M 12 8.875 C 10.85 8.875 9.8742188 9.2742187 9.0742188 10.074219 C 8.2742188 10.874219 7.875 11.85 7.875 13 C 7.875 14.15 8.2742187 15.125781 9.0742188 15.925781 C 9.8742188 16.725781 10.85 17.125 12 17.125 C 13.15 17.125 14.125781 16.725781 14.925781 15.925781 C 15.725781 15.125781 16.125 14.15 16.125 13 C 16.125 11.85 15.725781 10.874219 14.925781 10.074219 C 14.125781 9.2742188 13.15 8.875 12 8.875 z M 12 10.386719 A 2.6057522 2.6057522 0 0 1 14.605469 12.992188 A 2.6057522 2.6057522 0 0 1 12 15.599609 A 2.6057522 2.6057522 0 0 1 9.3945312 12.992188 A 2.6057522 2.6057522 0 0 1 12 10.386719 z "})]})});ri.displayName="CameraIcon";var ni=ri;const ai=gt({viewBox:"0 0 24 24",svg:P(M,{children:P("path",{d:"M12 13.05 6.925 18.125Q6.725 18.325 6.413 18.337Q6.1 18.35 5.875 18.125Q5.65 17.9 5.65 17.6Q5.65 17.3 5.875 17.075L10.95 12L5.875 6.925Q5.675 6.725 5.663 6.412Q5.65 6.1 5.875 5.875Q6.1 5.65 6.4 5.65Q6.7 5.65 6.925 5.875L12 10.95L17.075 5.875Q17.275 5.675 17.588 5.662Q17.9 5.65 18.125 5.875Q18.35 6.1 18.35 6.4Q18.35 6.7 18.125 6.925L13.05 12L18.125 17.075Q18.325 17.275 18.337 17.587Q18.35 17.9 18.125 18.125Q17.9 18.35 17.6 18.35Q17.3 18.35 17.075 18.125Z"})})});ai.displayName="CloseIcon";var oi=ai;const li=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M8.5 19v-3.5H5V14h5v5ZM5 10V8.5h3.5V5H10v5Zm9 9v-5h5v1.5h-3.5V19Zm0-9V5h1.5v3.5H19V10Z"})]})});li.displayName="FullscreenExitIcon";var ci=li;const di=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M5 19v-5h1.5v3.5H10V19Zm0-9V5h5v1.5H6.5V10Zm9 9v-1.5h3.5V14H19v5Zm3.5-9V6.5H14V5h5v5Z"})]})});di.displayName="FullscreenIcon";var hi=di;const ui=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M14.75 18.5Q14.125 18.5 13.688 18.062Q13.25 17.625 13.25 17V7Q13.25 6.375 13.688 5.938Q14.125 5.5 14.75 5.5H17Q17.625 5.5 18.062 5.938Q18.5 6.375 18.5 7V17Q18.5 17.625 18.062 18.062Q17.625 18.5 17 18.5ZM7 18.5Q6.375 18.5 5.938 18.062Q5.5 17.625 5.5 17V7Q5.5 6.375 5.938 5.938Q6.375 5.5 7 5.5H9.25Q9.875 5.5 10.312 5.938Q10.75 6.375 10.75 7V17Q10.75 17.625 10.312 18.062Q9.875 18.5 9.25 18.5ZM14.75 17H17V7H14.75ZM7 17H9.25V7H7ZM7 7V17ZM14.75 7V17Z"})]})});ui.displayName="PauseIcon";var mi=ui;const pi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M 8.739583,18.4955 Q 8.2525391,18.799994 7.7654953,18.526169 7.2791816,18.252344 7.2791816,17.674025 V 6.3259749 q 0,-0.578319 0.4863137,-0.852144 0.4870438,-0.273825 0.9740877,0.03067 l 8.91429,5.6889941 q 0.456376,0.304494 0.456376,0.806872 0,0.501648 -0.456376,0.806142 z M 8.80019,12.014969 Z m 0,4.625091 7.302007,-4.625091 L 8.80019,7.3906079 Z"})]})});pi.displayName="PlayIcon";var vi=pi;const gi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M18.95 21.6 16.45 19.125Q16.15 19.3 15.838 19.462Q15.525 19.625 15.2 19.775Q14.825 19.925 14.5 19.675Q14.175 19.425 14.175 19Q14.175 18.8 14.3 18.65Q14.425 18.5 14.6 18.4Q14.8 18.325 15 18.237Q15.2 18.15 15.375 18.05L11.8 14.45V16.6Q11.8 17.2 11.238 17.438Q10.675 17.675 10.25 17.25L7.5 14.5H4.7Q4.3 14.5 4.05 14.238Q3.8 13.975 3.8 13.6V10.4Q3.8 10.025 4.05 9.762Q4.3 9.5 4.7 9.5H6.825L2.525 5.2Q2.325 4.975 2.312 4.662Q2.3 4.35 2.525 4.125Q2.75 3.925 3.05 3.925Q3.35 3.925 3.575 4.125L20 20.55Q20.2 20.775 20.213 21.087Q20.225 21.4 20 21.6Q19.775 21.825 19.475 21.825Q19.175 21.825 18.95 21.6ZM15.2 4.175Q17.575 5.175 19.025 7.275Q20.475 9.375 20.475 11.975Q20.475 13.3 20.088 14.5Q19.7 15.7 18.975 16.725L17.9 15.65Q18.425 14.85 18.7 13.912Q18.975 12.975 18.975 11.975Q18.975 9.825 17.775 8.087Q16.575 6.35 14.6 5.55Q14.4 5.45 14.288 5.287Q14.175 5.125 14.175 4.925Q14.175 4.5 14.5 4.262Q14.825 4.025 15.2 4.175ZM9.3 11.975ZM15.925 13.675 14.175 11.925V8.3Q15.175 8.85 15.738 9.85Q16.3 10.85 16.3 12Q16.3 12.45 16.2 12.862Q16.1 13.275 15.925 13.675ZM11.8 9.525 9.625 7.375 10.25 6.75Q10.675 6.325 11.238 6.562Q11.8 6.8 11.8 7.4ZM10.3 15.15V12.95L8.325 11H5.3V13H8.15Z"})]})});gi.displayName="VolumeOffIcon";var fi=gi;const yi=gt({viewBox:"0 0 24 24",svg:S(M,{children:[P("path",{fill:"none",d:"M0 0h24v24H0z"}),P("path",{d:"M15.05 19.775Q14.675 19.925 14.363 19.675Q14.05 19.425 14.05 19Q14.05 18.8 14.163 18.65Q14.275 18.5 14.475 18.4Q16.45 17.6 17.65 15.863Q18.85 14.125 18.85 11.975Q18.85 9.825 17.65 8.087Q16.45 6.35 14.475 5.55Q14.25 5.45 14.15 5.287Q14.05 5.125 14.05 4.925Q14.05 4.5 14.363 4.262Q14.675 4.025 15.05 4.175Q17.45 5.175 18.9 7.275Q20.35 9.375 20.35 11.975Q20.35 14.575 18.9 16.675Q17.45 18.775 15.05 19.775ZM4.55 14.5Q4.175 14.5 3.913 14.238Q3.65 13.975 3.65 13.6V10.4Q3.65 10.025 3.913 9.762Q4.175 9.5 4.55 9.5H7.375L10.125 6.75Q10.55 6.325 11.1 6.562Q11.65 6.8 11.65 7.4V16.6Q11.65 17.2 11.1 17.438Q10.55 17.675 10.125 17.25L7.375 14.5ZM14.05 15.65V8.3Q15 8.825 15.575 9.825Q16.15 10.825 16.15 12Q16.15 13.175 15.575 14.15Q15 15.125 14.05 15.65ZM10.15 8.85 8 11H5.15V13H8L10.15 15.15ZM7.65 12Z"})]})});yi.displayName="VolumeUpIcon";var bi=yi;const Ri=({onClick:e})=>e?P(si,{className:"x-3deye-player__control-close",onClick:e,title:st.t("playerTools.closePlayer"),children:P(oi,{})}):null;Ri.displayName="CloseControl";var Ci=Ri;const wi=({toggle:e,active:t})=>P(si,{onClick:e??void 0,title:st.t("playerTools.fullScreen"),children:P(t?ci:hi,{})});wi.displayName="FullscreenControl";var Ti=wi;const ki=x.createContext(null),Pi=B((()=>{const e=z(ki);return P(si,{className:"x-3deye-player__control-playpause",onClick:e.togglePlayback,title:e.paused?st.t("playerTools.play"):st.t("playerTools.pause"),children:e.paused?P(vi,{}):P(mi,{})})}));Pi.displayName="PlayPauseControl";var Si=Pi;const Mi=[{value:.5,name:"0.5x"},{value:1,name:"1x"},{value:2,name:"2x"},{value:4,name:"4x"},{value:8,name:"8x"},{value:16,name:"16x"}],xi=B((()=>{const[e,t]=O(!1),i=z(ki);if("WebRTC"===i.mode)return null;let s=Mi.findIndex((e=>e.value===i.playbackRate));-1===s&&(s=1);const r=P(si,{className:"control-playbackrate",onClick:()=>t(!e),title:st.t("playerTools.playbackRate"),children:Mi[s].name});return P(Ht,{placement:"top",withArrow:!0,target:r,opened:e,onOpenChange:t,className:"popover-playbackrate",children:Array.from({length:Mi.length},((e,t)=>(t=Mi.length-1-t,P(vt,{onClick:()=>{return e=t,void i.setPlaybackRate(Mi[e].value);var e},style:{border:"2px solid "+(t===s?"rgba(255,255,255,0.5)":"transparent")},children:Mi[t].name},t))))})}));xi.displayName="PlaybackRateControl";var Ii=xi;const Ei=B((()=>{const e=z(ki);return P(si,{onClick:e.toggleResizeMode,title:"contain"===e.videoResizeMode?st.t("videoResizeMode.fit"):st.t("videoResizeMode.stretch"),children:"contain"===e.videoResizeMode?P(yt,{size:16}):P(Ot,{size:16})})}));Ei.displayName="ResizeModeControl";var Li=Ei;const Ni=()=>{const e=z(ki);return P(si,{onClick:()=>{const t=`${e.camera.name} ${(e.currentTime||new Date).toISOString().replace(/:/g,"-")}`;((e,t)=>{const i=document.createElement("canvas"),s=i.getContext("2d");if(!s)return;const{videoWidth:r,videoHeight:n}=e;i.width=r,i.height=n,s.drawImage(e,0,0,r,n);const a=i.toDataURL("image/jpeg"),o=document.createElement("a");o.href=a,o.download=`${t}.jpg`,document.body.appendChild(o),o.click(),o.remove()})(e.video,t)},title:st.t("playerTools.snapshot"),children:P(ni,{})})};var Di=Ni;Ni.displayName="SnapshotControl";const Oi=e=>{e.stopPropagation()},_i=B((()=>{const e=z(ki);return S(si,{className:"volume-control",title:st.t("playerTools.volume"),onClick:e.toggleMute,onWheel:t=>{const i=t.deltaY;i&&e.setVolume(ut(e.volume+(i<0?.1:-.1),0,1))},children:[e.muted?P(fi,{}):P(bi,{}),P("div",{onClick:Oi,className:"volume-range",children:P(Yt,{value:Math.round(100*e.volume),labelFormat:e=>`${e}%`,orientation:"vertical",onChange:t=>{e.setVolume(Number(t)/100)}})})]})}));_i.displayName="VolumeControl";var Ai=_i;const zi="x-3deye-player__controls--spaced",Fi="x-3deye-player__controls--compact",Qi="x-3deye-player__control--reflowed",Vi=e=>{if(!e)return;if(e.classList.contains(Fi)){e.classList.remove(Fi);for(const t of Array.from(e.children).filter((e=>e.classList.contains(Qi))))t instanceof HTMLElement&&(t.style.position="",t.style.bottom="",t.style.right="",t.classList.remove(Qi))}if(e.classList.contains(zi)){e.classList.remove(zi);for(const t of e.querySelectorAll(".before-spacer"))t.classList.remove("before-spacer")}if(e.scrollWidth-e.offsetWidth<=0){(e.querySelector(".spacer")?.clientWidth??0)>0&&e.classList.add(zi);for(const t of e.querySelectorAll(".spacer"))t.previousElementSibling?.classList.add("before-spacer");return}e.classList.add(Fi);const t=Array.from(e.children);let i=2,s=i;for(;e.scrollWidth-e.offsetWidth>0&&i<=t.length;){const e=t[t.length-i];e&&!e.classList.contains("spacer")?(e.style.position="absolute",e.style.bottom=8+38*(s-1)+"px",e.style.right="8px",e.classList.add(Qi),i++,s++):i++}};function Hi({style:e,children:t}){const i=E(null);return A((()=>{if(!i.current)return;const e=new MutationObserver((()=>Vi(i.current)));return e.observe(i.current,{childList:!0}),()=>e.disconnect()}),[]),A((()=>{const e=new ResizeObserver((()=>{Vi(i.current)})),t=i.current;return t&&e.observe(t),()=>e.disconnect()}),[]),F((()=>{Vi(i.current)})),P("div",{ref:i,className:"x-3deye-player__controls",style:e,children:t})}Hi.Spacer=()=>P("div",{className:"spacer"});const Ui=B((()=>{const e=z(ki),[t,i]=O(!1);if(!e.stats||!e.behavior)return null;const s=e=>{e.preventDefault(),i(!t)};if(!t)return P("details",{className:"x-3deye-player__stats",open:t,style:{pointerEvents:"auto"},children:P("summary",{onClick:s,children:"Stats"})});const r=e.stats,n=r.timestamp-r.startTime,a=r.bytesReceived/n,o=r.packetsReceived?Math.round(r.packetsLost/(r.packetsLost+r.packetsReceived)*100):0,{ttff:l}=e.behavior,c=l>0?`${(l/1e3).toFixed(2)} s`:"TBD";return S("details",{className:"x-3deye-player__stats",open:t,style:{pointerEvents:"auto"},children:[P("summary",{onClick:s,children:"Stats"}),S("dl",{children:[S("div",{children:[P("dt",{children:"frame width:"})," ",P("dd",{children:r.frameWidth||e.video.videoWidth})]}),S("div",{children:[P("dt",{children:"frame height:"})," ",P("dd",{children:r.frameHeight||e.video.videoHeight})]}),S("div",{children:[P("dt",{children:"bitrate:"}),S("dd",{children:[Math.round(8*r.bitrate)," kbit/s"]})]}),S("div",{children:[P("dt",{children:"average bitrate:"})," ",S("dd",{children:[Math.round(8*a)," kbit/s"]})]}),S("div",{children:[P("dt",{children:"elapsed time:"})," ",S("dd",{children:[Math.floor(n/1e3)," s"]})]}),S("div",{children:[P("dt",{children:"packets loss:"}),S("dd",{style:{color:o<10?"green":o<50?"yellow":"red"},children:[o,"%"]})]}),S("div",{children:[P("dt",{children:"packets received:"})," ",P("dd",{children:r.packetsReceived})]}),S("div",{children:[P("dt",{children:"packets lost:"})," ",P("dd",{children:r.packetsLost})]}),S("div",{children:[P("dt",{children:"frames received:"})," ",P("dd",{children:r.framesReceived})]}),S("div",{children:[P("dt",{children:"frames decoded:"})," ",P("dd",{children:r.framesDecoded})]}),S("div",{children:[P("dt",{children:"frames dropped:"})," ",P("dd",{children:r.framesDropped})]}),S("div",{children:[P("dt",{children:"round-trip time:"})," ",P("dd",{children:r.rtt})]}),S("div",{children:[P("dt",{children:"time to first frame:"})," ",P("dd",{children:c})]})]})]})}));Ui.displayName="PlayerStats";var Bi=Ui;const $i=B((()=>{const e=z(ki),[t,i]=O(!1);return S(Ht,{className:"x-3deye-player__camera-name-popover",opened:t,onOpenChange:i,placement:"bottom-start",autoDismiss:!1,withArrow:!0,target:P("div",{className:"x-3deye-player__camera-name",onClick:()=>i(!t),children:e.camera.name}),children:[S("div",{children:["id:"," ",P(vt,{style:{height:24},onClick:t=>{t.altKey?navigator.clipboard.writeText(JSON.stringify(e.camera.raw,null,2)):navigator.clipboard.writeText(e.camera.id.toString())},title:"copy to clipboard",children:e.camera.id})]}),S("div",{style:{lineHeight:"24px"},children:["provider: ",e.mode]}),P(Bi,{})]})}));$i.displayName="CameraName";var Wi,ji=$i;!function(e){e.Initial="initial",e.InitiallyPaused="initially-paused",e.Playing="playing",e.Paused="paused",e.Reconnecting="reconnecting",e.Stalled="stalled",e.Error="error",e.Failed="failed"}(Wi||(Wi={}));class qi extends nt{}const Zi=3e4;class Yi{player;video;hlsPlayer=null;live=!1;loading=!0;error=null;disposables=[];state=Wi.Initial;constructor(e,t,i){this.player=e,this.video=i,he(this,{hlsPlayer:ue.ref,goLive:!0,live:ue,loading:ue,error:ue,state:ue,seek:me,dispose:me}),this.live=t,this.disposables.push(at((()=>this.hlsPlayer),!0).pipe(be((e=>e?new s((t=>{e.on(ae.Events.ERROR,((e,i)=>{t.next(i)}))})):r))).subscribe((e=>{console.error(e),pe((()=>{e.details!==oe.BUFFER_ADD_CODEC_ERROR?e.type===le.NETWORK_ERROR&&[oe.FRAG_LOAD_ERROR,oe.MANIFEST_LOAD_ERROR].includes(e.details)&&403===e.response?.code?this.error=new qi("PLAYER_ERROR","HLS error",e):e.fatal&&(e.type===le.MEDIA_ERROR&&this.hlsPlayer&&this.hlsPlayer.recoverMediaError(),this.error=new qi("PLAYER_ERROR","HLS error",e)):this.error=new qi("PLAYER_ERROR","HLS error",e)}))}))),null===e.seekTime&&(this.live=!0),this.initDelayCompensation(),this.initPlayerState(),this.initLoadingTimeout(),this.reactToCamera(),this.catchUpAfterPause()}initDelayCompensation(){this.disposables.push(at((()=>this.live),!0).pipe(be((()=>this.live?at((()=>this.state),!0).pipe(be((e=>e!==Wi.Playing?r:n(5e3+5e3*Math.random(),3e4)))):r))).subscribe((()=>{const e=this.getDateRange(),{currentTime:t}=this.player;e&&t&&+e[1]-+t>6e4&&this.goLive()})))}initPlayerState(){this.disposables.push(this.player.progress$.pipe(Re((()=>{this.state===Wi.Playing||this.player.paused||pe((()=>{this.state=Wi.Playing}))})),Ce(2e3),we((()=>this.state===Wi.Playing))).subscribe((()=>{pe((()=>{this.state=Wi.Stalled}))}))),this.disposables.push(ve((()=>this.player.paused),(()=>{this.player.paused&&(this.state=Wi.Paused)})))}getPlayingFragment(){return this.hlsPlayer?.streamController?.fragPlaying??null}seek=e=>{if(!this.hlsPlayer)return;const t=this.getPlayingFragment();if(!t?.relurl)return void(this.player.seekTime=e);const i=+t.relurl.substring(0,t.relurl.length-3)-1e3*t.start;this.video.currentTime=(+e-i)/1e3,this.live=!1};getDateRange=()=>{if(!this.hlsPlayer)return null;const e=this.video.seekable;if(!e.length)return null;const t=e.start(0),i=e.end(e.length-1),s=this.getPlayingFragment();if(!s?.relurl)return null;const r=+s.relurl.substring(0,s.relurl.length-3)-1e3*s.start;return[new Date(1e3*t+r),new Date(1e3*i+r)]};goLive=()=>{this.seek(new Date),this.live=!0};getCurrentTime(){if(!this.hlsPlayer)return null;const e=this.getPlayingFragment();return e?.relurl?new Date(+e.relurl.substring(0,e.relurl.length-3)+1e3*(this.video.currentTime-e.start)):null}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(Zi)):r))).subscribe((()=>{pe((()=>{this.player.camera.isOnline?this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)}):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))}))),this.disposables.push(at((()=>this.state),!0).pipe(be((e=>e!==Wi.Stalled?r:n(Zi)))).subscribe((()=>{pe((()=>{this.player.camera.isOnline?this.error||(this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))})))}reactToCamera(){const{player:e}=this;this.disposables.push(ve((()=>({streamUrl:e.camera.streamUrl})),(({streamUrl:t})=>{pe((()=>{this.loading=!0})),this.hlsPlayer&&this.hlsPlayer.destroy(),t?(this.hlsPlayer=new ae,this.hlsPlayer.attachMedia(this.video),this.hlsPlayer.loadSource(t)):pe((()=>{e.camera.isOnline?this.error=new qi("NO_PLAYABLE_STREAM_ERROR","no playable stream"):this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline")}))}),{fireImmediately:!0}))}catchUpAfterPause(){this.disposables.push(a(this.video,"play").pipe(we((()=>this.live))).subscribe(this.goLive))}dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.hlsPlayer&&this.hlsPlayer.destroy(),this.hlsPlayer=null,this.player=null}}class Gi{player;video;live=!0;loading=!0;error=null;state=null;disposables=[];availabilityStartTime=-1;constructor(e,t){this.player=e,this.video=t,this.initLoadingTimeout(),this.reactToCamera(),this.catchUpAfterPause(),he(this,{loading:ue,error:ue})}goLive(){this.video.currentTime=this.video.seekable.end(0)}getCurrentTime(){return this.availabilityStartTime<0&&this.updateAvailabilityStartTime(),new Date(this.availabilityStartTime+1e3*this.video.currentTime)}updateAvailabilityStartTime(){this.video.seekable.length&&(this.availabilityStartTime=Date.now()-1e3*this.video.seekable.end(0))}getDateRange(){const{availabilityStartTime:e}=this;if(e<0)return null;if(!this.video.seekable.length)return null;return[new Date(e+1e3*this.video.seekable.start(0)),new Date(e+1e3*this.video.seekable.end(0))]}seek(e){this.live=!1,this.availabilityStartTime<0&&(this.updateAvailabilityStartTime(),this.availabilityStartTime<0)?this.player.seekTime=e:this.video.currentTime=(+e-+this.availabilityStartTime)/1e3}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(3e4)):r))).subscribe((()=>{pe((()=>{this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})}))})))}reactToCamera(){this.disposables.push(ve((()=>({streamUrl:this.player.camera.streamUrl})),(()=>{const e=this.player.camera,{streamUrl:t}=e.raw;pe((()=>{this.loading=!0})),this.availabilityStartTime=-1,this.video.src="",t?this.video.src=t:pe((()=>{this.player.camera.isOnline?this.error=new qi("NO_PLAYABLE_STREAM_ERROR","no playable stream"):this.error=new qi("CAMERA_OFFLINE_ERROR","camera offline")}))}),{fireImmediately:!0}))}catchUpAfterPause(){this.disposables.push(a(this.video,"play").pipe(we((()=>this.live))).subscribe((()=>{console.log("unpaused live HLS"),this.goLive()})))}dispose(){this.disposables.forEach((e=>{e instanceof o?e.closed||e.unsubscribe():e()}))}}class Ji{player;video;disposables=[];state=null;loading=!1;error=null;constructor(e,t){this.player=e,this.video=t,this.playNextChunkOnComplete(),this.reactToChunk(),this.initLoadingTimeout(),he(this,{loading:ue,error:ue})}seek=e=>{if(!this.player.chunk)return;const t=this.player.clip&&this.player.clip.isTimelapse?1e3*this.player.chunk.duration/(+this.player.chunk.endTime-+this.player.chunk.startTime):1,i=(+e-+this.player.chunk.startTime)/1e3*t;this.video.currentTime=i};getCurrentTime(){const e=this.player.chunk;if(!e)return null;const{clip:t}=this.player,i=t&&t.isTimelapse&&this.video.duration?(+e.endTime-+e.startTime)/this.video.duration:1e3;return new Date(+e.startTime+this.video.currentTime*i)}reactToChunk(){this.disposables.push(ve((()=>this.player.chunk),(e=>{if(!e)return this.video.pause(),this.video.removeAttribute("src"),void this.video.load();this.loading=!0,this.video.src=e.streamUrl,this.video.playbackRate=this.player.playbackRate}),{fireImmediately:!0}))}playNextChunkOnComplete(){this.disposables.push(this.player.ended$.subscribe((()=>{const{currentTime:e}=this.player;if(e)if(this.player.clip&&this.player.clip.isTimelapse){const{archives:t}=this.player.clip;if(t){const i=t.find((t=>t.startTime>=e));if(!i||i===this.player.chunk)return;return void this.player.changeMedia({time:i?.startTime,chunk:i})}}else this.player.changeMedia({time:new Date(+this.player.chunk.endTime+1)});else console.warn("Couldn't jump to the next chunk. Current player time is unknown")})))}initLoadingTimeout(){this.disposables.push(at((()=>this.loading),!0).pipe(be((e=>e?at((()=>this.loading),!0).pipe(Ce(3e4)):r))).subscribe((()=>{this.error=new qi("PLAYBACK_TIMEOUT_ERROR","playback timeout",{timeout:Math.round(30)})})))}resetVideo(){const{video:e}=this;e.pause(),e.removeAttribute("src"),e.load()}dispose(){this.disposables.forEach((e=>{e instanceof o?e.closed||e.unsubscribe():e()})),this.resetVideo(),this.player=null}}const Xi=new Map;class Ki{url;connection;sessionId;keepAliveIntervalId=null;pluginsCount=0;constructor(e){this.url=e,he(this,{sessionId:ue,pluginsCount:ue,registerPlugin:me,deregisterPlugin:me}),this.init()}registerPlugin=()=>{this.pluginsCount++};deregisterPlugin=()=>{this.pluginsCount--};async init(){const{url:e}=this;this.connection=new Ye(e,"janus-protocol",{maxReconnectionDelay:3e4}),this.startKeepingAlive(),this.stopWhenNoLongerNeeded(),this.connection.addEventListener("message",(({data:e})=>{const t=JSON.parse(e);"error"===t.janus&&458===t.error.code&&this.createSession()})),await new Promise((e=>{const t=()=>{this.connection.removeEventListener("open",t),e(void 0)};this.connection.addEventListener("open",t)})),this.createSession()}stopWhenNoLongerNeeded(){at((()=>this.pluginsCount),!0).pipe(be((e=>e?r:n(1e4)))).subscribe((()=>{this.dispose()}))}dispose(){this.connection.close(),Xi.delete(this.url)}async createSession(){const e=this.randomString(12);this.connection.send(JSON.stringify({janus:"create",transaction:e}));const t=await new Promise(((t,i)=>{const s=r=>{const n=JSON.parse(r.data);if(n.transaction===e){if(this.connection.removeEventListener("message",s),"success"===n.janus)return t(n.data.id);i(n.janus.error)}};this.connection.addEventListener("message",s)}));pe((()=>{this.sessionId=t}))}startKeepingAlive(){ge((()=>!!this.sessionId),(()=>{l((e=>this.connection.addEventListener("open",e)),(e=>this.connection.removeEventListener("open",e))).pipe(Te(null),be((()=>n(0,3e4).pipe(ke(l((e=>this.connection.addEventListener("close",e)),(e=>this.connection.removeEventListener("close",e)))))))).subscribe(this.keepAlive)}))}keepAlive=()=>{this.connection.send(JSON.stringify({janus:"keepalive",session_id:this.sessionId,transaction:this.randomString(12)}))};randomString(e){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let i="";for(let s=0;s<e;s++){const e=Math.floor(62*Math.random());i+=t.substring(e,e+1)}return i}}class es extends nt{}class ts{server;pc=null;pluginHandleId;stream=null;stats=null;error=null;disposables=[];cameraId;pin;connectionState=null;disposeDelayedStream;startTransaction;statsRequest=null;options={allowedIceCandidateProtocols:["udp","tcp"],iceServers:[{urls:"stun:stun.3deye.me:80"},{urls:"stun:stun.l.google.com:19302"}],iceTransportPolicy:"all"};constructor(e,t,i,s){he(this,{pc:ue.ref,pluginHandleId:ue,stream:ue.ref,stats:ue.ref,error:ue.ref,connectionState:ue,onmessage:me,setStream:me,updateStats:me,dispose:me}),Object.assign(this.options,s),this.server=function(e){if(Xi.has(e)){const t=Xi.get(e);if(!t)throw new Error("Couldn't get server");return t}const t=new Ki(e);return Xi.set(e,t),t}(e),this.server.registerPlugin(),this.cameraId=t,this.pin=i,this.autoAttachPlugin(),this.autoCollectStats(),this.initConnectionState(),this.initTrack(),this.disposables.push(ve((()=>this.pluginHandleId),this.onInit,{fireImmediately:!0})),this.disposables.push(ge((()=>!!this.server.sessionId),(()=>this.disposables.push(l((e=>this.server.connection.addEventListener("message",e)),(e=>this.server.connection.removeEventListener("message",e)),(e=>e)).subscribe(this.onmessage)))))}onInit=e=>{if(!e)return;const{cameraId:t,pin:i}=this;this.pc&&(this.disposeDelayedStream&&(this.disposeDelayedStream(),this.disposeDelayedStream=null),this.safeCloseRTCPeerConnection(this.pc)),this.pc=new RTCPeerConnection({iceServers:this.options.iceServers,bundlePolicy:"max-bundle",iceTransportPolicy:this.options.iceTransportPolicy}),this.server.connection.send(JSON.stringify({janus:"message",handle_id:e,session_id:this.server.sessionId,body:{request:"watch",id:t,pin:i},transaction:this.server.randomString(12)}))};pause=()=>{this.server.connection.send(JSON.stringify({janus:"message",handle_id:this.pluginHandleId,session_id:this.server.sessionId,body:{request:"pause",id:this.cameraId},transaction:this.server.randomString(12)}))};resume=()=>{this.server.connection.send(JSON.stringify({janus:"message",handle_id:this.pluginHandleId,session_id:this.server.sessionId,body:{request:"start",id:this.cameraId},transaction:this.server.randomString(12)}))};onmessage=({data:e})=>{const{pluginHandleId:t}=this;if(!t)return;const i=JSON.parse(e);return"error"===i.janus&&i.transaction===this.startTransaction?(this.error=new es("STREAMING_ERROR",i.error.reason,i.error),console.error(i.error)):"sender"in i&&i.sender===t?"hangup"===i.janus?("ICE FAILED"===i.reason.toUpperCase()?this.error=new es("ICE_FAILED",i.reason,i):"CLOSE PC"===i.reason.toUpperCase()?this.error=new es("CLOSE_PC",i.reason,i):this.error=new es("STREAMING_ERROR",i.reason,i),console.error(i.reason)):"event"===i.janus&&i.plugindata?.data&&"error"in i.plugindata.data?(this.error=new es("STREAMING_ERROR",i.plugindata.data.error.reason,i.plugindata.data.error),console.error(i.plugindata.data)):void("jsep"in i&&this.onremotedescription(new RTCSessionDescription(i.jsep))):void 0};async onremotedescription(e){const{pluginHandleId:t}=this,i=this.pc;if(!e.sdp||!i)return;const s=[];if(1===this.options.allowedIceCandidateProtocols.length){const t=this.options.allowedIceCandidateProtocols[0],i=e.sdp.split("\r\n");let r="video";const n={video:[],audio:[]};for(const e of i)e.startsWith("a=mid:audio")?r="audio":e.startsWith("a=mid:video")?r="video":e.startsWith("a=candidate")&&n[r].push(e);const a=i.filter((e=>!(e.startsWith("a=candidate")||e.startsWith("a=end-of-candidates")))),o=e=>e.split(/\s+/)[2]===t,l={video:n.video.filter(o),audio:n.audio.filter(o)};e=new RTCSessionDescription({type:"offer",sdp:[...a].join("\r\n")});let c={audio:[],video:[]};l.video.length?c=l:(console.warn(`no video ${t.toUpperCase()} candidates found. Falling back to all candidates`),c=n);for(const e in c)if(Object.hasOwn(c,e))for(const t of c[e])s.push(new RTCIceCandidate({candidate:t.replace(/^a=/,""),sdpMLineIndex:0,sdpMid:e}))}try{await i.setRemoteDescription(e),s.length>1&&([s[0],s[1]]=[s[1],s[0]]),await Promise.allSettled(s.map((e=>i.addIceCandidate(e))));const r=await i.createAnswer();await i.setLocalDescription(r);const n={type:r.type,sdp:r.sdp};this.startTransaction=this.server.randomString(12),this.server.connection.send(JSON.stringify({janus:"message",handle_id:t,session_id:this.server.sessionId,body:{request:"start"},jsep:n,transaction:this.startTransaction}))}catch(e){return console.error(e),void pe((()=>{e instanceof Error&&e.message.toLowerCase().includes("failed to set remote offer sdp")?this.error=new es("SDP_OFFER_FAILED",e.message,e):e instanceof Error&&e.message.toLowerCase().includes("failed to set local answer sdp")?this.error=new es("SDP_ANSWER_FAILED",e.message,e):this.error=new es("STREAMING_ERROR",e instanceof Error?e.message:e,e)}))}i.addEventListener("icecandidate",(e=>{e.candidate&&this.server.connection.send(JSON.stringify({janus:"trickle",candidate:e.candidate,handle_id:t,session_id:this.server.sessionId,transaction:this.server.randomString(12)}))}))}setStream=e=>{this.disposeDelayedStream&&this.disposeDelayedStream(),null!==e?this.disposeDelayedStream=ge((()=>"completed"===this.connectionState||"connected"===this.connectionState),(()=>{this.stream=e})):this.stream=null};autoAttachPlugin(){this.disposables.push(at((()=>this.server?this.server.sessionId:null),!0).pipe(we(Boolean),be((()=>{const e=this.server.randomString(12);return this.server.connection.send(JSON.stringify({janus:"attach",plugin:"janus.plugin.streaming",transaction:e,session_id:this.server.sessionId})),l((e=>this.server.connection.addEventListener("message",e)),(e=>this.server.connection.removeEventListener("message",e)),(({data:e})=>JSON.parse(e))).pipe(we((t=>"transaction"in t&&t.transaction===e)),Pe(1))}))).subscribe((e=>{pe((()=>{switch(e.janus){case"success":this.pluginHandleId=e.data.id;break;case"error":this.error=new es("PLUGIN_INIT_ERROR",e.error.reason,e);break;default:console.error("unexpected message",e)}}))})))}initConnectionState=()=>{this.disposables.push(at((()=>this.pc),!0).pipe(be((e=>null===e?t(null):a(e,"iceconnectionstatechange").pipe(Te(null),Se((()=>e.iceConnectionState)))))).subscribe((e=>{pe((()=>{this.connectionState=e}))})))};initTrack=()=>{this.disposables.push(at((()=>this.pc),!0).pipe(be((e=>null===e?t(null):l((t=>e.addEventListener("track",t)),(t=>e.removeEventListener("track",t)),(e=>e)).pipe(Te(null))))).subscribe((e=>{let t=null;null!==e&&(t=e.streams[0],e.track&&(e.track.onended=e=>{this.stream&&this.stream.removeTrack(e.target)})),this.setStream(t)})))};autoCollectStats=()=>{this.disposables.push(at((()=>this.stream),!0).pipe(be((e=>e?n(0,1e3).pipe(Me((()=>this.getStats()))):t(null)))).subscribe(this.updateStats))};updateStats=e=>{if(e){if(this.stats){const t=e.bytesReceived-this.stats.bytesReceived,i=e.timestamp-this.stats.timestamp;e.bitrate=t/i,e.startTime=this.stats.startTime}else e.startTime=e.timestamp;this.stats=e}else this.stats=null};async getStats(){if(!this.pc)return null;this.statsRequest=this.pc.getStats();const e=await this.statsRequest;this.statsRequest=null;const t={};return e.forEach((e=>{if("inbound-rtp"!==e.type||"video"!==e.kind&&"video"!==e.mediaType){if("track"===e.type){const{frameWidth:i,frameHeight:s,framesDropped:r,framesReceived:n}=e;Object.assign(t,{frameWidth:i,frameHeight:s,framesDropped:r,framesReceived:n})}else if("candidate-pair"===e.type)Object.assign(t,{rtt:1e3*e.currentRoundTripTime});else if("ssrc"===e.type){const i={};for(const t of e.values)for(const e of Object.keys(t))i[e]=t[e];const{framesDecoded:s,bytesReceived:r,packetsLost:n,packetsReceived:a,googFrameHeightReceived:o,googFrameWidthReceived:l}=i;Object.assign(t,{frameWidth:+l,frameHeight:+o,framesDecoded:s,bytesReceived:r,packetsLost:n,packetsReceived:a})}}else{const{bytesReceived:i,framesDecoded:s,packetsLost:r,packetsReceived:n,timestamp:a}=e;Object.assign(t,{bytesReceived:i,framesDecoded:s,packetsLost:r,packetsReceived:n,timestamp:a})}})),t}async safeCloseRTCPeerConnection(e){await this.statsRequest,e.close()}dispose=()=>{this.disposeDelayedStream&&(this.disposeDelayedStream(),this.disposeDelayedStream=null),this.pc&&this.safeCloseRTCPeerConnection(this.pc);for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.server.deregisterPlugin(),this.server.connection.send(JSON.stringify({janus:"detach",handle_id:this.pluginHandleId,session_id:this.server.sessionId,transaction:this.server.randomString(12)})),this.pc=null,this.stream=null,this.stats=null,this.error=null}}const is=1e4;class ss{player;options;streamingPlugin;disposables=[];state=null;setPlayerState(e){this.state=e}ttff=-1;live=!0;loading=!1;error=null;get streamingError(){return this.streamingPlugin?this.streamingPlugin.error:null}get stream(){return this.streamingPlugin?this.streamingPlugin.stream:null}getCurrentTime(){return this.state===Wi.Playing?new Date:null}constructor(e,t){this.player=e,this.options=t,he(this,{streamingPlugin:ue.ref,state:ue,setPlayerState:me,ttff:ue,streamingError:ce,stream:ce,loading:ue,error:ue,dispose:me}),this.player=e,RTCPeerConnection?this.disposables.push(this.reactToStream(),...this.initPauseAndResume(),this.reconnectWhenNeeded(),this.fallbackToDvrOnFirstFrameTimeout(),this.fallBackToDvrOnConnectionProblems(),this.initTransitionToReconnecting(),this.setInitialIndication(),this.updateIndicationOnPlaying(),this.updateIndicationOnReconnecting(),this.initFromErrorToPlaying(),this.initFromInitialToPlaying(),this.reactToStreamingError(),this.initTtff(),this.initStats(),this.reactToCamera()):this.state=Wi.Failed}reconnectWhenNeeded(){return at((()=>this.state),!0).pipe(c((e=>{if(e!==Wi.Reconnecting)return r;this.streamingPlugin&&this.streamingPlugin.dispose();const{webRtcUrl:t,id:i,pin:s}=this.player.camera;return pe((()=>{this.streamingPlugin=new ts(t,i,s,this.options)})),at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),h(3e4)):r)),u(1))}))).subscribe({next:()=>{this.setPlayerState(Wi.Playing)},error:e=>{if(e instanceof m)return console.error("player",this.player.id,"cam",this.player.camera.id,"no frames in 30s after reconnect"),void(this.streamingPlugin?.pc&&["connected","new"].includes(this.streamingPlugin.pc.iceConnectionState)?(console.warn("player",this.player.id,"cam",this.player.camera.id,"fallback to DVR"),this.state=Wi.Stalled):console.warn("player",this.player.id,"cam",this.player.camera.id,"waiting for reconnect"));pe((()=>{this.setPlayerState(Wi.Error),this.error=e})),console.error(e)}})}fallbackToDvrOnFirstFrameTimeout(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),h(is)):r)),u(1))))).subscribe({error:e=>{if(e instanceof m)return console.error("player",this.player.id,"cam",this.player.camera.id,"no frames in 10s. Fallback to DVR"),void this.setPlayerState(Wi.Stalled);pe((()=>{this.setPlayerState(Wi.Error),this.error=e})),console.error(e)}})}fallBackToDvrOnConnectionProblems(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.streamingPlugin?.connectionState),!0).pipe(c((e=>e&&"connected"!==e&&"new"!==e?"failed"===e?p((()=>new qi("CONNECTION_FAILED_ERROR","Connection failed"))):n(2e4).pipe(v((()=>p((()=>new qi("CONNECTION_TIMEOUT_ERROR","Connection timeout")))))):r)))))).subscribe({error:e=>e instanceof qi&&"CONNECTION_TIMEOUT_ERROR"===e.name?(console.error("player",this.player.id,"cam",this.player.camera.id,"no connection established in 20s. Fallback to DVR"),void this.setPlayerState(Wi.Stalled)):e instanceof qi&&"CONNECTION_FAILED_ERROR"===e.name?(console.error("player",this.player.id,"cam",this.player.camera.id,"Connection failed"),void this.setPlayerState(Wi.Stalled)):(pe((()=>{this.state=Wi.Error,this.error=e})),void console.error(e))})}initTransitionToReconnecting(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Playing?r:at((()=>this.streamingPlugin?.stats?.framesDecoded??null),!0).pipe(d(Boolean),g(is))))).subscribe((()=>{console.log("player",this.player.id,"cam",this.player.camera.id,"no new frames in 10000s"),this.setPlayerState(Wi.Reconnecting)}))}setInitialIndication(){return ve((()=>this.state),(e=>{e===Wi.Initial&&pe((()=>{this.loading=!0,this.error=null}))}))}updateIndicationOnPlaying(){return ve((()=>this.state),(e=>{e===Wi.Playing&&pe((()=>{this.loading=!1,this.error=null}))}))}updateIndicationOnReconnecting(){return ve((()=>this.state),(e=>{e===Wi.Reconnecting&&pe((()=>{this.loading=!0}))}))}reactToStreamingError(){return ve((()=>this.streamingError),(e=>{if(!e)return;console.error(e);if("PLUGIN_INIT_ERROR"===e.name||"ERROR_PROCESSING_SDP"===e.name||"ICE_FAILED"===e.name||"SDP_OFFER_FAILED"===e.name||"CLOSE_PC"===e.name||"SDP_ANSWER_FAILED"===e.name)return console.warn("player",this.player.id,"cam",this.player.camera.id,"fallback to DVR"),this.error=new qi("STREAMING_ERROR",e.message,e),void this.setPlayerState(Wi.Stalled);pe((()=>{this.error=new qi("STREAMING_ERROR",e.message,e),this.state=Wi.Error}))}))}initTtff(){const e=Date.now();return at((()=>this.state),!0).pipe(d((e=>e===Wi.Playing)),u(1)).subscribe((()=>{this.ttff=Date.now()-e}))}initFromErrorToPlaying(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Error?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?this.streamingPlugin.stats?.framesDecoded:null)):r)),d(Boolean),u(1))))).subscribe((()=>{this.setPlayerState(Wi.Playing)}))}initFromInitialToPlaying(){return at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.stream),!0).pipe(c((e=>e?at((()=>this.streamingPlugin?.stats?.framesDecoded??null)):r)),d(Boolean),u(1))))).subscribe((()=>{this.setPlayerState(Wi.Playing)}))}initPauseAndResume(){return[at((()=>this.state),!0).pipe(d((e=>e===Wi.Playing||e===Wi.Paused))).subscribe((e=>{e===Wi.Playing?this.streamingPlugin?.resume():this.streamingPlugin?.pause()})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Playing?r:at((()=>this.player.paused)).pipe(d(Boolean))))).subscribe((()=>{this.setPlayerState(Wi.Paused)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Paused?r:at((()=>this.player.paused)).pipe(d((e=>!e)))))).subscribe((()=>{this.setPlayerState(Wi.Playing)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.Initial?r:at((()=>this.player.paused)).pipe(d((e=>e)))))).subscribe((()=>{this.streamingPlugin?.dispose(),this.loading=!1,this.setPlayerState(Wi.InitiallyPaused)})),at((()=>this.state),!0).pipe(c((e=>e!==Wi.InitiallyPaused?r:at((()=>this.player.paused)).pipe(d((e=>!e)))))).subscribe(this.transitionToInitialState)]}reactToCamera(){return ve((()=>({id:this.player.camera.id,url:this.player.camera.webRtcUrl,pin:this.player.camera.pin,isOnline:this.player.camera.isOnline,enabled:this.player.camera.enabled})),(({id:e,isOnline:t},i)=>{this.streamingPlugin&&this.streamingPlugin.dispose(),pe((()=>{t?this.player.paused&&e===i?.id?this.state=Wi.InitiallyPaused:this.transitionToInitialState():(this.error=new qi("CAMERA_OFFLINE_ERROR","Camera is offline"),this.state=Wi.Error,this.streamingPlugin=null)}))}),{fireImmediately:!0})}reactToStream(){return ve((()=>this.stream),(e=>{pe((()=>{if(!e){if(this.state===Wi.Reconnecting)return;return void(this.player.stream=null)}this.player.stream=e;const t=e.getVideoTracks();t&&0!==t.length||(console.warn("player",this.player.id,"cam",this.player.camera.id,"no video",t),this.error=new qi("NO_VIDEO_TRACK_ERROR","No video track"),this.state=Wi.Error)}))}))}initStats(){return ve((()=>this.streamingPlugin?this.streamingPlugin.stats:null),(e=>{this.player.stats=e}))}transitionToInitialState=()=>{const{webRtcUrl:e,id:t,pin:i}=this.player.camera;pe((()=>{this.streamingPlugin&&this.streamingPlugin.dispose(),this.streamingPlugin=new ts(e,t,i,this.options),this.state=Wi.Initial}))};dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.player.stream&&(this.player.stream=null),this.streamingPlugin&&this.streamingPlugin.dispose(),this.streamingPlugin=null,this.player.stats=null,this.player=null}}const rs=(()=>{let e=0;return()=>++e})();class ns{id=rs();disposables=[];liveChunk;currentTime=null;targetTime=null;chunk=null;paused=!1;error=null;get loading(){return this.behavior?.loading??!1}playbackRate=1;volume=1;muted=!0;videoResizeMode="fill";camera;stats=null;mode=null;behavior=null;transform=null;isRotating=!1;setTransform=(e,t=!1)=>{const{translate:{tx:i,ty:s},rotation:{angle:r},scale:{sx:n}}=De(e??Oe());this.isRotating=!1,this.animationController.start({scale:n,x:i,y:s,angle:r,immediate:!t})};resetTransform=()=>{this.isRotating=!1,this.setTransform(Oe())};animationController=new Ge({scale:1,x:0,y:0,angle:0,onChange:e=>{pe((()=>{if(this.isRotating){const t=this.transform??Oe(),{rotation:{angle:i}}=De(t);this.transform=_e(Ae(e.value.angle-i,this.width/2,this.height/2),t)}else this.transform=_e(ze(e.value.x,e.value.y),Fe(e.value.scale,e.value.scale),Ae(e.value.angle))}))}});width=0;height=0;chunkRequest=null;loopRange=null;loopRangeEnabled=!1;restoreFromDvrEnabled=!1;pendingBehavior=null;video;clip;startTime=null;endTime=null;stream=null;canSeek=!1;canSeek$;progress$;muted$;volume$;ended$;archivesStore;behaviors;seekTime;constructor({camera:e,startTime:t,endTime:i,clip:s,archivesStore:r,behaviors:n}){fe(this,{behavior:ue.ref,camera:ue.ref,chunk:ue.ref,chunkRequest:ue.ref,liveChunk:ue.ref,loopRange:ue.ref}),this.camera=e,this.startTime=t||null,this.endTime=i||null,this.clip=s,this.archivesStore=r,this.behaviors=n,s?(this.loopRange={start:s.startTime,end:s.endTime},this.loopRangeEnabled=!0):this.loopRange=null,this.disposables.push(ve((()=>this.behavior?.error),(()=>{this.error=this.behavior?.error??null})))}attach(e,{canSeek$:t,progress$:i,muted$:s,volume$:r,ended$:n}){this.video=e,this.canSeek$=t,this.progress$=i,this.ended$=n,this.muted$=s,this.volume$=r,this.reactToVolumeChange(),this.initPlayerBehavior(),this.seekAfterReady(),this.stopLoadingOnError(),this.initChunkRequest(),this.initLiveChunkUpdate(),this.initCurrentTime(),this.initSameChunkRequestFix(),this.setupLiveChunk(),this.replaceErrorMessageOnOffline(),this.disposables.push(this.canSeek$.subscribe((()=>{this.canSeek=!0}))),this.disposables.push(ve((()=>({camera:this.camera,startTime:this.startTime})),(({startTime:e})=>{pe((()=>{this.chunk&&this.chunk.cameraId!==this.camera.id&&(this.chunk=null,this.currentTime=null),this.chunkRequest=null,this.setupLiveChunk(),e?this.changeMedia({time:e}):this.goLive()}))}))),this.clip||this.startTime||this.mode||this.goLive(),!this.clip&&this.startTime&&this.changeMedia({time:this.startTime}),this.initPlayableRange(),this.initUpgradeToWebRtcWhenCameraIsBackOnline(),this.initUpgradeToWebRtcAfterFallbackToDvr(),this.initFallbackToDVR()}seek=e=>{"WebRTC"!==this.mode?this.behavior&&this.behavior.seek?this.behavior.seek(e):console.warn("incorrect call of seek"):console.warn("cannot seek in live mode")};seekAfterReady(){this.disposables.push(this.canSeek$.pipe(c((()=>f(t(null),this.progress$.pipe(u(1)))))).pipe(y((()=>this.seekTime)),d(Boolean)).subscribe((e=>{this.seekTime=null,this.seek(e)})))}stopLoadingOnError(){this.disposables.push(ve((()=>this.error),(e=>{e&&this.behavior&&(this.behavior.loading=!1)})))}replaceErrorMessageOnOffline(){this.disposables.push(at((()=>this.error),!0).pipe(c((e=>e?at((()=>this.camera.isOnline),!1).pipe(d((e=>!e))):r))).subscribe((()=>{this.error instanceof qi&&"CAMERA_OFFLINE_ERROR"===this.error.name||(this.error=new qi("CAMERA_OFFLINE_ERROR","camera is offline"))})))}changeMedia=({time:e,chunk:t,backward:i=!1})=>{if(this.restoreFromDvrEnabled=!1,this.targetTime=e??null,this.loopRange&&e>=this.loopRange.end&&(this.loopRangeEnabled=!1),this.loopRange&&e<this.loopRange.end&&(this.loopRangeEnabled=!0),!t&&this.chunk&&this.chunk.startTime<=e&&(this.chunk.endTime>=e||this.chunk.isLive)&&(t=this.chunk),!t)return this.chunkRequest={time:e,backward:i},this.canSeek=!1,void(this.mode="archive");if(t){if(this.chunkRequest=null,this.paused&&(this.paused=!1),"WebRTC"!==this.mode&&t===this.chunk&&this.canSeek)return this.seek(e);this.canSeek=!1,this.error=null,this.mode=t.isLive?"DVR":"archive",this.chunk=t,this.seekTime=e}};initCurrentTime(){this.disposables.push(this.progress$.pipe(d((()=>!this.seekTime&&!this.chunkRequest)),d((()=>!this.paused))).subscribe((()=>{if(!this.behavior)return;const e=this.behavior.getCurrentTime();e&&pe((()=>{this.behavior&&(this.behavior.loading=!1),this.error=null,this.currentTime=e,this.targetTime=null}))})))}initPlayableRange(){this.disposables.push(at((()=>({enabled:this.loopRangeEnabled,paused:this.paused,startTime:this.loopRange?.start,endTime:this.loopRange?.end})),!0).pipe(c((({enabled:e,paused:t,startTime:i,endTime:s})=>e&&!t&&s&&i?at((()=>this.currentTime),!0).pipe(b(),d((([e,t])=>null!==e&&null!==t&&e<s&&t>=s))):r))).subscribe((()=>{this.loopRange&&this.changeMedia({time:this.loopRange.start})})))}initSameChunkRequestFix(){this.disposables.push(this.progress$.pipe(d((()=>!this.chunkRequest&&!!this.seekTime&&!this.chunk?.isLive))).subscribe((()=>{this.seekTime&&this.chunk&&this.chunk.startTime<=this.seekTime&&this.chunk.endTime>=this.seekTime&&(this.seek(this.seekTime),this.seekTime=null)})))}initLiveChunkUpdate(){this.disposables.push(at((()=>this.liveChunk),!0).pipe(c((e=>e?R(250):r))).subscribe((()=>{pe((()=>{if("DVR"===this.mode&&this.behavior&&"function"==typeof this.behavior.getDateRange&&this.liveChunk){const e=this.behavior.getDateRange();if(!e)return;this.liveChunk.setBounds(e)}"DVR"!==this.mode&&this.liveChunk&&!this.liveChunk.managed&&this.liveChunk.setBounds([new Date(Date.now()-1e3*this.camera.raw.dvrWindowLength),new Date])}))})))}initChunkRequest(){this.disposables.push(at((()=>this.chunkRequest),!0).pipe(c((e=>{if(null===e)return r;const{time:i,backward:s}=e;if(this.clip?.isTimelapse&&this.clip.archives){const{archives:e}=this.clip,r=e.find((e=>e.startTime<=i&&e.endTime>=i));if(r)return t({chunk:r,time:i,backward:s});if(s){const r=e.find((e=>e.endTime<i));return t(r?{chunk:r,time:i,backward:s}:{chunk:null,time:i,backward:s})}const n=e.find((e=>e.startTime>i));return t(n?{chunk:n,time:i,backward:s}:{chunk:null,time:i,backward:s})}const n=this.camera.id,a=this.archivesStore.getChunks({cameraId:this.camera.id,from:i,to:i})[0];if(a)return t({chunk:a,time:i,backward:s});return(s?this.archivesStore.fetchPrevChunk({cameraId:n,time:i}):this.archivesStore.fetchNextChunk({cameraId:n,time:i})).pipe(y((e=>e?s?i<=e.endTime?{chunk:e,time:i,backward:s}:{chunk:e,time:new Date(+e.endTime-5e3),backward:s}:{chunk:e,time:new Date(Math.max(+e.startTime,+i)),backward:s}:this.liveChunk&&this.liveChunk.startTime<i?{chunk:this.liveChunk,time:i,backward:s}:{chunk:null,time:i,backward:s})))}))).subscribe((({chunk:e,time:t,backward:i})=>{pe((()=>{if(!e){if(i||!this.liveChunk)return void(this.chunkRequest=null);e=this.liveChunk}this.currentTime=e.startTime,this.changeMedia({chunk:e,time:t})}))})))}setupLiveChunk(){const{camera:e}=this;e.streamUrl&&e.raw.dvrWindowLength?this.liveChunk?.cameraId!==e.id&&pe((()=>{this.liveChunk=new ct({cameraId:e.id,endTime:new Date,startTime:new Date(Date.now()-e.dvrWindowLength),streamUrl:e.streamUrl,dashStreamUrl:e.dashStreamUrl,length:e.dvrWindowLength})})):this.liveChunk=null}initPlayerBehavior(){this.disposables.push(at((()=>this.mode),!0).pipe(C((async e=>{if(this.behavior){const e=this.behavior;pe((()=>{this.behavior=null})),await e.dispose()}return e}))).subscribe((e=>{e&&pe((()=>{if("WebRTC"===e&&this.pendingBehavior)return this.behavior=this.pendingBehavior,void(this.pendingBehavior=null);const t=this.behaviors[e];this.behavior=t?t(this):null}))})))}seekBackward=e=>{if(!this.currentTime&&this.targetTime)return;!this.currentTime&&this.behavior?.live&&this.changeMedia({time:new Date(Date.now()-e),backward:!0});const t=this.targetTime||this.currentTime;if(!t)return;const i=new Date(+t-e);this.changeMedia({time:i,backward:!0})};seekForward=e=>{if(!this.currentTime&&this.targetTime)return;const t=this.targetTime||this.currentTime;if(!t)return;const i=new Date(+t+e);this.liveChunk&&i>this.liveChunk.endTime?this.goLive():this.changeMedia({time:i,backward:!1})};goLive=()=>{this.seekTime=null,this.playbackRate=1,this.paused=!1,this.behaviors.WebRTC?this.mode="WebRTC":"DVR"===this.mode?this.behavior?.goLive?.():(this.mode="DVR",this.chunk=this.liveChunk||null)};setCamera=e=>{this.camera=e};setCameraAndStartTime=(e,t)=>{this.camera=e,this.startTime=t};toggleResizeMode=()=>{"contain"!==this.videoResizeMode?this.videoResizeMode="contain":this.videoResizeMode="fill"};setVideoResizeMode=e=>{this.videoResizeMode=e};toggleMute=()=>{this.muted=!this.muted};setStartTime=e=>{this.startTime=e};setVolume=e=>{this.volume=e};setPlaybackRate=e=>{this.playbackRate=e};reactToVolumeChange(){this.disposables.push(this.volume$.subscribe(this.setVolume))}togglePlayback=()=>{this.paused=!this.paused};play=()=>{this.paused=!1};pause=()=>{this.paused=!0};detach=()=>{this.behavior&&(this.behavior.dispose(),this.behavior=null);for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e();this.video=null};initUpgradeToWebRtcWhenCameraIsBackOnline(){this.behaviors.WebRTC&&this.disposables.push(at((()=>!this.paused&&"DVR"===this.mode&&this.behavior?.live),!0).pipe(c((e=>e?at((()=>this.camera.isOnline)).pipe(c((e=>e?(this.goLive(),r):r))):r))).subscribe())}initFallbackToDVR=()=>{this.disposables.push(at((()=>this.behavior),!0).pipe(c((e=>"WebRTC"===this.mode&&e?at((()=>e.state),!0).pipe(d((e=>e===Wi.Stalled||e===Wi.Failed))):r))).subscribe((e=>{pe((()=>{this.seekTime=null,this.mode="DVR",this.chunk=this.liveChunk||null,this.restoreFromDvrEnabled=e!==Wi.Failed}))})))};initUpgradeToWebRtcAfterFallbackToDvr(){if(!this.behaviors.WebRTC)return;let e=null;this.disposables.push(at((()=>({enabled:this.restoreFromDvrEnabled,mode:this.mode,paused:this.paused}))).pipe(c((({mode:i,enabled:s,paused:n})=>"DVR"!==i||!s||n?(e&&(e.dispose(),e=null),r):t(null).pipe(w(1e4),c((()=>{if(!this.behaviors.WebRTC)return r;e&&(e.dispose(),e=null),e=this.behaviors.WebRTC(this);const i=e;return at((()=>i.state),!0).pipe(v((()=>{const{state:s}=i;if(!s)return r;if(s===Wi.Playing)return t(s);if([Wi.Error,Wi.Failed,Wi.Stalled].includes(s)){i.dispose(),e=null;const t=i.error;return p((()=>new Error(s,{cause:t})))}return r})),u(1))})),et({initialInterval:1e4,maxInterval:8e4,shouldRetry:e=>!(e instanceof Error&&e.message===Wi.Failed)}))))).subscribe({next:()=>{pe((()=>{this.seekTime=null,this.playbackRate=1,this.paused=!1,this.pendingBehavior=e,e=null,this.mode="WebRTC",this.restoreFromDvrEnabled=!1}))},error:t=>{console.error("Failed to upgrade to WebRTC after fallback to DVR",t),pe((()=>{e=null,this.restoreFromDvrEnabled=!1}))}}))}}class as{disposables=[];constructor(e,t){const i=f(a(e,"play").pipe(xe(!1)),a(e,"pause").pipe(xe(!0))),s=a(e,"volumechange").pipe(Se((()=>e.volume)),Ie()),n=a(e,"timeupdate"),o=f(a(e,ht?"loadeddata":"loadedmetadata"),a(e,"playing")),l=a(e,"ended"),c=a(e,"volumechange").pipe(Se((()=>e.muted)),Ie());t.attach(e,{canSeek$:o,ended$:l,progress$:n,volume$:s,muted$:c}),this.disposables.push(ve((()=>t.stream),(t=>{e.srcObject=t}))),this.disposables.push(ve((()=>t.volume),(t=>{e.volume=t}))),this.disposables.push(ve((()=>t.playbackRate),(t=>{e.playbackRate=t}))),this.disposables.push(a(e,"canplay").subscribe((()=>{e.playbackRate!==t.playbackRate&&(e.playbackRate=t.playbackRate)}))),this.disposables.push(a(e,"error").subscribe((()=>{e.error&&(console.error(e.error),t.error=new qi("MEDIA_ERROR",e.error.message,e.error))}))),this.disposables.push(a(e,"seeking").subscribe((()=>{pe((()=>{t.behavior&&(t.behavior.loading=!0)}))}))),this.disposables.push(a(e,"pause").subscribe((()=>{pe((()=>{t.behavior&&(t.behavior.loading=!1)}))})));const d=new T;let h=!1;this.disposables.push(f(at((()=>t.paused)),d).pipe(Ee((t=>(h=t,t&&e.paused||!t&&!e.paused?r:t?(e.pause(),r):e.play().catch((e=>console.error(e))))))).subscribe((e=>{e!==h&&d.next(e)}))),this.disposables.push(i.subscribe((e=>{(e&&!t.paused||!e&&t.paused)&&d.next(t.paused)}))),this.disposables.push(a(e,"seeked").subscribe((()=>{t.paused||d.next(!1)})))}dispose(){for(const e of this.disposables)e instanceof o?e.closed||e.unsubscribe():e()}}const os=B((()=>{const e=z(ki),t=z(rt),{utc:i,hour12:s}=t?.account.preferences??{utc:!1,hour12:!1},r=Q((()=>{const e=new Intl.DateTimeFormat(st.language,{timeStyle:"medium",timeZone:i?"UTC":void 0,hour12:s||void 0,hourCycle:s?void 0:"h23"}),t=new Intl.DateTimeFormat(st.language,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZone:i?"UTC":void 0,hour12:s||void 0,hourCycle:s?void 0:"h23"});return s=>((e,t,i)=>i?e.getUTCFullYear()===t.getUTCFullYear()&&e.getUTCMonth()===t.getUTCMonth()&&e.getUTCDate()===t.getUTCDate():e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate())(s,new Date,i)?e.format(s):t.format(s)}),[i,s]);return t&&"activeLayoutView"in t?e.behavior&&e.behavior instanceof ss?null:P("div",{className:W("x-3deye-player__current-time",{"x-3deye-player__current-time--synced":t.activeLayoutView?.synced?.players.includes(e)}),children:e.currentTime&&r(e.currentTime)}):null}));os.displayName="CurrentTimeIndicator";var ls=os;const cs=e=>{const t=Math.floor(e)%60;return`- ${(Math.floor(e)-t)/60}:${t<10?`0${t}`:t}`},ds=B((()=>{const e=z(ki);if(e.endTime)return null;if(!e.camera.isOnline)return null;if(e.error)return null;if(e.behavior?.live&&e.behavior.delay&&e.behavior.delay>1)return P(vt,{className:"x-3deye-delay-indicator",style:{pointerEvents:"auto"},onClick:e.behavior.goLive,children:cs(e.behavior.delay)});return!e.paused&&(e.behavior&&e.behavior instanceof ss)?P("div",{className:"x-3deye-live-indicator",children:st.t("playerTools.live")}):P(vt,{style:{pointerEvents:"auto"},className:"x-3deye-button--live",onClick:e.goLive,tabIndex:-1,children:st.t("playerTools.goLive")})}));ds.displayName="LiveIndicator";var hs=ds;const us=B((()=>{const e=E(null),t=z(ki),i=E(!1);return A((()=>{const t=e.current;if(!t)return;const i=()=>{t.style.display="none"};return t.addEventListener("animationend",i),()=>{t.removeEventListener("animationend",i)}}),[]),A((()=>{e.current&&(i.current?e.current.style.display="block":i.current=!0)})),P("div",{ref:e,className:"x-3deye-player__playback-indicator",children:t.paused?P(xt,{size:32,color:"rgba(255, 255, 255, 0.8)"}):P(Et,{size:32,color:"rgba(255, 255, 255, 0.8)"})})}));us.displayName="PlaybackIndicator";var ms=us;const ps=B((()=>{const e=z(ki);if(!e.error)return null;const t=e.error?"CONNECTION_TIMEOUT_ERROR"===e.error.name?st.t("player.playbackTimeoutError",{count:e.error.cause.count}):"CAMERA_OFFLINE_ERROR"===e.error.name?e.camera.enabled?st.t("player.cameraIsOffline"):st.t("player.cameraIsDisabled"):"NO_PLAYABLE_STREAM_ERROR"===e.error.name?st.t("player.noPlayableStream"):"NO_VIDEO_TRACK_ERROR"===e.error.name?st.t("player.noVideoTrack"):st.t("player.genericError"):null;return P("div",{style:{position:"absolute",top:0,left:0,bottom:0,right:0,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"none"},children:P("span",{style:{backgroundColor:"rgba(0, 0, 0, 0.5)",padding:"8px 16px",fontSize:12},children:t})})}));function vs(e,t,i){return t<i?Math.max(Math.min(e,i),t):Math.max(Math.min(e,t),i)}function gs(e,t,i){e=Ue(e);const s=Be(e,[[0,0],[0,i],[t,0],[t,i]]),r=Math.min(...s.map((e=>e[0]))),n=Math.max(...s.map((e=>e[0]))),a=Math.min(...s.map((e=>e[1]))),o=Math.max(...s.map((e=>e[1]))),{scale:{sx:l},rotation:{angle:c}}=De(e);if(c<0)if(c>-Math.PI/2){const s=-Math.sin(c)*l*t;e.e=vs(e.e,t+r-n,0),e.f=vs(e.f,s-o+a+i,s)}else{const s=-Math.cos(c)*l*t;e.e=vs(e.e,s,t+r-n+s),e.f=vs(e.f,i,o-a)}if(c>0)if(c<Math.PI/2){const s=Math.sin(c)*l*i;e.e=vs(e.e,s-n+r+t,s),e.f=vs(e.f,i+a-o,0)}else{const s=-Math.cos(c)*l*i;e.e=vs(e.e,t,n-r),e.f=vs(e.f,i+a-o+s,s)}return 0===c&&(e.e=vs(e.e,(1-l)*t,0),e.f=vs(e.f,(1-l)*i,0)),e}const fs=B((({hideCameraTitle:e,width:t,height:i,onDoubleClick:s,onAuxClick:r,onMouseDown:n,children:a})=>{const o=z(ki),l=x.useRef(null),c=x.useRef(null),d=`zoom-slider-${o.id}`,h=200,u=136,m=()=>{const e=o.transform??Oe();if(!c.current)return;const t=c.current.querySelector(".x-3deye-player__zoomable");if(!t)return;t.style.transformOrigin="0 0";const{scale:{sx:i},translate:{tx:s,ty:r},rotation:{angle:n}}=De(e);if(0===n){const e=1/i,n=-s/(o.width/h)*e,a=-r/(o.height/u)*e;return void(t.style.transform=$e(_e(ze(n,a),Fe(e))))}const{width:a,height:l}=o,d=Be(e,[[0,0],[0,l],[a,0],[a,l]]),m=Math.min(...d.map((([e])=>e))),p=Math.max(...d.map((([e])=>e))),v=Math.min(...d.map((([e,t])=>t))),g=Math.max(...d.map((([e,t])=>t)));let f=0,y=0,b=1,R=[0,1],C=[0,1];if(n<0&&n>-Math.PI/2){const s=-Math.sin(n)*i*a;b=a/(a+Math.abs(a+m-p)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([0,a+m-p],R)(e.e),y=qe([s,s-g+v+l],C)(e.f),t.dataset.factorX=((a+m-p)/(R[1]-R[0])).toString(),t.dataset.factorY=((-g+v+l)/(C[1]-C[0])).toString()}if(n<0&&n<-Math.PI/2){const s=-Math.cos(n)*i*a;b=a/(a+Math.abs(a+m-p)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([s,a+m-p+s],R)(e.e),y=qe([g-v,l],C)(e.f),t.dataset.factorX=((a+m-p)/(R[1]-R[0])).toString(),t.dataset.factorY=((l-g+v)/(C[1]-C[0])).toString()}if(n>0&&n<Math.PI/2){const s=Math.sin(n)*i*l;b=l/(l+Math.abs(l+v-g)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([s,s-p+m+a],R)(e.e),y=qe([0,l+v-g],C)(e.f),t.dataset.factorX=((-p+m+a)/(R[1]-R[0])).toString(),t.dataset.factorY=((l+v-g)/(C[1]-C[0])).toString()}if(n>0&&n>Math.PI/2){const s=-Math.cos(n)*i*l;b=l/(l+Math.abs(l+v-g)),R=[0,h*(1-b)],C=[0,u*(1-b)],f=qe([p-m,a],R)(e.e),y=qe([s,l+v-g+s],C)(e.f),t.dataset.factorX=((a-p+m)/(R[1]-R[0])).toString(),t.dataset.factorY=((l+v-g)/(C[1]-C[0])).toString()}t.style.transform=$e(_e(ze(f,y),Fe(b)))};A((()=>ve((()=>({width:o.width,height:o.height})),(({width:e,height:t},{width:i,height:s})=>{if(!e||!t)return;if(!i||!s)return;if(i===e&&s===t)return;const r=o.transform??Oe(),{scale:n}=De(r);if(1===n.sx)return;const a=Qe(r),l=Ve(a,{x:i/2,y:s/2}),c=Ve(r,{x:l.x/i*e,y:l.y/s*t}),d=_e(ze(e/2-c.x,t/2-c.y),r);o.setTransform(d),m()}))),[]),je({onMouseDown:({event:e})=>{n(e)},onDrag:({movement:e,last:s,altKey:r,first:n,xy:a,memo:c,pinching:d,cancel:h})=>{if(d)return void h();const u=n?o.transform??Oe():c.matrix;if(r&&n){const{top:e,left:s}=l.current.getBoundingClientRect(),{rotation:{angle:r}}=De(u);return{startAngle:Math.atan2(a[1]-(e+i/2),a[0]-(s+t/2))-r,matrix:u}}if(void 0!==c?.startAngle){const{top:e,left:s}=l.current.getBoundingClientRect(),{rotation:{angle:r}}=De(u),n=Math.atan2(a[1]-(e+i/2),a[0]-(s+t/2)),d=_e(Ae(n-c.startAngle-r,t/2,i/2),u);return void o.setTransform(d)}const m=gs(_e(ze(...e),u),t,i);return o.setTransform(m),{matrix:u}},onPinch:({first:e,last:t,da:i,origin:s,memo:r})=>{if(t)return;const[n,a]=i;let[c,d]=s;const{top:h,left:u}=l.current.getBoundingClientRect();c-=u,d-=h;const m={x:c+n/2*Math.sin(a*Math.PI/180),y:d-n/2*Math.cos(a*Math.PI/180)},p={x:c-n/2*Math.sin(a*Math.PI/180),y:d+n/2*Math.cos(a*Math.PI/180)};if(e){return{prevP1:m,prevP2:p,prevMatrix:o.transform??Oe()}}const{prevP1:v,prevP2:g,prevMatrix:f}=r,y=He(v,g,m,p),b=_e(y,f);return o.setTransform(b),{prevP1:m,prevP2:p,prevMatrix:b}},onWheel:({last:e,event:s,memo:r})=>{if(e)return;const n=r??o.transform??Oe(),{top:a,left:c}=l.current.getBoundingClientRect(),d=s.clientX-c,h=s.clientY-a;let u=2**function(e){return-e.deltaY*(1===e.deltaMode?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}(s);const m=Math.sqrt(n.a**2+n.b**2);u*m<1&&(u=1/m),u*m>4&&(u=4/m);const p=gs(_e(Fe(u,u,d,h),n),t,i);return o.setTransform(p,!0),p}},{target:l,pinch:{pinchOnWheel:!1,scaleBounds:{min:.5,max:2}},wheel:{eventOptions:{passive:!1},preventDefault:!0}}),A((()=>ve((()=>o.transform),m)),[]);const p=We((({movement:e,first:t,memo:i,target:s})=>{if(t){const{rotation:{angle:e}}=De(o.transform??Oe());return{matrix:o.transform,angle:e}}const{matrix:r,angle:n}=i,a=gs(n?_e(ze(e[0]*+s.dataset.factorX,e[1]*+s.dataset.factorY),r):_e(r,ze(-e[0]*o.width/h,-e[1]*o.height/u)),o.width,o.height);return o.setTransform(a),{matrix:r,angle:n}})),{scale:{sx:v},rotation:{angle:g}}=De(o.transform??Oe());return S(M,{children:[S("div",{className:"x-3deye-player__overlay",children:[P("div",{ref:l,style:{position:"absolute",touchAction:"none",top:0,bottom:0,left:0,right:0},onDoubleClick:s||k,onAuxClick:r}),P(ms,{}),S("div",{className:"x-3deye-player__indicators",children:[e?null:P(ji,{}),P("div",{style:{flex:1}}),P(hs,{}),P(ls,{})]}),o.loading&&P(Gt,{style:{pointerEvents:"none",position:"absolute",top:"calc(50% - 33px)",left:"calc(50% - 33px)"}}),P(ps,{}),a]}),P(M,{children:S("div",{id:d,className:"x-3deye-player__zoom-slider",style:{color:"#fff8",display:1!==v||0!==g?"flex":"none",gap:8},children:[S("div",{ref:c,className:"x-3deye-player__zoom-preview",style:{width:204,height:140},tabIndex:-1,children:[P("div",{className:"zoom-value",children:`${v.toPrecision(3)}x`}),P("div",{className:"x-3deye-player__zoomable",...p(),style:{touchAction:"none"}})]}),P("div",{style:{height:136,paddingBlock:8,paddingLeft:8,marginLeft:-8},children:P(Yt,{orientation:"vertical",value:(v-1)/3*100,onChange:e=>{const t=1+e/100*3,i=o.transform??Oe(),s=o.width/2,r=o.height/2,n=Math.sqrt(i.a**2+i.b**2),a=gs(_e(Fe(t/n,t/n,s,r),i),o.width,o.height);o.setTransform(a)},labelFormat:null})}),S("div",{style:{paddingBottom:20,width:32,marginRight:-8},children:[P(ei,{angle:g,onChange:e=>{const s=o.transform??Oe(),{rotation:{angle:r}}=De(s),n=_e(Ae(e-r,t/2,i/2),s);o.setTransform(n)}}),S(vt,{disabled:!g,title:g?st.t("playerTools.resetRotation"):null,style:{position:"absolute",color:"currentColor",right:4,bottom:2,fontFamily:"Roboto Mono, monospace",letterSpacing:"-0.1em",paddingInline:0,paddingBlock:2,height:"fit-content",fontSize:"0.75rem"},onMouseDown:()=>{const e=o.transform??Oe(),{rotation:{angle:s}}=De(e),r=_e(Ae(-s,t/2,i/2),e),n=gs(r,t,i);o.setTransform(n,!0),o.isRotating=Math.abs(r.e-n.e)<1e-6&&Math.abs(r.f-n.f)<1e-6},children:[(180*g/Math.PI).toFixed(1),"°"]})]})]})})]})}));fs.displayName="PlayerOverlay";var ys=fs;const bs=60,Rs=B((({cameraId:e,disabled:t})=>{const i=z(rt),s=$((()=>({x:0,y:0,update(e,t){this.x=e,this.y=t}})));A((()=>{const t=at((()=>({x:s.x,y:s.y}))).pipe(Ie(((e,t)=>Math.round(100*e.x)===Math.round(t.x)&&Math.round(100*e.y)===Math.round(t.y))),Le(100),be((t=>t.x||t.y?i.api.cameras.MoveCameraContinuousStart({id:e},Math.round(100*t.x),Math.round(100*t.y),0,30):i.api.cameras.MoveCameraContinuousStop({id:e})))).subscribe();return()=>t.unsubscribe()}),[]);const[{x:r,y:n},a]=Je((()=>({x:0,y:0,config:Xe.wobbly}))),o=We((({down:e,movement:[t,i]})=>{if(t*t+i*i>bs*bs){const e=Math.sqrt(t*t+i*i);t=t/e*bs,i=i/e*bs}e?s.update(t/bs,-i/bs):s.update(0,0),a.start({x:e?t:0,y:e?i:0,immediate:e})}),{enabled:!t,pointer:{capture:!1}});return S("div",{style:{display:"grid",placeItems:"center",position:"relative",flex:1},children:[P("div",{style:{gridRow:"1 / 1",gridColumn:"1 / 1",width:120,height:120,borderRadius:"50%",background:"rgba(255, 255, 255, 0.25)"}}),P(Ke.div,{...o(),style:{x:r,y:n,width:50,height:50,background:"rgb(255 255 255 / 0.5)",touchAction:"none",borderRadius:"50%",gridRow:"1 / 1",gridColumn:"1 / 1"}})]})}));Rs.displayName="ContinuousPtzControls";var Cs=Rs;const ws=B((({cameraId:e,disabled:t})=>{const{api:i}=z(rt);return P(vt,{disabled:t,className:"x-3deye-button--icon",style:{width:36,height:36},title:st.t("ptzControl.moveCameraHome"),onPointerDown:()=>i.cameras.GoHomePtzCamera({id:e}).subscribe(),children:P(St,{})})}));ws.displayName="GoHome";var Ts=ws;const ks=Ze().domain([1,100]).range([0,100]),Ps=B((({movementSpeed:e,setMovementSpeed:t,disallowGoHome:i=!1,disabled:s,cameraId:r})=>{const{api:n}=z(rt),a=Math.floor(ks.invert(e));return S("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr) 24px",flex:1},children:[i?P("div",{style:{gridRow:2,gridColumn:2}}):P(vt,{disabled:s,onPointerDown:()=>n.cameras.GoHomePtzCamera({id:r}).subscribe(),className:"x-3deye-button--icon",style:{gridRow:2,gridColumn:2,justifySelf:"center",alignSelf:"center",width:36,height:36},title:st.t("ptzControl.moveCameraHome"),children:P(St,{size:24})}),Array.from(Array(8),((e,t)=>{const i=[0,1,2,7,3,6,5,4][t],o=t<3?0:t<5?1:2,l=t<4?t%3:(t+1)%3,c=i%2?[0,0]:[-1*(l-1),-1*(o-1)],d=`rotate(${45*i-135}deg)`,h=(l-1)*a,u=(o-1)*-a;return P(vt,{disabled:s,onPointerDown:()=>n.cameras.MoveCamera({id:r},h,u,0,0,0).subscribe(),className:"x-3deye-button--icon",style:{transform:`translate(${10*c[0]}px, ${10*c[1]}px)`,justifySelf:"center",alignSelf:"center",width:36,height:36},children:P(Et,{style:{transform:d},size:i%2?24:16})},t)})),S("div",{style:{gridColumn:"4",gridRow:"1 / span 3",position:"relative"},children:[P("div",{style:{position:"absolute",top:0,bottom:0,left:0,aspectRatio:"1/1",display:"flex",flexDirection:"column"},children:P(Yt,{orientation:"vertical",style:{flex:1,marginTop:10,marginBottom:10},disabled:s,value:e,onChange:t,labelFormat:e=>`${e}%`})}),P(Xt,{label:st.t("ptzControl.movementSpeed"),children:P("div",{style:{width:24,height:24,position:"absolute",bottom:-24,left:0},children:P(At,{})})})]})]})}));Ps.displayName="RelativePtzControls";var Ss=Ps;const Ms=B((({cameraId:e,disabled:t})=>{const{api:i,notification:s}=z(rt);return P(vt,{disabled:t,className:"x-3deye-button--icon",style:{width:36,height:36},title:st.t("ptzControl.setHome"),onClick:async()=>{confirm(st.t("ptzControls.confirmSetHomePosition"))&&i.cameras.SetHomePtzCamera({id:e}).subscribe((e=>{e.success?s.success(st.t("ptzControls.cameraPtzHomeSet")):(s.error(st.t("ptzControls.errorWhileUpdatingHomePositionDescription")),console.error(e.error))}))},children:P(kt,{})})}));Ms.displayName="SetHome";var xs=Ms;const Is=Ze().domain([1,100]).range([0,100]),Es=B((({cameraId:e,style:t,disabled:i,initialZoomSpeed:s=50,initialMovementSpeed:r=50,disallowHomePositionUpdate:n=!1,disallowGoHome:a=!1})=>{const{api:o}=z(rt),[l,c]=O(Ls.Relative),[d,h]=O(s),[u,m]=O(r),p=Math.floor(Is.invert(d));return S("div",{style:{display:"flex",flexDirection:"column",...t},children:[S("div",{style:{display:"flex",justifyContent:"space-between"},children:[P(vt,{disabled:i,onPointerDown:()=>o.cameras.MoveCamera({id:e},0,0,-p,0,0).subscribe(),className:"x-3deye-button--icon",style:{gridColumn:"1/1",justifySelf:"start"},children:P(Vt,{size:24})}),P(vt,{disabled:i,onPointerDown:()=>o.cameras.MoveCamera({id:e},0,0,p,0,0).subscribe(),className:"x-3deye-button--icon",style:{gridColumn:"2/3",justifySelf:"end"},children:P(Ft,{size:24})})]}),S("div",{style:{display:"flex",alignItems:"center"},children:[P(Xt,{label:st.t("ptzControl.zoomSpeed"),children:P("div",{children:P(At,{})})}),P(Yt,{style:{flex:1,marginLeft:10,marginRight:10},disabled:i,value:d,onChange:h,labelFormat:e=>`${e}%`}),P(Nt,{})]}),l===Ls.Relative?P(Ss,{cameraId:e,disabled:i,movementSpeed:u,setMovementSpeed:m,disallowGoHome:a}):P(Cs,{cameraId:e,disabled:i}),S("div",{style:{display:"flex",justifyContent:"space-between"},children:[n?P("div",{style:{width:24,height:24}}):P(xs,{cameraId:e,disabled:i}),l===Ls.Continuous&&!a&&P(Ts,{cameraId:e,disabled:i})]}),S(Wt,{value:l,onChange:c,children:[P(qt,{value:Ls.Relative,children:st.t("ptzControl.relative")}),P(qt,{value:Ls.Continuous,children:st.t("ptzControl.continuous")})]})]})}));var Ls;!function(e){e[e.Relative=0]="Relative",e[e.Continuous=1]="Continuous"}(Ls||(Ls={}));const Ns=B((({onRequestClose:e,fullscreenControl:t})=>S(Hi,{children:[P(Si,{}),P(Ai,{}),P(Ii,{}),P(Li,{}),P(Hi.Spacer,{}),P(Di,{}),t,P(Ci,{onClick:e})]})));Ns.displayName="ToolkitPlayerControls";var Ds=Ns;const Os=B((e=>{const t=z(H)??U;return P(rt.Provider,{value:t,children:P(Es,{...e})})}));Os.displayName="PtzControls";var _s=Os;const As=new URLSearchParams(location.search.toLowerCase()),zs=As.has("dash")||As.has("dvr"),Fs=B(x.forwardRef((({id:e,archivesStore:t,startTime:i,endTime:s,clip:r,camera:n,webRtcOptions:a,className:o,controls:l,onDoubleClick:c,onMouseDown:d,onAuxClick:h,hideCameraTitle:u,controllerRef:m,videoRef:p,...v},g)=>{const f=E(null),[y,b]=O(0),R=E(null),C=E(null),[w,T]=O((()=>new WeakRef(n))),k=E(null),[M]=O((()=>new ns({camera:n,startTime:i,endTime:s,clip:r,archivesStore:t,behaviors:{archive:e=>new Ji(e,R.current),DVR:e=>ae.isSupported()?new Yi(e,zs,R.current):new Gi(e,R.current),WebRTC:zs||!1===a?.enabled?null:e=>new ss(e,a)}})));V(m,(()=>M),[]),A((()=>{C.current=new as(R.current,M);const e=ht?at((()=>M.mode),!0).pipe(Ne()).subscribe((([e])=>{"WebRTC"===e&&(k.current={restoreAt:M.seekTime},M.detach(),b((e=>e+1)))})):void 0;return()=>{e?.unsubscribe(),C.current?.dispose(),C.current=null,M.detach()}}),[]);const{muted:x,paused:I}=M;A((()=>{k.current&&(C.current.dispose(),k.current.restoreAt&&M.setStartTime(k.current.restoreAt),C.current=new as(R.current,M),k.current=null)}),[y]),A((()=>{const e=new ye((e=>{for(const t of e){const e=t.contentRect.width,i=t.contentRect.height;pe((()=>{M.width=e,M.height=i}))}}));return e.observe(f.current),()=>{e.disconnect()}}),[]),A((()=>{if(w.deref()!==n)return M.setCameraAndStartTime(n,i||null),M.resetTransform(),void T(new WeakRef(n));M.setStartTime(i||null)}),[n,+(i||0)]);const N=L((e=>{e.currentTarget===e.target&&0===e.button&&d&&d(e)}),[d]);return S("div",{ref:ne(f,g),id:e||`player-${M.id}`,className:W(o,"x-3deye-player",{"x-3deye-player--paused":I}),...v,children:[P("div",{className:"x-3deye-player__zoomable-wrapper",children:P("div",{className:"x-3deye-player__zoomable",style:{transformOrigin:"0 0",transform:M.transform?$e(M.transform):void 0},children:P("video",{autoPlay:!0,crossOrigin:"anonymous",playsInline:!0,ref:ne(R,p),muted:x,style:(e=>{if("archive"!==M.mode||!ht||"fill"!==e.objectFit)return e;let t=1,i=1;const{width:s,height:r}=M,n=M.camera.raw.width||R.current?.videoWidth,a=M.camera.raw.height||R.current?.videoHeight;if(!(n&&a&&s&&r))return e;const o=n/a;s/r>o?(t=s/(r*o),i=1):(t=1,i=r/(s/o));const{objectFit:l,...c}=e;return{...c,objectFit:"contain",scale:`${t} ${i}`}})({objectFit:M.videoResizeMode})},y)})}),P(ki.Provider,{value:M,children:P(ys,{onDoubleClick:c,onAuxClick:h,onMouseDown:N,width:M.width,height:M.height,hideCameraTitle:u,children:l})})]})})));Fs.displayName="Player";const Qs=B(x.forwardRef(((e,t)=>{const i=z(H)??U,{ref:s,toggle:r,active:n,enabled:a}=ti(),{cameraId:o,startTime:l,onDoubleClick:c,onMouseDown:d,onRequestClose:h,playerRef:u,controls:m=P(Ds,{fullscreenControl:a?P(Ti,{active:n,toggle:r}):void 0,onRequestClose:h}),webRtcOptions:p={enabled:!0},...v}=e;if(!i.cameras.loaded)return P("div",{ref:t,...v});const g=o?i.cameras.camerasById.get(o):null;if(!g)return console.warn("can't render player for unknown camera"),P("div",{ref:t,...v});const f={hideCameraTitle:!0,camera:g,controls:m,onDoubleClick:c,onMouseDown:d,startTime:l,controllerRef:u,...v},y=ne(t,ht?void 0:s),b=ht?s:void 0;return P(rt.Provider,{value:i,children:P(Fs,{ref:y,videoRef:b,archivesStore:i.archives,webRtcOptions:p,...f})})})));Qs.displayName="CameraPlayer";var Vs=Qs;function Hs(){const[e,t]=O(null);return{playerRef:L((e=>{t(e??null)}),[]),player:e}}const Us=e=>e.stopPropagation(),Bs=B((e=>{const t=E(null),i=$((()=>({current:null}))),s=$((()=>({dragging:!1}))),r=E(new T),n=L((e=>{e.persist(),e.stopPropagation(),r.current.next(e)}),[]),o=me((()=>{i.current=null,e.onRequestCancel()})),l=me((()=>{i.current=null,e.onClose()}));return A((()=>{const n=r.current.pipe(Me((r=>{const n=r.clientX,o=r.clientY;s.dragging=!0;const{top:l,left:c}=t.current.getBoundingClientRect();return a(document,"mousemove").pipe(Se((t=>{const i=n-c,s=o-l,r=t.clientX-n,a=t.clientY-o,d=(a>=0?s:s+a)/e.height,h=(r>=0?i:i+r)/e.width,u=d+Math.abs(a)/e.height,m=h+Math.abs(r)/e.width;return{top:ut(d,0,1),left:ut(h,0,1),bottom:ut(u,0,1),right:ut(m,0,1)}})),ke(a(document,"mouseup").pipe(Re((()=>{if(s.dragging=!1,!i.current)return;const t=(i.current.bottom-i.current.top)*(i.current.right-i.current.left);e.width*e.height*t<100?i.current=null:e.onSelect({Top:i.current.top,Left:i.current.left,Bottom:i.current.bottom,Right:i.current.right})})))))}))).subscribe((e=>{e&&(i.current=e)}));return()=>n.unsubscribe()}),[e.width,e.height]),A((()=>{if(i.current)return;const e=e=>{const t=e.target;/^(input|select|textarea)$/i.test(t.tagName)||"Escape"===e.code&&l()};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}}),[null===i.current]),P("div",{ref:t,onMouseDown:n,style:{position:"absolute",top:0,left:0,width:e.width,height:e.height,display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column"},children:i.current?P("div",{className:"box-selector",style:{position:"absolute",top:100*i.current.top+"%",left:100*i.current.left+"%",bottom:100*(1-i.current.bottom)+"%",right:100*(1-i.current.right)+"%"},children:s.dragging?null:P(vt,{className:"box-selector-close",onMouseDown:Us,onClick:l,style:{position:"absolute",top:-10,right:-10,padding:2,width:20,height:20,borderRadius:10},children:P(Rt,{size:16})})}):S("div",{className:"box-selector-select",children:[P("div",{children:st.t("selectArea")}),P("div",{className:"box-selector-preview",children:P("div",{className:"box-selector",children:P(wt,{size:16})})}),P(vt,{className:"box-selector-cancel",onClick:o,children:st.t("button.cancel")})]})})})),$s=B((({onSelect:e,onRequestCancel:t,onClose:i})=>{const s=z(ki);return P(Bs,{width:s.width,height:s.height,onSelect:e,onRequestCancel:t,onClose:i})}));$s.displayName="BoxSelector";var Ws=$s;(e=>{if(e&&Object.assign(it,e),st.isInitialized){if(it.resources)for(const e of Object.keys(it.resources))st.addResourceBundle(e,"translation",it.resources[e].translation,!0);else console.warn("i18n is already initialized");return t(st.t)}i(st.init(it))})({resources:{en:{translation:tt}}});export{Ws as BoxSelector,ot as Camera,Vs as CameraPlayer,Ci as CloseControl,si as Control,Hi as Controls,Ds as DefaultControls,Ti as FullscreenControl,Si as PlayPauseControl,Ii as PlaybackRateControl,Fs as Player,ki as PlayerContext,_s as PtzControls,Li as ResizeModeControl,Di as SnapshotControl,Ai as VolumeControl,Vs as default,ti as useFullscreen,Hs as usePlayerRef};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@3deye-toolkit/react-camera",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"module": "dist/react-camera.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
8
8
|
"types": "dist/react-camera.d.ts",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@3deye-toolkit/core": "0.0.
|
|
10
|
+
"@3deye-toolkit/core": "0.0.8",
|
|
11
11
|
"@floating-ui/react": "^0.25.4",
|
|
12
12
|
"@react-spring/web": "^9.7.3",
|
|
13
13
|
"@seznam/compose-react-refs": "^1.0.6",
|