@3deye-toolkit/core 0.0.1-alpha.9 → 0.0.2

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/core.js CHANGED
@@ -1,29 +1 @@
1
- import{observable as e,computed as t,action as n,runInAction as r,reaction as i,when as s}from"mobx";import{Observable as a,empty as o,of as c,throwError as l,timer as h,Subject as u,BehaviorSubject as d}from"rxjs";import{switchMap as f,flatMap as p,retryWhen as v,catchError as m,startWith as y,pairwise as b,filter as g,concatMap as T,delay as E,take as I,takeUntil as O,shareReplay as _,map as w,tap as A,skip as C,share as R}from"rxjs/operators";import S from"jqueryless-signalr";import k from"crossfilter2";
2
- /*! *****************************************************************************
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
5
- this file except in compliance with the License. You may obtain a copy of the
6
- License at http://www.apache.org/licenses/LICENSE-2.0
7
-
8
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
9
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
10
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
11
- MERCHANTABLITY OR NON-INFRINGEMENT.
12
-
13
- See the Apache Version 2.0 License for specific language governing permissions
14
- and limitations under the License.
15
- ***************************************************************************** */function j(e,t,n,r){var i,s=arguments.length,a=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,n,a):i(t,n))||a);return s>3&&a&&Object.defineProperty(t,n,a),a}function N(e){return null!=e}function B(){return e=>e.pipe(g(N))}const D={archives:{PopulateArchive:null,GetArchives:null,GetClips:null,UpdateClip:null,DeleteClip:null,SaveClip:null,SaveTimelaps:null,SaveArchive:null,DeleteArchive:null,ShareClip:null,GetSharedClips:null,UpdateSharedClip:null,DeleteSharedClip:null},cameras:{GetCameras:null,GetMotionEvents:null,MoveCamera:null,GoHomePtzCamera:null,SetHomePtzCamera:null,GetSensorDataSchema:null,GetSensorEvents:null},camgroups:{GetCamgroups:null,DeleteCamgroup:null,AddCamgroup:null,UpdateCamgroup:null},sound:{GetPushSoundServiceUrl:null},thumbnails:{GetThumbnailsInfo:null,GetThumbnailInfo:null,GetHeatMapsInfo:null},users:{GetUser:null,UserUpdateProfile:null}},U={cameras:[{name:"OnCameraMotionEvent",explicit:!0},{name:"OnCameraAdded"},{name:"OnCameraUpdated"},{name:"OnSystemCameraUpdated"},{name:"OnCameraDeleted"}],users:[{name:"OnUserUpdateProfile"}],camgroups:[{name:"OnAdd"},{name:"OnUpdate"},{name:"OnDelete"}],archives:[{name:"OnTimelapsAdded"},{name:"OnClipAdded"},{name:"OnClipUpdated"},{name:"OnClipDeleted"},{name:"OnArchiveAdded"},{name:"OnArchiveUpdated"},{name:"OnArchiveDeleted"},{name:"OnArchiveRecordCreated"}]};var P,F;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.CONNECTED=1]="CONNECTED",e[e.RECONNECTING=2]="RECONNECTING",e[e.DISCONNECTED=3]="DISCONNECTED"}(P||(P={}));class q{constructor(e,t,n){this.connectionShutdown$=new u,this.connection$=new d(null),this.events=new u,this.logging=!1,this.apiConfig=e,this.init(),this.createConnection=n,this.authStore=t,i(()=>t.token,e=>{if(!e)return void this.shutdownConnection();if(e.invalid)return;if(!e.accessToken)return;const t=this.connection$.getValue();t&&t.state!==P.DISCONNECTED?t.qs.access_token=e.accessToken:this.connect(e)}),this.connection$.pipe(f(e=>null!==e||!t.isAuthenticated||t.token&&t.token.invalid?o():(this.logging&&console.warn("disconnected by some reason"),h(5e3))),g(()=>t.isAuthenticated&&!!t.token&&!t.token.invalid)).subscribe(()=>{this.connect(t.token),this.logging&&console.warn("attempting to reconnect")}),this.connection$.pipe(B(),E(100)).subscribe(this.subscribeToEvents)}static create(e,t,n){return new q(null!==e?e:D,t,n)}connect(e){if(this.connection$.getValue()&&this.connection$.getValue().state===P.CONNECTED)return;const{accessToken:t}=e,n=this.createConnection(t);Object.keys(this.apiConfig).forEach(e=>n.createHubProxy(e)),Object.entries(U).forEach(([e,t])=>{t&&n.proxies[e]&&t.forEach(({name:t})=>{n.proxies[e].on(t,n=>this.events.next({hub:e,event:t,data:n}))})}),n.start().done(()=>{this.logging&&console.warn("connected"),this.connection$.next(n)}).fail(e=>{if(401===e.source.status||403===e.source.status||409===e.source.status)return this.authStore.invalidateToken()}),n.error(e=>{if(e.source&&(401===e.source.status||403===e.source.status||409===e.source.status))return this.logging&&console.warn("authentication error, invalidating token"),this.authStore.invalidateToken()}),n.disconnected(()=>{this.connection$.getValue()?this.logging&&console.warn("disconnected",this.connection$.getValue().lastError):this.logging&&console.warn("disconnected. this connection is already null"),this.connection$.next(null)}),n.reconnecting(()=>console.log("reconnecting")),n.reconnected(()=>{this.connection$.getValue()===n&&(this.logging&&console.warn("reconnected"),this.connection$.next(n))})}shutdownConnection(){const e=this.connection$.getValue();e&&e.stop(),this.connectionShutdown$.next(null)}init(){Object.keys(this.apiConfig).forEach(e=>{this[e]={},Object.keys(this.apiConfig[e]).forEach(t=>{this[e][t]=this.createHubMethod(e,t)})})}createHubMethod(e,t){const n=this;return function r(...i){return n.connection$.pipe(B(),g(e=>e.state===P.CONNECTED),I(1)).pipe(p(n=>new Promise((r,s)=>{n.proxies[e].invoke(t,...i).done(e=>r(e)).fail(e=>s(e))})),m(e=>!e.message||"Connection started reconnecting before invocation result was received."!==e.message&&"Connection was disconnected before invocation result was received."!==e.message?e.message&&e.message.startsWith("Caller is not authorized to invoke the ")?(console.warn(e.message),n.connection$.getValue().stop(),n.authStore.invalidateToken(),r(...i)):l(e):(console.warn(e.message),r(...i))),O(n.connectionShutdown$))}}subscribeToEvents(e){Object.entries(U).forEach(([t,n])=>{n&&e.proxies[t]&&n.filter(({explicit:e})=>e).forEach(({name:n})=>{e.proxies[t].invoke("SubscribeToEvent",n)})})}}
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation. All rights reserved.
18
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
19
- this file except in compliance with the License. You may obtain a copy of the
20
- License at http://www.apache.org/licenses/LICENSE-2.0
21
-
22
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
24
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
25
- MERCHANTABLITY OR NON-INFRINGEMENT.
26
-
27
- See the Apache Version 2.0 License for specific language governing permissions
28
- and limitations under the License.
29
- ***************************************************************************** */function L(e,t,n,r){var i,s=arguments.length,a=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(s<3?i(a):s>3?i(t,n,a):i(t,n))||a);return s>3&&a&&Object.defineProperty(t,n,a),a}function M(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}class x{constructor(e){this.json=e,this.accessToken=e.access_token||e.accessToken,this.accessTokenExpires=new Date(e.access_token_expires||e.accessTokenExpires),this.accessTokenIssued=new Date(e.access_token_issued||e.accessTokenIssued),this.clientId=e.client_id||e.clientId,this.expiresIn=e.expires_in||e.expiresIn,this.refreshToken=e.refresh_token||e.refreshToken,this.refreshTokenExpires=new Date(e.refresh_token_expires||e.refreshTokenExpires),this.refreshTokenIssued=new Date(e.refresh_token_issued||e.refreshTokenIssued),this.tokenType=e.token_type||e.tokenType,this.userName=e.userName,this.widgetId=e.widgetId,this.widgetToken=e.widgetToken,this.invalid=!1}}function G(e,n=!1){const r=t(e);return a.create(e=>r.observe(({newValue:t})=>e.next(t),n))}class z{constructor({tokenServiceUrl:e,widgetTokenServiceUrl:t,storage:n,tokenStorageKey:i,deviceInfo:s,clientId:a}){this.token=null,this.isAuthenticating=!1,this.signOut=()=>{this.isAuthenticating||(this.token=null)},this.signIn=({username:e,password:t,tokenToKick:n,agreedWithTerms:i})=>{if(this.isAuthenticating)return;r(()=>this.isAuthenticating=!0);const s={username:e,password:t};return n&&(s.kick_refresh_token=n),i&&(s.agree_with_terms=!0),this.fetchTokenBy("password",s).then(e=>(r(()=>{this.token=e,this.isAuthenticating=!1}),e)).catch(e=>{throw r(()=>{this.isAuthenticating=!1}),e})},this.invalidateToken=()=>{this.token&&(this.token=Object.assign(Object.assign({},this.token),{invalid:!0}))},this.isAuthenticating=!0,this.storage=n,this.tokenServiceUrl=e,this.widgetTokenServiceUrl=t,this.tokenStorageKey=i,this.deviceInfo=s,this.clientId=a,this.getInitialToken().then(e=>{this.token=e,this.isAuthenticating=!1});const u=G(()=>this.token),d=u.pipe(f(e=>{if(null===e)return o();const t=c(e).pipe(p(e=>e.widgetId?this.fetchWidgetToken(e):this.fetchTokenBy("refresh_token",{refresh_token:e.refreshToken})),v(e=>e.pipe(p(e=>!e.status||401!==e.status&&403!==e.status&&409!==e.status?e.error&&"refresh_token_error"===e.error||"invalid_grant"===e.error?l(e):h(5e3):l(e)))));if(!e.invalid){const n=Math.max(.75*(+e.accessTokenExpires-Date.now()),0);return h(n).pipe(p(()=>t))}return t}),m(e=>(console.error(e),this.token=null,d)));d.subscribe(e=>{this.token=e,console.warn("token updated")}),u.pipe(y(null),b(),g(([e,t])=>!!(t||!t&&e)),T(([,e])=>this.storeToken(e))).subscribe()}get isAuthenticated(){return Boolean(this.token&&!this.isAuthenticating)}async getTokenFromStorage(){const e=await this.storage.getItem(this.tokenStorageKey);return e?new x(JSON.parse(e)):null}async storeToken(e){return!e||e.invalid?this.storage.removeItem(this.tokenStorageKey):this.storage.setItem(this.tokenStorageKey,JSON.stringify(e.json))}async getInitialToken(){const e=await this.getTokenFromStorage();if(!e)return null;if(+e.accessTokenExpires>Date.now())return e;if(e.widgetId&&e.widgetToken)return e;if(+e.refreshTokenExpires>Date.now())try{const{refreshToken:t}=e;return await this.fetchTokenBy("refresh_token",{refresh_token:t})}catch(e){this.token=null,this.storeToken(null),console.error("refresh token error",e)}return null}async fetchTokenBy(e,t){const n=Object.assign({grant_type:e,client_id:this.clientId,device:this.deviceInfo},t),r=Object.keys(n).map(e=>`${e}=${encodeURIComponent(n[e])}`).join("&"),i=new Headers;i.append("Content-Type","application/x-www-form-urlencoded"),i.append("accept","application/json");const s=await fetch(this.tokenServiceUrl,{method:"POST",headers:i,body:r});try{const e=await s.json();return 200!==s.status?Promise.reject({status:s.status,data:e}):new x(e)}catch(e){return Promise.reject(s)}}async fetchWidgetToken(e){const{widgetId:t,widgetToken:n}=e;if(!t||!n)throw new Error("token must contain widgetId and widgetToken");if(!this.widgetTokenServiceUrl)throw new Error("please set widgetTokenServiceUrl");const r={widgetId:t,userKey:n},i=new Headers;i.append("Content-Type","application/x-www-form-urlencoded"),i.append("accept","application/json");const s=Object.keys(r).map(e=>`${e}=${encodeURIComponent(r[e])}`).join("&"),a=await fetch(this.widgetTokenServiceUrl,{method:"POST",headers:i,body:s});try{const e=await a.json();return 200!==a.status?Promise.reject({status:a.status,data:e}):new x(Object.assign({widgetId:t,widgetToken:n},e))}catch(e){return Promise.reject(a)}}}L([e,M("design:type",Object)],z.prototype,"token",void 0),L([e,M("design:type",Boolean)],z.prototype,"isAuthenticating",void 0),L([t,M("design:type",Boolean),M("design:paramtypes",[])],z.prototype,"isAuthenticated",null),L([n,M("design:type",Object)],z.prototype,"signOut",void 0),L([n,M("design:type",Object)],z.prototype,"invalidateToken",void 0),function(e){e.Motion="Motion",e.Tampering="Tampering",e.PanTiltZoom="PanTiltZoom",e.CrossLine="CrossLine",e.Start="Start",e.Stop="Stop",e.Restart="Restart",e.Audio="Audio",e.Analytic="Analytic",e.Unknown="Unknown"}(F||(F={}));class H{constructor(){this.values=new Map}getItem(e){return this.values.get(e)||null}setItem(e,t){this.values.set(e,t)}removeItem(e){this.values.delete(e)}}var $="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function W(e,t){return e(t={exports:{}},t.exports),t.exports}var V=W((function(e,t){var n={};n[t.ACCEPTED=202]="Accepted",n[t.BAD_GATEWAY=502]="Bad Gateway",n[t.BAD_REQUEST=400]="Bad Request",n[t.CONFLICT=409]="Conflict",n[t.CONTINUE=100]="Continue",n[t.CREATED=201]="Created",n[t.EXPECTATION_FAILED=417]="Expectation Failed",n[t.FAILED_DEPENDENCY=424]="Failed Dependency",n[t.FORBIDDEN=403]="Forbidden",n[t.GATEWAY_TIMEOUT=504]="Gateway Timeout",n[t.GONE=410]="Gone",n[t.HTTP_VERSION_NOT_SUPPORTED=505]="HTTP Version Not Supported",n[t.IM_A_TEAPOT=418]="I'm a teapot",n[t.INSUFFICIENT_SPACE_ON_RESOURCE=419]="Insufficient Space on Resource",n[t.INSUFFICIENT_STORAGE=507]="Insufficient Storage",n[t.INTERNAL_SERVER_ERROR=500]="Server Error",n[t.LENGTH_REQUIRED=411]="Length Required",n[t.LOCKED=423]="Locked",n[t.METHOD_FAILURE=420]="Method Failure",n[t.METHOD_NOT_ALLOWED=405]="Method Not Allowed",n[t.MOVED_PERMANENTLY=301]="Moved Permanently",n[t.MOVED_TEMPORARILY=302]="Moved Temporarily",n[t.MULTI_STATUS=207]="Multi-Status",n[t.MULTIPLE_CHOICES=300]="Multiple Choices",n[t.NETWORK_AUTHENTICATION_REQUIRED=511]="Network Authentication Required",n[t.NO_CONTENT=204]="No Content",n[t.NON_AUTHORITATIVE_INFORMATION=203]="Non Authoritative Information",n[t.NOT_ACCEPTABLE=406]="Not Acceptable",n[t.NOT_FOUND=404]="Not Found",n[t.NOT_IMPLEMENTED=501]="Not Implemented",n[t.NOT_MODIFIED=304]="Not Modified",n[t.OK=200]="OK",n[t.PARTIAL_CONTENT=206]="Partial Content",n[t.PAYMENT_REQUIRED=402]="Payment Required",n[t.PERMANENT_REDIRECT=308]="Permanent Redirect",n[t.PRECONDITION_FAILED=412]="Precondition Failed",n[t.PRECONDITION_REQUIRED=428]="Precondition Required",n[t.PROCESSING=102]="Processing",n[t.PROXY_AUTHENTICATION_REQUIRED=407]="Proxy Authentication Required",n[t.REQUEST_HEADER_FIELDS_TOO_LARGE=431]="Request Header Fields Too Large",n[t.REQUEST_TIMEOUT=408]="Request Timeout",n[t.REQUEST_TOO_LONG=413]="Request Entity Too Large",n[t.REQUEST_URI_TOO_LONG=414]="Request-URI Too Long",n[t.REQUESTED_RANGE_NOT_SATISFIABLE=416]="Requested Range Not Satisfiable",n[t.RESET_CONTENT=205]="Reset Content",n[t.SEE_OTHER=303]="See Other",n[t.SERVICE_UNAVAILABLE=503]="Service Unavailable",n[t.SWITCHING_PROTOCOLS=101]="Switching Protocols",n[t.TEMPORARY_REDIRECT=307]="Temporary Redirect",n[t.TOO_MANY_REQUESTS=429]="Too Many Requests",n[t.UNAUTHORIZED=401]="Unauthorized",n[t.UNPROCESSABLE_ENTITY=422]="Unprocessable Entity",n[t.UNSUPPORTED_MEDIA_TYPE=415]="Unsupported Media Type",n[t.USE_PROXY=305]="Use Proxy",t.getStatusText=function(e){if(n.hasOwnProperty(e))return n[e];throw new Error("Status code does not exist: "+e)},t.getStatusCode=function(e){for(key in n)if(n[key]===e)return parseInt(key,10);throw new Error("Reason phrase does not exist: "+e)}}));V.ACCEPTED,V.BAD_GATEWAY,V.BAD_REQUEST,V.CONFLICT,V.CONTINUE,V.CREATED,V.EXPECTATION_FAILED,V.FAILED_DEPENDENCY,V.FORBIDDEN,V.GATEWAY_TIMEOUT,V.GONE,V.HTTP_VERSION_NOT_SUPPORTED,V.IM_A_TEAPOT,V.INSUFFICIENT_SPACE_ON_RESOURCE,V.INSUFFICIENT_STORAGE,V.INTERNAL_SERVER_ERROR,V.LENGTH_REQUIRED,V.LOCKED,V.METHOD_FAILURE,V.METHOD_NOT_ALLOWED,V.MOVED_PERMANENTLY,V.MOVED_TEMPORARILY,V.MULTI_STATUS,V.MULTIPLE_CHOICES,V.NETWORK_AUTHENTICATION_REQUIRED,V.NO_CONTENT,V.NON_AUTHORITATIVE_INFORMATION,V.NOT_ACCEPTABLE,V.NOT_FOUND,V.NOT_IMPLEMENTED,V.NOT_MODIFIED,V.OK,V.PARTIAL_CONTENT,V.PAYMENT_REQUIRED,V.PERMANENT_REDIRECT,V.PRECONDITION_FAILED,V.PRECONDITION_REQUIRED,V.PROCESSING,V.PROXY_AUTHENTICATION_REQUIRED,V.REQUEST_HEADER_FIELDS_TOO_LARGE,V.REQUEST_TIMEOUT,V.REQUEST_TOO_LONG,V.REQUEST_URI_TOO_LONG,V.REQUESTED_RANGE_NOT_SATISFIABLE,V.RESET_CONTENT,V.SEE_OTHER,V.SERVICE_UNAVAILABLE,V.SWITCHING_PROTOCOLS,V.TEMPORARY_REDIRECT,V.TOO_MANY_REQUESTS,V.UNAUTHORIZED,V.UNPROCESSABLE_ENTITY,V.UNSUPPORTED_MEDIA_TYPE,V.USE_PROXY,V.getStatusText,V.getStatusCode;let Q=[];function Y(){return Array.isArray(Q)?Q[0]:Q}class K{initWith(e){this.api=e,this.afterInit&&this.afterInit()}}class J extends K{constructor(e){super(),this.notification=e,this.user=null,this.camerasPermissions=new Map,s(()=>!!this.user,()=>this.fetchPermissions())}get userDisplayName(){return this.user?this.user.firstName&&this.user.firstName.trim()||this.user.lastName&&this.user.lastName.trim()?[this.user.firstName,this.user.lastName].filter(Boolean).join(" ").trim():this.user.email:null}afterInit(){this.api.users.GetUser().pipe(p(e=>e.success?c(e.resultItems[0]):l(e.error))).subscribe(e=>this.user=e,()=>console.error("Couldn't get user"))}setAuthStore(e){this.auth=e}async updateUserPassword(e){var t,n;const r=Y().changePasswordUrl,i=null===(n=null===(t=this.auth)||void 0===t?void 0:t.token)||void 0===n?void 0:n.accessToken,s=JSON.stringify({currentPassword:e.previous,newPassword:e.new}),a=new Headers;a.append("content-type","application/json"),a.append("accept","application/json"),a.append("authorization",`bearer ${i}`);const o=await fetch(r,{method:"PUT",headers:a,body:s}),{status:c}=o;if(c!==V.OK){const e=await o.json();throw new Error(e.errors[0].message)}}async fetchPermissions(){var e,t;if(!Y())return;const n=Y().userPermissionsUrl;if(!n)return console.warn("user permissions URL is missing in config");const r=null===(t=null===(e=this.auth)||void 0===e?void 0:e.token)||void 0===t?void 0:t.accessToken,i=new Headers;i.append("content-type","application/json"),i.append("accept","application/json"),i.append("authorization",`bearer ${r}`);const s=await fetch(n,{headers:i}),{status:a}=s;if(a!==V.OK){const e=await s.json();throw new Error(e.errors[0].message)}(await s.json()).securables.forEach(e=>{"camera"===e.securableType&&this.camerasPermissions.set(e.securableId,e.permissions)})}updateUserSettings({firstName:e,lastName:t}){if(!this.user)return l("user is not initialized");const n={id:this.user.id,firstName:e,lastName:t,version:this.user.version},r=this.api.users.UserUpdateProfile(n).pipe(p(e=>e.success?c(e.resultItems[0]):l(e.error)),_());return r.subscribe(e=>{this.user=e}),r}setDefaultGroup(e){if(!this.user)return;const t={id:this.user.id,layoutStartId:e,layoutStartType:"camgroup",version:this.user.version},n=this.api.users.UserUpdateProfile(t).pipe(p(e=>e.success?c(e.resultItems[0]):l(e.error)),_());return n.subscribe(e=>{var t;this.user=e,null===(t=this.notification)||void 0===t||t.success("Successfully set default group")},e=>{var t;console.error(e),null===(t=this.notification)||void 0===t||t.error(e.message)}),n}}j([e.ref],J.prototype,"user",void 0),j([e],J.prototype,"camerasPermissions",void 0),j([t],J.prototype,"userDisplayName",null);class X{constructor(e){this.isLive=!1,this.json=JSON.stringify(e,null,2),this.startTime=new Date(e.startTime),this.endTime=new Date(e.endTime),this.streamUrl=e.streamUrl,this.cameraId=e.cameraId,this.duration=e.duration,this.id=e.id}}window.ArchiveChunk=X;class Z extends K{constructor(){super(),this.chunksById=new Map,this.knownIntervals=new Map,this.updates=0,this.data=k(),this.chunksByCameraId=this.data.dimension(e=>e.cameraId),this.chunksByStart=this.data.dimension(e=>+e.startTime),this.chunksByEnd=this.data.dimension(e=>+e.endTime),this.pendingRequests=k(),this.pendingRequestsByStart=this.pendingRequests.dimension(e=>+e.startTime),this.pendingRequestsByEnd=this.pendingRequests.dimension(e=>+e.endTime),this.pendingRequestsByCameraId=this.pendingRequests.dimension(e=>e.cameraId)}fetch(e,t,n){this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(n);const r=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),r)return r.request;if(this.knownIntervals.has(e)){const[r,i]=this.knownIntervals.get(e);if(r<=t&&i>=n)return c(this.getChunks({cameraId:e,from:t,to:n}));r<=t&&i<n&&(t=i),r>t&&i>=n&&(n=r),n<r&&(n=r),t>i&&(t=i)}const i=this.api.archives.PopulateArchive({cameraId:e,startTime:t,endTime:n}).pipe(w(e=>e.resultItems[0].chunks.map(e=>new X(e))),A(this.add),A(t=>this.extendKnownInterval(e,t)),_());return this.pendingRequests.add([{cameraId:e,startTime:t,endTime:n,request:i}]),i.pipe(A(()=>this.pendingRequests.remove(e=>e.request===i))).subscribe(),i}extendKnownInterval(e,t){const n=new Date(Math.min(...t.map(e=>+e.startTime))),r=new Date(Math.max(...t.map(e=>+e.endTime)));if(this.knownIntervals.has(e)){const t=this.knownIntervals.get(e);n<t[0]&&(t[0]=n),r>t[1]&&(t[1]=r)}else this.knownIntervals.set(e,[n,r])}add(e){const t=e.filter(e=>!this.chunksById.has(e.id));t.forEach(e=>this.chunksById.set(e.id,e)),this.data.add(t),t.length&&this.updates++}getChunks({cameraId:e,from:t,to:n}){this.chunksByStart.filter([-1/0,+n+5e-4]),this.chunksByEnd.filter([t,1/0]),e&&this.chunksByCameraId.filter(e);const r=this.chunksByStart.top(1/0);return e&&this.chunksByCameraId.filterAll(),this.chunksByStart.filterAll(),this.chunksByEnd.filterAll(),r}findClosestChunk({cameraId:e,time:t}){this.chunksByCameraId.filter(e),this.chunksByEnd.filter([t,1/0]);const n=this.chunksByStart.bottom(1);return this.chunksByCameraId.filterAll(),this.chunksByEnd.filterAll(),n[0]}afterInit(){this.api.events.pipe(g(({hub:e,event:t})=>"archives"===e&&"OnArchiveChunksCreated"===t)).subscribe(({data:e})=>{this.add(e.resultItems.map(e=>new X(e)))})}}var ee,te;j([e],Z.prototype,"updates",void 0),j([n.bound],Z.prototype,"add",null);var ne=0;function re(e){return e>=48&&e<=57}function ie(e,t){for(var n=(e+="").length,r=(t+="").length,i=0,s=0;i<n&&s<r;){var a=e.charCodeAt(i),o=t.charCodeAt(s);if(re(a)){if(!re(o))return a-o;for(var c=i,l=s;48===a&&++c<n;)a=e.charCodeAt(c);for(;48===o&&++l<r;)o=t.charCodeAt(l);for(var h=c,u=l;h<n&&re(e.charCodeAt(h));)++h;for(;u<r&&re(t.charCodeAt(u));)++u;var d=h-c-u+l;if(d)return d;for(;c<h;)if(d=e.charCodeAt(c++)-t.charCodeAt(l++))return d;i=h,s=u}else{if(a!==o)return a<ne&&o<ne&&-1!==te[a]&&-1!==te[o]?te[a]-te[o]:a-o;++i,++s}}return i>=n&&s<r&&n>=r?-1:s>=r&&i<n&&r>=n?1:n-r}ie.caseInsensitive=ie.i=function(e,t){return ie((""+e).toLowerCase(),(""+t).toLowerCase())},Object.defineProperties(ie,{alphabet:{get:function(){return ee},set:function(e){te=[];var t=0;if(ee=e)for(;t<ee.length;t++)te[ee.charCodeAt(t)]=t;for(ne=te.length,t=0;t<ne;t++)void 0===te[t]&&(te[t]=-1)}}});var se,ae=ie;class oe{constructor(e){this.update(e)}get isOnline(){return this.enabled&&"Started"===this.state}get supportsWebRTC(){return!!this.webRtcUrl}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.stateUpdatedAt=new Date(e.cameraStateChangedTime)}}j([e],oe.prototype,"name",void 0),j([e],oe.prototype,"streamUrl",void 0),j([e],oe.prototype,"dashStreamUrl",void 0),j([e],oe.prototype,"enabled",void 0),j([e],oe.prototype,"isMicEnabled",void 0),j([e],oe.prototype,"state",void 0),j([e],oe.prototype,"pin",void 0),j([e],oe.prototype,"webRtcUrl",void 0),j([t],oe.prototype,"isOnline",null),j([n.bound],oe.prototype,"update",null);class ce extends K{constructor(){super(),this.camerasById=new Map,this.data=[],this.loading=!1,this.loaded=!1,this.add=e=>{e.forEach(e=>{this.camerasById.has(e.id)?this.camerasById.get(e.id).update(e):this.camerasById.set(e.id,new oe(e))}),this.data=Array.from(this.camerasById.values()).sort((e,t)=>ae.caseInsensitive(e.name,t.name))},this.sync=()=>{const e=this.data.reduce((e,t)=>Math.max(e,+t.stateUpdatedAt),0);e&&this.api.cameras.GetCameras({},new Date(1e3*(Math.floor(e/1e3)+1))).pipe(p(e=>e.success?c(e.resultItems):(console.error(e.error),l(e.error)))).subscribe(e=>this.add(e))},s(()=>this.loaded,()=>{this.api.connection$.pipe(C(1)).subscribe(this.sync)})}fetch(){this.loading=!0;const e=this.api.cameras.GetCameras({},null).pipe(p(e=>e.success?c(e.resultItems):(console.error(e.error),l(e.error))),R());return e.subscribe(e=>{r(()=>{this.add(e),this.loading=!1,this.loaded=!0})}),e}afterInit(){this.api.events.pipe(g(({hub:e,event:t})=>"cameras"===e&&("OnCameraUpdated"===t||"OnSystemCameraUpdated"===t)),w(({data:e})=>e.resultItems?e.resultItems[0]:e)).subscribe(e=>{const t=this.camerasById.get(e.id);if(!t)return console.warn("got update for unknown camera:",e.id);t.update(e)})}}j([e.ref],ce.prototype,"data",void 0),j([e],ce.prototype,"loading",void 0),j([e],ce.prototype,"loaded",void 0),j([n],ce.prototype,"add",void 0),function(e){e.Default="Default",e.Analytic="Analytic"}(se||(se={}));class le{constructor(e){if(this.raw=e,this.id=e.id,this.startTime=new Date(e.startTime),e.endTime&&(this.endTime=new Date(e.endTime)),this.cameraId=e.cameraId,e.data.startsWith("{"))try{const t=JSON.parse(e.data);t.FoundObjects&&(this.type=se.Analytic,this.foundObjects=t.FoundObjects),t.Faces&&(this.type=se.Analytic,this.faces=t.Faces),this.thumbnailUrl=t.ThumbnailUrl}catch(t){console.warn("invalid data",e.data),this.type=se.Default}else this.type=se.Default;this.type===se.Default&&+this.endTime-+this.startTime==0&&Date.now()-+this.startTime>6e5&&(this.endTime=new Date(+this.startTime+12e4)),this.foundObjects||(this.foundObjects=[])}get isLive(){return this.type===se.Default&&+this.startTime==+this.endTime}}j([e],le.prototype,"endTime",void 0);class he{constructor(e){this.eventsStore=e,this.data=[],this.cameraFilters=[],this.objectFilters=[],this.loading=!1,this.probabilityThreshold=.5,this.facesProbabilityThreshold=.7,this.onlyFaces=!1,this.totalCount=0,this.facesCount=0,this.title="menu.events",this.pendingData=[],this.paused=!1,this.updates=0,this.colors=new Set,this.flushUpdates=()=>{this.pendingData=[],this.updates++},this.isAboveThreshold=e=>{if(e.type!==se.Analytic)return!0;if(!this.objectFilters.length)return!0;const t=this.objectFilters.map(e=>e.id);return!(!e.faces||!e.faces.some(e=>e.Probability>=this.probabilityThreshold))||e.foundObjects.some(e=>{const n=t.includes(e.Type)&&e.Probability>=this.probabilityThreshold;return this.colors.size?n&&e.Colors.some(e=>this.colors.has(e.Color)):n})},this.hasFacesAboveThreshold=e=>!(!e.faces||!e.faces.length)&&e.faces.some(e=>e.Probability>=this.facesProbabilityThreshold),this.getProbabilityTreshold=()=>this.probabilityThreshold,this.setProbabilityTreshold=e=>{this.probabilityThreshold=e},this.getFacesProbabilityTreshold=()=>this.facesProbabilityThreshold,this.setFacesProbabilityTreshold=e=>{this.facesProbabilityThreshold=e},G(()=>this.paused,!0).pipe(f(t=>G(t?()=>({updates:this.updates,from:this.from,to:this.to,filters:this.filters,onlyFaces:this.onlyFaces,probabilityThreshold:this.probabilityThreshold,facesProbabilityThreshold:this.facesProbabilityThreshold,colors:this.colors}):()=>({updates:e.updates,from:this.from,to:this.to,filters:this.filters,onlyFaces:this.onlyFaces,probabilityThreshold:this.probabilityThreshold,facesProbabilityThreshold:this.facesProbabilityThreshold,colors:this.colors})))).subscribe(({from:t,to:n,onlyFaces:i,colors:s})=>{const a=this.cameraFilters.map(e=>e.id),o=this.objectFilters.map(e=>e.id),c={from:t,to:n};a.length&&(c.cameraIds=a);const l={};o.length&&(l.objectType=o,s.size&&(l.colors=s)),r(()=>{if(i){const t=e.getEvents(Object.assign(Object.assign({},c),l)).filter(this.isAboveThreshold);this.totalCount=t.length,this.data=e.getEvents(c).filter(e=>e.faces&&e.faces.length).filter(this.hasFacesAboveThreshold),this.facesCount=this.data.length}else this.data=e.getEvents(Object.assign(Object.assign({},c),l)).filter(this.isAboveThreshold),this.totalCount=this.data.length,this.facesCount=e.getEvents(c).filter(this.hasFacesAboveThreshold).length})}),G(()=>this.paused,!0).pipe(f(t=>t?G(()=>e.recentAdditions):o())).subscribe(t=>{const n=t.map(t=>e.eventsById.get(t)).filter(Boolean),{from:r,to:i,onlyFaces:s}=this,a=this.cameraFilters.map(e=>e.id);let o=n;a&&(o=o.filter(e=>a.includes(e.cameraId))),r&&(o=o.filter(e=>e.startTime>=r)),i&&(o=o.filter(e=>e.endTime<=i)),s?o=o.filter(this.hasFacesAboveThreshold):this.objectFilters.length&&(o=o.filter(this.isAboveThreshold),this.colors.size&&o.filter(e=>e.foundObjects.some(e=>e.Colors.some(e=>this.colors.has(e.Color))))),o.length&&(this.pendingData=this.pendingData.concat(o))}),G(()=>({from:this.from,to:this.to})).pipe(f(({from:e,to:t})=>(this.loading=!0,this.eventsStore.fetchEvents(-1,e,t)))).subscribe(()=>{this.loading=!1})}get someAnalyticsFilterSelected(){return!!this.objectFilters.length}get filters(){return this.onlyFaces?this.cameraFilters:this.objectFilters.concat(this.cameraFilters)}toggleFaces(){this.onlyFaces=!this.onlyFaces}load(){this.from=new Date(Date.now()-864e5),this.to=null,this.loading=!1}setFilters(e){this.cameraFilters=e?e.filter(e=>!("isEventType"in e)):[],this.onlyFaces||(this.objectFilters=e?e.filter(e=>"isEventType"in e):[])}toggleColor(e){const t=new Set(this.colors);this.colors.has(e)?t.delete(e):t.add(e),this.colors=t}clearColors(){this.colors=new Set}}j([e.ref],he.prototype,"data",void 0),j([e.ref],he.prototype,"cameraFilters",void 0),j([e.ref],he.prototype,"objectFilters",void 0),j([e],he.prototype,"to",void 0),j([e],he.prototype,"from",void 0),j([e],he.prototype,"loading",void 0),j([e],he.prototype,"probabilityThreshold",void 0),j([e],he.prototype,"facesProbabilityThreshold",void 0),j([e],he.prototype,"onlyFaces",void 0),j([e],he.prototype,"totalCount",void 0),j([e],he.prototype,"facesCount",void 0),j([e.ref],he.prototype,"pendingData",void 0),j([e],he.prototype,"paused",void 0),j([e],he.prototype,"updates",void 0),j([e.ref],he.prototype,"colors",void 0),j([t],he.prototype,"someAnalyticsFilterSelected",null),j([t],he.prototype,"filters",null),j([n],he.prototype,"flushUpdates",void 0),j([n.bound],he.prototype,"toggleFaces",null),j([n],he.prototype,"load",null),j([n.bound],he.prototype,"toggleColor",null),j([n.bound],he.prototype,"clearColors",null);var ue={red:{50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",900:"#b71c1c",a100:"#ff8a80",a200:"#ff5252",a400:"#ff1744",a700:"#d50000"},pink:{50:"#fce4ec",100:"#f8bbd0",200:"#f48fb1",300:"#f06292",400:"#ec407a",500:"#e91e63",600:"#d81b60",700:"#c2185b",800:"#ad1457",900:"#880e4f",a100:"#ff80ab",a200:"#ff4081",a400:"#f50057",a700:"#c51162"},purple:{50:"#f3e5f5",100:"#e1bee7",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",600:"#8e24aa",700:"#7b1fa2",800:"#6a1b9a",900:"#4a148c",a100:"#ea80fc",a200:"#e040fb",a400:"#d500f9",a700:"#aa00ff"},deepPurple:{50:"#ede7f6",100:"#d1c4e9",200:"#b39ddb",300:"#9575cd",400:"#7e57c2",500:"#673ab7",600:"#5e35b1",700:"#512da8",800:"#4527a0",900:"#311b92",a100:"#b388ff",a200:"#7c4dff",a400:"#651fff",a700:"#6200ea"},indigo:{50:"#e8eaf6",100:"#c5cae9",200:"#9fa8da",300:"#7986cb",400:"#5c6bc0",500:"#3f51b5",600:"#3949ab",700:"#303f9f",800:"#283593",900:"#1a237e",a100:"#8c9eff",a200:"#536dfe",a400:"#3d5afe",a700:"#304ffe"},blue:{50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1",a100:"#82b1ff",a200:"#448aff",a400:"#2979ff",a700:"#2962ff"},lightBlue:{50:"#e1f5fe",100:"#b3e5fc",200:"#81d4fa",300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",600:"#039be5",700:"#0288d1",800:"#0277bd",900:"#01579b",a100:"#80d8ff",a200:"#40c4ff",a400:"#00b0ff",a700:"#0091ea"},cyan:{50:"#e0f7fa",100:"#b2ebf2",200:"#80deea",300:"#4dd0e1",400:"#26c6da",500:"#00bcd4",600:"#00acc1",700:"#0097a7",800:"#00838f",900:"#006064",a100:"#84ffff",a200:"#18ffff",a400:"#00e5ff",a700:"#00b8d4"},teal:{50:"#e0f2f1",100:"#b2dfdb",200:"#80cbc4",300:"#4db6ac",400:"#26a69a",500:"#009688",600:"#00897b",700:"#00796b",800:"#00695c",900:"#004d40",a100:"#a7ffeb",a200:"#64ffda",a400:"#1de9b6",a700:"#00bfa5"},green:{50:"#e8f5e9",100:"#c8e6c9",200:"#a5d6a7",300:"#81c784",400:"#66bb6a",500:"#4caf50",600:"#43a047",700:"#388e3c",800:"#2e7d32",900:"#1b5e20",a100:"#b9f6ca",a200:"#69f0ae",a400:"#00e676",a700:"#00c853"},lightGreen:{50:"#f1f8e9",100:"#dcedc8",200:"#c5e1a5",300:"#aed581",400:"#9ccc65",500:"#8bc34a",600:"#7cb342",700:"#689f38",800:"#558b2f",900:"#33691e",a100:"#ccff90",a200:"#b2ff59",a400:"#76ff03",a700:"#64dd17"},lime:{50:"#f9fbe7",100:"#f0f4c3",200:"#e6ee9c",300:"#dce775",400:"#d4e157",500:"#cddc39",600:"#c0ca33",700:"#afb42b",800:"#9e9d24",900:"#827717",a100:"#f4ff81",a200:"#eeff41",a400:"#c6ff00",a700:"#aeea00"},yellow:{50:"#fffde7",100:"#fff9c4",200:"#fff59d",300:"#fff176",400:"#ffee58",500:"#ffeb3b",600:"#fdd835",700:"#fbc02d",800:"#f9a825",900:"#f57f17",a100:"#ffff8d",a200:"#ffff00",a400:"#ffea00",a700:"#ffd600"},amber:{50:"#fff8e1",100:"#ffecb3",200:"#ffe082",300:"#ffd54f",400:"#ffca28",500:"#ffc107",600:"#ffb300",700:"#ffa000",800:"#ff8f00",900:"#ff6f00",a100:"#ffe57f",a200:"#ffd740",a400:"#ffc400",a700:"#ffab00"},orange:{50:"#fff3e0",100:"#ffe0b2",200:"#ffcc80",300:"#ffb74d",400:"#ffa726",500:"#ff9800",600:"#fb8c00",700:"#f57c00",800:"#ef6c00",900:"#e65100",a100:"#ffd180",a200:"#ffab40",a400:"#ff9100",a700:"#ff6d00"},deepOrange:{50:"#fbe9e7",100:"#ffccbc",200:"#ffab91",300:"#ff8a65",400:"#ff7043",500:"#ff5722",600:"#f4511e",700:"#e64a19",800:"#d84315",900:"#bf360c",a100:"#ff9e80",a200:"#ff6e40",a400:"#ff3d00",a700:"#dd2c00"},brown:{50:"#efebe9",100:"#d7ccc8",200:"#bcaaa4",300:"#a1887f",400:"#8d6e63",500:"#795548",600:"#6d4c41",700:"#5d4037",800:"#4e342e",900:"#3e2723"},grey:{50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121"},blueGrey:{50:"#eceff1",100:"#cfd8dc",200:"#b0bec5",300:"#90a4ae",400:"#78909c",500:"#607d8b",600:"#546e7a",700:"#455a64",800:"#37474f",900:"#263238"},darkText:{primary:"rgba(0, 0, 0, 0.87)",secondary:"rgba(0, 0, 0, 0.54)",disabled:"rgba(0, 0, 0, 0.38)",dividers:"rgba(0, 0, 0, 0.12)"},lightText:{primary:"rgba(255, 255, 255, 1)",secondary:"rgba(255, 255, 255, 0.7)",disabled:"rgba(255, 255, 255, 0.5)",dividers:"rgba(255, 255, 255, 0.12)"},darkIcons:{active:"rgba(0, 0, 0, 0.54)",inactive:"rgba(0, 0, 0, 0.38)"},lightIcons:{active:"rgba(255, 255, 255, 1)",inactive:"rgba(255, 255, 255, 0.5)"},white:"#ffffff",black:"#000000"};const de={Person:"red",Car:"green",Animal:"blue"},fe=["green","red","blue","purple","teal","amber","pink","blueGrey","cyan","yellow","lightGreen","brown","lime","deepOrange","grey","indigo","orange","deepPurple","lightBlue"];class pe extends K{constructor(){super(...arguments),this.schemaDescription=[],this.fetchAnalyticEventSchema=()=>{this.api.cameras.GetSensorDataSchema(F.Analytic).subscribe(e=>{e.success?this.schemaDescription=e.resultItems:console.error(e)},console.error)}}get foundObjectTypes(){if(!this.schemaDescription.length)return[];const e=this.schemaDescription.filter(e=>"filter"===e.parameterType&&"Type"===e.fieldName&&e.eventType===F.Analytic)[0];return e?e.valueSet.split(", "):[]}get foundObjectTypesForSelect(){const e=Object.entries(de).filter(([e])=>this.foundObjectTypes.includes(e)).map(([,e])=>e),t=fe.filter(t=>!e.includes(t));return this.foundObjectTypes.map((e,n)=>{const r=e in de?de[e]:t[n],i=ue[r],s=ue[r];return{id:e,name:e.toLowerCase(),color:i[500],highlightColor:s.a400,isEventType:!0}})}get colorsByFoundObjectType(){const e=new Map;return this.foundObjectTypesForSelect.forEach(t=>{e.set(t.id,t.highlightColor)}),e}afterInit(){this.fetchAnalyticEventSchema()}}j([e.ref],pe.prototype,"schemaDescription",void 0),j([t],pe.prototype,"foundObjectTypes",null),j([t],pe.prototype,"foundObjectTypesForSelect",null),j([t],pe.prototype,"colorsByFoundObjectType",null);var ve=function(e,t,n,r){for(var i=-1,s=null==e?0:e.length;++i<s;){var a=e[i];t(r,a,n(a),e)}return r};var me=function(e){return function(t,n,r){for(var i=-1,s=Object(t),a=r(t),o=a.length;o--;){var c=a[e?o:++i];if(!1===n(s[c],c,s))break}return t}}();var ye=function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r},be="object"==typeof $&&$&&$.Object===Object&&$,ge="object"==typeof self&&self&&self.Object===Object&&self,Te=be||ge||Function("return this")(),Ee=Te.Symbol,Ie=Object.prototype,Oe=Ie.hasOwnProperty,_e=Ie.toString,we=Ee?Ee.toStringTag:void 0;var Ae=function(e){var t=Oe.call(e,we),n=e[we];try{e[we]=void 0;var r=!0}catch(e){}var i=_e.call(e);return r&&(t?e[we]=n:delete e[we]),i},Ce=Object.prototype.toString;var Re=function(e){return Ce.call(e)},Se=Ee?Ee.toStringTag:void 0;var ke=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Se&&Se in Object(e)?Ae(e):Re(e)};var je=function(e){return null!=e&&"object"==typeof e};var Ne=function(e){return je(e)&&"[object Arguments]"==ke(e)},Be=Object.prototype,De=Be.hasOwnProperty,Ue=Be.propertyIsEnumerable,Pe=Ne(function(){return arguments}())?Ne:function(e){return je(e)&&De.call(e,"callee")&&!Ue.call(e,"callee")},Fe=Array.isArray;var qe=function(){return!1},Le=W((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,i=r&&r.exports===n?Te.Buffer:void 0,s=(i?i.isBuffer:void 0)||qe;e.exports=s})),Me=/^(?:0|[1-9]\d*)$/;var xe=function(e,t){var n=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==n||"symbol"!=n&&Me.test(e))&&e>-1&&e%1==0&&e<t};var Ge=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991},ze={};ze["[object Float32Array]"]=ze["[object Float64Array]"]=ze["[object Int8Array]"]=ze["[object Int16Array]"]=ze["[object Int32Array]"]=ze["[object Uint8Array]"]=ze["[object Uint8ClampedArray]"]=ze["[object Uint16Array]"]=ze["[object Uint32Array]"]=!0,ze["[object Arguments]"]=ze["[object Array]"]=ze["[object ArrayBuffer]"]=ze["[object Boolean]"]=ze["[object DataView]"]=ze["[object Date]"]=ze["[object Error]"]=ze["[object Function]"]=ze["[object Map]"]=ze["[object Number]"]=ze["[object Object]"]=ze["[object RegExp]"]=ze["[object Set]"]=ze["[object String]"]=ze["[object WeakMap]"]=!1;var He=function(e){return je(e)&&Ge(e.length)&&!!ze[ke(e)]};var $e=function(e){return function(t){return e(t)}},We=W((function(e,t){var n=t&&!t.nodeType&&t,r=n&&e&&!e.nodeType&&e,i=r&&r.exports===n&&be.process,s=function(){try{var e=r&&r.require&&r.require("util").types;return e||i&&i.binding&&i.binding("util")}catch(e){}}();e.exports=s})),Ve=We&&We.isTypedArray,Qe=Ve?$e(Ve):He,Ye=Object.prototype.hasOwnProperty;var Ke=function(e,t){var n=Fe(e),r=!n&&Pe(e),i=!n&&!r&&Le(e),s=!n&&!r&&!i&&Qe(e),a=n||r||i||s,o=a?ye(e.length,String):[],c=o.length;for(var l in e)!t&&!Ye.call(e,l)||a&&("length"==l||i&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||xe(l,c))||o.push(l);return o},Je=Object.prototype;var Xe=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||Je)};var Ze=function(e,t){return function(n){return e(t(n))}}(Object.keys,Object),et=Object.prototype.hasOwnProperty;var tt=function(e){if(!Xe(e))return Ze(e);var t=[];for(var n in Object(e))et.call(e,n)&&"constructor"!=n&&t.push(n);return t};var nt=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};var rt=function(e){if(!nt(e))return!1;var t=ke(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t};var it=function(e){return null!=e&&Ge(e.length)&&!rt(e)};var st=function(e){return it(e)?Ke(e):tt(e)};var at=function(e,t){return function(n,r){if(null==n)return n;if(!it(n))return e(n,r);for(var i=n.length,s=t?i:-1,a=Object(n);(t?s--:++s<i)&&!1!==r(a[s],s,a););return n}}((function(e,t){return e&&me(e,t,st)}));var ot=function(e,t,n,r){return at(e,(function(e,i,s){t(r,e,n(e),s)})),r};var ct=function(){this.__data__=[],this.size=0};var lt=function(e,t){return e===t||e!=e&&t!=t};var ht=function(e,t){for(var n=e.length;n--;)if(lt(e[n][0],t))return n;return-1},ut=Array.prototype.splice;var dt=function(e){var t=this.__data__,n=ht(t,e);return!(n<0)&&(n==t.length-1?t.pop():ut.call(t,n,1),--this.size,!0)};var ft=function(e){var t=this.__data__,n=ht(t,e);return n<0?void 0:t[n][1]};var pt=function(e){return ht(this.__data__,e)>-1};var vt=function(e,t){var n=this.__data__,r=ht(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this};function mt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}mt.prototype.clear=ct,mt.prototype.delete=dt,mt.prototype.get=ft,mt.prototype.has=pt,mt.prototype.set=vt;var yt=mt;var bt=function(){this.__data__=new yt,this.size=0};var gt=function(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n};var Tt=function(e){return this.__data__.get(e)};var Et,It=function(e){return this.__data__.has(e)},Ot=Te["__core-js_shared__"],_t=(Et=/[^.]+$/.exec(Ot&&Ot.keys&&Ot.keys.IE_PROTO||""))?"Symbol(src)_1."+Et:"";var wt=function(e){return!!_t&&_t in e},At=Function.prototype.toString;var Ct=function(e){if(null!=e){try{return At.call(e)}catch(e){}try{return e+""}catch(e){}}return""},Rt=/^\[object .+?Constructor\]$/,St=Function.prototype,kt=Object.prototype,jt=St.toString,Nt=kt.hasOwnProperty,Bt=RegExp("^"+jt.call(Nt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Dt=function(e){return!(!nt(e)||wt(e))&&(rt(e)?Bt:Rt).test(Ct(e))};var Ut=function(e,t){return null==e?void 0:e[t]};var Pt=function(e,t){var n=Ut(e,t);return Dt(n)?n:void 0},Ft=Pt(Te,"Map"),qt=Pt(Object,"create");var Lt=function(){this.__data__=qt?qt(null):{},this.size=0};var Mt=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},xt=Object.prototype.hasOwnProperty;var Gt=function(e){var t=this.__data__;if(qt){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return xt.call(t,e)?t[e]:void 0},zt=Object.prototype.hasOwnProperty;var Ht=function(e){var t=this.__data__;return qt?void 0!==t[e]:zt.call(t,e)};var $t=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=qt&&void 0===t?"__lodash_hash_undefined__":t,this};function Wt(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Wt.prototype.clear=Lt,Wt.prototype.delete=Mt,Wt.prototype.get=Gt,Wt.prototype.has=Ht,Wt.prototype.set=$t;var Vt=Wt;var Qt=function(){this.size=0,this.__data__={hash:new Vt,map:new(Ft||yt),string:new Vt}};var Yt=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var Kt=function(e,t){var n=e.__data__;return Yt(t)?n["string"==typeof t?"string":"hash"]:n.map};var Jt=function(e){var t=Kt(this,e).delete(e);return this.size-=t?1:0,t};var Xt=function(e){return Kt(this,e).get(e)};var Zt=function(e){return Kt(this,e).has(e)};var en=function(e,t){var n=Kt(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this};function tn(e){var t=-1,n=null==e?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}tn.prototype.clear=Qt,tn.prototype.delete=Jt,tn.prototype.get=Xt,tn.prototype.has=Zt,tn.prototype.set=en;var nn=tn;var rn=function(e,t){var n=this.__data__;if(n instanceof yt){var r=n.__data__;if(!Ft||r.length<199)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new nn(r)}return n.set(e,t),this.size=n.size,this};function sn(e){var t=this.__data__=new yt(e);this.size=t.size}sn.prototype.clear=bt,sn.prototype.delete=gt,sn.prototype.get=Tt,sn.prototype.has=It,sn.prototype.set=rn;var an=sn;var on=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this};var cn=function(e){return this.__data__.has(e)};function ln(e){var t=-1,n=null==e?0:e.length;for(this.__data__=new nn;++t<n;)this.add(e[t])}ln.prototype.add=ln.prototype.push=on,ln.prototype.has=cn;var hn=ln;var un=function(e,t){for(var n=-1,r=null==e?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1};var dn=function(e,t){return e.has(t)};var fn=function(e,t,n,r,i,s){var a=1&n,o=e.length,c=t.length;if(o!=c&&!(a&&c>o))return!1;var l=s.get(e);if(l&&s.get(t))return l==t;var h=-1,u=!0,d=2&n?new hn:void 0;for(s.set(e,t),s.set(t,e);++h<o;){var f=e[h],p=t[h];if(r)var v=a?r(p,f,h,t,e,s):r(f,p,h,e,t,s);if(void 0!==v){if(v)continue;u=!1;break}if(d){if(!un(t,(function(e,t){if(!dn(d,t)&&(f===e||i(f,e,n,r,s)))return d.push(t)}))){u=!1;break}}else if(f!==p&&!i(f,p,n,r,s)){u=!1;break}}return s.delete(e),s.delete(t),u},pn=Te.Uint8Array;var vn=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n};var mn=function(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n},yn=Ee?Ee.prototype:void 0,bn=yn?yn.valueOf:void 0;var gn=function(e,t,n,r,i,s,a){switch(n){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!s(new pn(e),new pn(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return lt(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var o=vn;case"[object Set]":var c=1&r;if(o||(o=mn),e.size!=t.size&&!c)return!1;var l=a.get(e);if(l)return l==t;r|=2,a.set(e,t);var h=fn(o(e),o(t),r,i,s,a);return a.delete(e),h;case"[object Symbol]":if(bn)return bn.call(e)==bn.call(t)}return!1};var Tn=function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e};var En=function(e,t,n){var r=t(e);return Fe(e)?r:Tn(r,n(e))};var In=function(e,t){for(var n=-1,r=null==e?0:e.length,i=0,s=[];++n<r;){var a=e[n];t(a,n,e)&&(s[i++]=a)}return s};var On=function(){return[]},_n=Object.prototype.propertyIsEnumerable,wn=Object.getOwnPropertySymbols,An=wn?function(e){return null==e?[]:(e=Object(e),In(wn(e),(function(t){return _n.call(e,t)})))}:On;var Cn=function(e){return En(e,st,An)},Rn=Object.prototype.hasOwnProperty;var Sn=function(e,t,n,r,i,s){var a=1&n,o=Cn(e),c=o.length;if(c!=Cn(t).length&&!a)return!1;for(var l=c;l--;){var h=o[l];if(!(a?h in t:Rn.call(t,h)))return!1}var u=s.get(e);if(u&&s.get(t))return u==t;var d=!0;s.set(e,t),s.set(t,e);for(var f=a;++l<c;){var p=e[h=o[l]],v=t[h];if(r)var m=a?r(v,p,h,t,e,s):r(p,v,h,e,t,s);if(!(void 0===m?p===v||i(p,v,n,r,s):m)){d=!1;break}f||(f="constructor"==h)}if(d&&!f){var y=e.constructor,b=t.constructor;y==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof y&&y instanceof y&&"function"==typeof b&&b instanceof b||(d=!1)}return s.delete(e),s.delete(t),d},kn=Pt(Te,"DataView"),jn=Pt(Te,"Promise"),Nn=Pt(Te,"Set"),Bn=Pt(Te,"WeakMap"),Dn=Ct(kn),Un=Ct(Ft),Pn=Ct(jn),Fn=Ct(Nn),qn=Ct(Bn),Ln=ke;(kn&&"[object DataView]"!=Ln(new kn(new ArrayBuffer(1)))||Ft&&"[object Map]"!=Ln(new Ft)||jn&&"[object Promise]"!=Ln(jn.resolve())||Nn&&"[object Set]"!=Ln(new Nn)||Bn&&"[object WeakMap]"!=Ln(new Bn))&&(Ln=function(e){var t=ke(e),n="[object Object]"==t?e.constructor:void 0,r=n?Ct(n):"";if(r)switch(r){case Dn:return"[object DataView]";case Un:return"[object Map]";case Pn:return"[object Promise]";case Fn:return"[object Set]";case qn:return"[object WeakMap]"}return t});var Mn=Ln,xn=Object.prototype.hasOwnProperty;var Gn=function(e,t,n,r,i,s){var a=Fe(e),o=Fe(t),c=a?"[object Array]":Mn(e),l=o?"[object Array]":Mn(t),h="[object Object]"==(c="[object Arguments]"==c?"[object Object]":c),u="[object Object]"==(l="[object Arguments]"==l?"[object Object]":l),d=c==l;if(d&&Le(e)){if(!Le(t))return!1;a=!0,h=!1}if(d&&!h)return s||(s=new an),a||Qe(e)?fn(e,t,n,r,i,s):gn(e,t,c,n,r,i,s);if(!(1&n)){var f=h&&xn.call(e,"__wrapped__"),p=u&&xn.call(t,"__wrapped__");if(f||p){var v=f?e.value():e,m=p?t.value():t;return s||(s=new an),i(v,m,n,r,s)}}return!!d&&(s||(s=new an),Sn(e,t,n,r,i,s))};var zn=function e(t,n,r,i,s){return t===n||(null==t||null==n||!je(t)&&!je(n)?t!=t&&n!=n:Gn(t,n,r,i,e,s))};var Hn=function(e,t,n,r){var i=n.length,s=i,a=!r;if(null==e)return!s;for(e=Object(e);i--;){var o=n[i];if(a&&o[2]?o[1]!==e[o[0]]:!(o[0]in e))return!1}for(;++i<s;){var c=(o=n[i])[0],l=e[c],h=o[1];if(a&&o[2]){if(void 0===l&&!(c in e))return!1}else{var u=new an;if(r)var d=r(l,h,c,e,t,u);if(!(void 0===d?zn(h,l,3,r,u):d))return!1}}return!0};var $n=function(e){return e==e&&!nt(e)};var Wn=function(e){for(var t=st(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,$n(i)]}return t};var Vn=function(e,t){return function(n){return null!=n&&(n[e]===t&&(void 0!==t||e in Object(n)))}};var Qn=function(e){var t=Wn(e);return 1==t.length&&t[0][2]?Vn(t[0][0],t[0][1]):function(n){return n===e||Hn(n,e,t)}};var Yn=function(e){return"symbol"==typeof e||je(e)&&"[object Symbol]"==ke(e)},Kn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Jn=/^\w*$/;var Xn=function(e,t){if(Fe(e))return!1;var n=typeof e;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!Yn(e))||(Jn.test(e)||!Kn.test(e)||null!=t&&e in Object(t))};function Zn(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],s=n.cache;if(s.has(i))return s.get(i);var a=e.apply(this,r);return n.cache=s.set(i,a)||s,a};return n.cache=new(Zn.Cache||nn),n}Zn.Cache=nn;var er=Zn;var tr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,nr=/\\(\\)?/g,rr=function(e){var t=er(e,(function(e){return 500===n.size&&n.clear(),e})),n=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(tr,(function(e,n,r,i){t.push(r?i.replace(nr,"$1"):n||e)})),t}));var ir=function(e,t){for(var n=-1,r=null==e?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i},sr=Ee?Ee.prototype:void 0,ar=sr?sr.toString:void 0;var or=function e(t){if("string"==typeof t)return t;if(Fe(t))return ir(t,e)+"";if(Yn(t))return ar?ar.call(t):"";var n=t+"";return"0"==n&&1/t==-1/0?"-0":n};var cr=function(e){return null==e?"":or(e)};var lr=function(e,t){return Fe(e)?e:Xn(e,t)?[e]:rr(cr(e))};var hr=function(e){if("string"==typeof e||Yn(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t};var ur=function(e,t){for(var n=0,r=(t=lr(t,e)).length;null!=e&&n<r;)e=e[hr(t[n++])];return n&&n==r?e:void 0};var dr=function(e,t,n){var r=null==e?void 0:ur(e,t);return void 0===r?n:r};var fr=function(e,t){return null!=e&&t in Object(e)};var pr=function(e,t,n){for(var r=-1,i=(t=lr(t,e)).length,s=!1;++r<i;){var a=hr(t[r]);if(!(s=null!=e&&n(e,a)))break;e=e[a]}return s||++r!=i?s:!!(i=null==e?0:e.length)&&Ge(i)&&xe(a,i)&&(Fe(e)||Pe(e))};var vr=function(e,t){return null!=e&&pr(e,t,fr)};var mr=function(e,t){return Xn(e)&&$n(t)?Vn(hr(e),t):function(n){var r=dr(n,e);return void 0===r&&r===t?vr(n,e):zn(t,r,3)}};var yr=function(e){return e};var br=function(e){return function(t){return null==t?void 0:t[e]}};var gr=function(e){return function(t){return ur(t,e)}};var Tr=function(e){return Xn(e)?br(hr(e)):gr(e)};var Er=function(e){return"function"==typeof e?e:null==e?yr:"object"==typeof e?Fe(e)?mr(e[0],e[1]):Qn(e):Tr(e)};var Ir=function(e,t){return function(n,r){var i=Fe(n)?ve:ot,s=t?t():{};return i(n,e,Er(r),s)}}((function(e,t,n){e[n?0:1].push(t)}),(function(){return[[],[]]}));var Or=function(e,t,n,r){for(var i=e.length,s=n+(r?1:-1);r?s--:++s<i;)if(t(e[s],s,e))return s;return-1};var _r=function(e){return e!=e};var wr=function(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1};var Ar=function(e,t,n){return t==t?wr(e,t,n):Or(e,_r,n)};var Cr=function(e,t){return!!(null==e?0:e.length)&&Ar(e,t,0)>-1};var Rr=function(e,t,n){for(var r=-1,i=null==e?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1};var Sr=function(){},kr=Nn&&1/mn(new Nn([,-0]))[1]==1/0?function(e){return new Nn(e)}:Sr;var jr=function(e,t,n){var r=-1,i=Cr,s=e.length,a=!0,o=[],c=o;if(n)a=!1,i=Rr;else if(s>=200){var l=t?null:kr(e);if(l)return mn(l);a=!1,i=dn,c=new hn}else c=t?[]:o;e:for(;++r<s;){var h=e[r],u=t?t(h):h;if(h=n||0!==h?h:0,a&&u==u){for(var d=c.length;d--;)if(c[d]===u)continue e;t&&c.push(u),o.push(h)}else i(c,u,n)||(c!==o&&c.push(u),o.push(h))}return o};var Nr=function(e,t){return e&&e.length?jr(e,Er(t)):[]};function Br(e){if(e.length<2)return e;const t=[e[0]];for(let n=1;n<e.length;n++){const r=t.length-1,i=t[r],s=e[n];s[0]>i[1]?t.push(s):t[r]=[i[0],new Date(Math.max(+i[1],+s[1]))]}return t}class Dr extends K{constructor(e){super(),this.camerasStore=e,this.knownIntervals=k(),this.eventsById=new Map,this.updates=0,this.recentAdditions=[],this.update=e=>{e.forEach(e=>{const t=this.eventsById.get(e.id);t&&(t.endTime=e.endTime,this.data.remove(t=>t.id===e.id),this.data.add([t]))})},this.add=e=>{const t=e.filter(e=>!this.eventsById.has(e.id));t.forEach(e=>this.eventsById.set(e.id,e)),this.data.add(t),t.length&&this.updates++},this.processNewEvents=({data:e})=>{const t=Nr(e.filter(e=>this.camerasStore.camerasById.has(e.cameraId)).reverse(),"id").map(e=>new le(e)),[n,r]=Ir(t,e=>this.eventsById.has(e.id));this.update(n),this.add(r),r.length&&(this.recentAdditions=r.map(e=>e.id))},this.data=k(),this.eventsByCameraId=this.data.dimension(e=>e.cameraId),this.eventsByStart=this.data.dimension(e=>+e.startTime),this.eventsByEnd=this.data.dimension(e=>+e.endTime),this.eventsByType=this.data.dimension(e=>e.type),this.eventsByFoundObjects=this.data.dimension(e=>e.foundObjects.map(e=>e.Type),!0),this.eventsByColor=this.data.dimension(e=>e.foundObjects.reduce((e,t)=>e.concat(...t.Colors.map(e=>e.Color)),[]),!0),this.eventsByLiveliness=this.data.dimension(e=>e.isLive),this.pendingRequests=k(),this.pendingRequestsByStart=this.pendingRequests.dimension(e=>+e.startTime),this.pendingRequestsByEnd=this.pendingRequests.dimension(e=>+e.endTime),this.pendingRequestsByCameraId=this.pendingRequests.dimension(e=>e.cameraId),this.knownIntervalsByCameraId=this.knownIntervals.dimension(e=>e.cameraId),this.knownIntervalsByStart=this.knownIntervals.dimension(e=>+e.from),this.knownIntervalsByEnd=this.knownIntervals.dimension(e=>+e.to)}fetchEvents(e,t,n){n&&n>new Date&&(n=null);const r=null===n?new Date(Date.now()-6e5):n;-1===e?this.knownIntervalsByCameraId.filter(-1):this.knownIntervalsByCameraId.filter(t=>-1===t||t===e),this.knownIntervalsByStart.filter([-1/0,r]),this.knownIntervalsByEnd.filter([t,1/0]);const i=this.knownIntervalsByStart.bottom(1/0),s=[];if(this.knownIntervalsByCameraId.filterAll(),this.knownIntervalsByStart.filterAll(),this.knownIntervalsByEnd.filterAll(),i.length){const a=Br(i.map(e=>[e.from,e.to]));a[0][0]>t&&s.push([t,a[0][0]]);for(let e=0;e<a.length-1;e++)s.push([a[e][1],a[e+1][0]]);a[Br.length-1][1]<r&&s.push([a[Br.length-1][1],r]),s.length&&(t=s[0][0],+s[s.length-1][1]<=+r&&(n=s[s.length-1][1]),this.knownIntervals.add([{cameraId:e,from:t,to:r}]))}else this.knownIntervals.add([{cameraId:e,from:t,to:r}]);this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(r);const a=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),a)return a.request;if(i.length&&!s.length)return c([]);const o=this.api.cameras.GetMotionEvents({cameraId:e,startTime:t,endTime:n}).pipe(p(e=>e.success?c(e.motionEventItems.map(e=>new le(e))):(console.error(e.error),l(e.error))),R());return this.pendingRequests.add([{cameraId:e,startTime:t,endTime:n||new Date,request:o}]),o.pipe(A(()=>this.pendingRequests.remove(e=>e.request===o))).subscribe(this.add),o}getEvents({cameraIds:e,from:t,to:n,objectType:r,colors:i}){this.eventsByStart.filter([+t,n?+n+5e-4:1/0]),r&&this.eventsByFoundObjects.filter(e=>r.includes(e)),e&&this.eventsByCameraId.filter(t=>e.includes(t)),i&&this.eventsByColor.filter(e=>i.has(e));const s=this.eventsByStart.top(1/0);return e&&this.eventsByCameraId.filterAll(),r&&this.eventsByFoundObjects.filterAll(),i&&this.eventsByColor.filterAll(),this.eventsByStart.filterAll(),s}getOverlappedEvents({cameraId:e,from:t,to:n}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([-1/0,+n+5e-4]),this.eventsByLiveliness.filterExact(!0);const r=this.eventsByStart.top(1/0);this.eventsByLiveliness.filterAll(),this.eventsByEnd.filter([+t,1/0]);const i=this.eventsByStart.top(1/0);return this.eventsByCameraId.filterAll(),this.eventsByStart.filterAll(),this.eventsByStart.filterAll(),i.concat(r)}getLastBefore({cameraId:e,date:t}){this.eventsByCameraId.filter(e),this.eventsByEnd.filter([-1/0,+t]),this.eventsByLiveliness.filter(!1),this.eventsByType.filter(se.Default);const n=this.eventsByEnd.top(1);return this.eventsByCameraId.filterAll(),this.eventsByEnd.filterAll(),this.eventsByLiveliness.filterAll(),this.eventsByType.filterAll(),n[0]}getFirstAfter({cameraId:e,date:t}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([+t+5e-4,1/0]),this.eventsByType.filter(se.Default);const n=this.eventsByEnd.bottom(1);return this.eventsByCameraId.filterAll(),this.eventsByStart.filterAll(),this.eventsByType.filterAll(),n[0]}afterInit(){this.api.events.pipe(g(({hub:e,event:t})=>"cameras"===e&&"OnCameraMotionEvent"===t)).subscribe(this.processNewEvents)}}j([e],Dr.prototype,"updates",void 0),j([e.ref],Dr.prototype,"recentAdditions",void 0),j([n],Dr.prototype,"update",void 0),j([n],Dr.prototype,"add",void 0);class Ur extends K{constructor(){super(),this.toThumbnail=e=>({realtimestamp:t,url:n,width:r,height:i})=>({cameraId:e,url:n,width:r,height:i,timestamp:new Date(t)}),this.thumbnails=k(),this.thumbnailsByCameraId=this.thumbnails.dimension(e=>e.cameraId),this.thumbnailsByDate=this.thumbnails.dimension(e=>+e.timestamp),this.pendingRequests=k(),this.pendingRequestsByStart=this.pendingRequests.dimension(e=>+e.from),this.pendingRequestsByEnd=this.pendingRequests.dimension(e=>+e.to),this.pendingRequestsByCameraId=this.pendingRequests.dimension(e=>e.cameraId),this.pendingRequestsByCount=this.pendingRequests.dimension(e=>e.count)}fetchThumbnails(e,t,n,r){this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(n),this.pendingRequestsByCount.filter(r);const i=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),this.pendingRequestsByCount.filterAll(),i)return i.request;const s=this.api.thumbnails.GetThumbnailsInfo({cameraId:e,from:t,to:n,count:r}).pipe(w(e=>e.resultItems),_());return this.pendingRequests.add([{cameraId:e,from:t,to:n,count:r,request:s}]),s.subscribe(t=>{const n=t.filter(e=>e.url).map(this.toThumbnail(e));this.thumbnails.add(n),this.pendingRequests.remove(e=>e.request===s)}),s}getIntervalState(e,t,n){const r=this.getThumbnail({cameraId:e,from:t,to:n});if(r)return{state:"fullfilled",data:r};this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter([-1/0,+n+5e-4]),this.pendingRequestsByEnd.filter([t,1/0]);let i=this.pendingRequests.allFiltered();return this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),i=i.filter(e=>1===e.count?+e.from==+t&&+e.to==+n:Math.abs((+e.to-+e.from)/e.count-(+n-+t))<=1),i.length?{state:"pending",request:i[0].request}:null}fetchThumbnail(e,t,n){const r=this.getIntervalState(e,t,n);if(null!==r){if("fullfilled"===r.state)return c(r.data);if("pending"===r.state)return r.request.pipe(w(()=>this.getThumbnail({cameraId:e,from:t,to:n})))}const i=this.api.thumbnails.GetThumbnailInfo({cameraId:e,from:t,to:n}).pipe(w(e=>e.resultItems),_());return i.subscribe(t=>{const n=t.filter(e=>e.url).map(this.toThumbnail(e));this.thumbnails.add(n),this.pendingRequests.remove(e=>e.request===i)}),this.pendingRequests.add([{cameraId:e,from:t,to:n,count:1,request:i}]),i.pipe(w(()=>this.getThumbnail({cameraId:e,from:t,to:n})))}getThumbnail({cameraId:e,from:t,to:n}){this.thumbnailsByCameraId.filter(e),this.thumbnailsByDate.filter([+t,+n+(+t==+n?5e-4:0)]);const r=this.thumbnails.allFiltered()[0];return this.thumbnailsByDate.filterAll(),this.thumbnailsByCameraId.filterAll(),r}getThumbnails({cameraId:e,from:t,to:n}){this.thumbnailsByCameraId.filter(e),this.thumbnailsByDate.filter([+t,+n+5e-4]);const r=this.thumbnails.allFiltered();return this.thumbnailsByDate.filterAll(),this.thumbnailsByCameraId.filterAll(),r}}class Pr{constructor(){this.cameras=new ce,this.archives=new Z,this.events=new Dr(this.cameras),this.eventSchema=new pe,this.thumbnails=new Ur,this.account=new J,this.eventList=new he(this.events),s(()=>!!this.account.user,()=>{this.cameras.fetch()}),s(()=>this.cameras.loaded,()=>{this.eventList.load()})}init({token:e,apiUrl:t="https://services.3deye.me/reactiveapi",tokenServiceUrl:n="https://admin.3deye.me/token",widgetTokenServiceUrl:r="https://admin.3deye.me/widget/token"}){const i=e.clientId||"WebApp",s=new H;s.setItem("@3deye-toolkit/token",JSON.stringify(e)),this.auth=new z({widgetTokenServiceUrl:r,tokenServiceUrl:n,tokenStorageKey:"@3deye-toolkit/token",storage:s,clientId:i,deviceInfo:null}),this.api=q.create(D,this.auth,e=>S(t,{qs:{access_token:e}})),this.cameras.initWith(this.api),this.archives.initWith(this.api),this.events.initWith(this.api),this.eventSchema.initWith(this.api),this.thumbnails.initWith(this.api),this.account.initWith(this.api),this.account.setAuthStore(this.auth)}}j([e],Pr.prototype,"isFullscreen",void 0);const Fr=new Pr;export{Fr as app};
1
+ import{reaction as e,computed as t,runInAction as r,makeObservable as i,observable as n,action as a,when as s}from"mobx";import{Subject as o,BehaviorSubject as l,switchMap as c,EMPTY as u,timer as d,filter as h,delay as f,take as b,mergeMap as p,catchError as v,throwError as m,takeUntil as y,Observable as g,of as w,retryWhen as O,startWith as j,pairwise as P,concatMap as I,Subscription as A,share as k,shareReplay as T,skip as B,exhaustMap as S,map as C}from"rxjs";import _ from"jqueryless-signalr";import{StatusCodes as E}from"http-status-codes";import{mergeMap as R,shareReplay as D,retry as U,filter as q,map as M,tap as x,expand as N,last as F,share as z}from"rxjs/operators";import G from"crossfilter2";import L from"string-natural-compare";import"date-fns/esm";import $ from"i18next";import W from"react";const V={archives:{PopulateArchive:null,GetArchives:null,GetClips:null,UpdateClip:null,DeleteClip:null,SaveClip:null,SaveTimelaps:null,SaveArchive:null,DeleteArchive:null,ShareClip:null,GetSharedClips:null,UpdateSharedClip:null,DeleteSharedClip:null},cameras:{GetCameras:null,UpdateCamera:null,GetSensorDataSchema:null,GetSensorEvents:null,GetSensorEventsPage:null,GetLicensePlateLookUp:null,GetSensorEventsLprPage:null,GetPeopleCountingData:null,AddUserSensorEvent:null,AcknowledgeSensorEvent:null,MoveCamera:null,MoveCameraContinuousStart:null,MoveCameraContinuousStop:null,GoHomePtzCamera:null,SetHomePtzCamera:null},camgroups:{GetCamgroups:null,DeleteCamgroup:null,AddCamgroup:null,UpdateCamgroup:null},sound:{GetPushSoundServiceUrl:null},thumbnails:{GetThumbnailsInfo:null,GetThumbnailInfo:null,GetHeatMapsInfo:null},users:{GetUser:null,UserUpdateProfile:null}},H={cameras:[{name:"OnCameraMotionEvent",explicit:!0},{name:"OnCameraAdded"},{name:"OnCameraUpdated"},{name:"OnSystemCameraUpdated"},{name:"OnCameraDeleted"}],users:[{name:"OnUserUpdateProfile"}],camgroups:[{name:"OnAdd"},{name:"OnUpdate"},{name:"OnDelete"}],archives:[{name:"OnTimelapsAdded"},{name:"OnClipAdded"},{name:"OnClipUpdated"},{name:"OnClipDeleted"},{name:"OnArchiveAdded"},{name:"OnArchiveUpdated"},{name:"OnArchiveDeleted"},{name:"OnArchiveRecordCreated"}]};var J,K;!function(e){e[e.CONNECTING=0]="CONNECTING",e[e.CONNECTED=1]="CONNECTED",e[e.RECONNECTING=2]="RECONNECTING",e[e.DISCONNECTED=3]="DISCONNECTED"}(J||(J={}));class Z{static create(e,t,r){return new Z(null!==e?e:V,t,r)}constructor(t,r,i){Object.defineProperty(this,"connectionShutdown$",{enumerable:!0,configurable:!0,writable:!0,value:new o}),Object.defineProperty(this,"connection$",{enumerable:!0,configurable:!0,writable:!0,value:new l(null)}),Object.defineProperty(this,"events",{enumerable:!0,configurable:!0,writable:!0,value:new o}),Object.defineProperty(this,"logging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"authStore",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createConnection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiConfig",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.apiConfig=t,this.init(),this.createConnection=i,this.authStore=r,e((()=>r.token),(e=>{if(!e)return void this.shutdownConnection();if(e.invalid)return;if(!e.accessToken)return;const t=this.connection$.getValue();t&&t.state!==J.DISCONNECTED?t.qs.access_token=e.accessToken:this.connect(e)})),this.connection$.pipe(c((e=>null!==e||!r.isAuthenticated||r.token&&r.token.invalid?u:(this.logging&&console.warn("disconnected by some reason"),d(5e3)))),h((()=>r.isAuthenticated&&!!r.token&&!r.token.invalid))).subscribe((()=>{this.connect(r.token),this.logging&&console.warn("attempting to reconnect")})),this.connection$.pipe(h(Boolean),f(100)).subscribe(this.subscribeToEvents)}connect(e){if(this.connection$.getValue()&&this.connection$.getValue().state===J.CONNECTED)return;const{accessToken:t}=e,r=this.createConnection(t);Object.keys(this.apiConfig).forEach((e=>r.createHubProxy(e))),Object.entries(H).forEach((([e,t])=>{t&&r.proxies[e]&&t.forEach((({name:t})=>{r.proxies[e].on(t,(r=>this.events.next({hub:e,event:t,data:r})))}))})),r.start().done((()=>{this.logging&&console.warn("connected"),this.connection$.next(r)})).fail((e=>{var t,r,i;401!==(null===(t=e.source)||void 0===t?void 0:t.status)&&403!==(null===(r=e.source)||void 0===r?void 0:r.status)&&409!==(null===(i=e.source)||void 0===i?void 0:i.status)||this.authStore.invalidateToken()})),r.error((e=>{if(e.source&&(401===e.source.status||403===e.source.status||409===e.source.status))return this.logging&&console.warn("authentication error, invalidating token"),this.authStore.invalidateToken()})),r.disconnected((()=>{this.connection$.getValue()?this.logging&&console.warn("disconnected",this.connection$.getValue().lastError):this.logging&&console.warn("disconnected. this connection is already null"),this.connection$.next(null)})),r.reconnecting((()=>console.log("reconnecting"))),r.reconnected((()=>{this.connection$.getValue()===r&&(this.logging&&console.warn("reconnected"),this.connection$.next(r))}))}shutdownConnection(){const e=this.connection$.getValue();e&&e.stop(),this.connectionShutdown$.next(null)}init(){Object.keys(this.apiConfig).forEach((e=>{this[e]={},Object.keys(this.apiConfig[e]).forEach((t=>{this[e][t]=this.createHubMethod(e,t)}))}))}createHubMethod(e,t){const r=this;return function i(...n){return r.connection$.pipe(h(Boolean),h((e=>e.state===J.CONNECTED)),b(1)).pipe(p((r=>new Promise(((i,a)=>{r.proxies[e].invoke(t,...n).done((e=>i(e))).fail((e=>a(e)))})))),v((e=>!e.message||"Connection started reconnecting before invocation result was received."!==e.message&&"Connection was disconnected before invocation result was received."!==e.message?e.message&&e.message.startsWith("Caller is not authorized to invoke the ")?(console.warn(e.message),r.connection$.getValue().stop(),r.authStore.invalidateToken(),i(...n)):m(e):(console.warn(e.message),i(...n)))),y(r.connectionShutdown$))}}subscribeToEvents(e){Object.entries(H).forEach((([t,r])=>{r&&e.proxies[t]&&e.state===J.CONNECTED&&r.filter((({explicit:e})=>e)).forEach((({name:r})=>{e.proxies[t].invoke("SubscribeToEvent",r)}))}))}}class Y{constructor(e){Object.defineProperty(this,"accessToken",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"accessTokenExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"accessTokenIssued",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"expiresIn",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"refreshToken",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"refreshTokenExpires",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"refreshTokenIssued",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokenType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"userName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"invalid",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"widgetId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"widgetToken",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"json",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.json=e,this.accessToken=e.access_token||e.accessToken,this.accessTokenExpires=new Date(e.access_token_expires||e.accessTokenExpires),this.accessTokenIssued=new Date(e.access_token_issued||e.accessTokenIssued),this.clientId=e.client_id||e.clientId,this.expiresIn=e.expires_in||e.expiresIn,this.refreshToken=e.refresh_token||e.refreshToken,this.refreshTokenExpires=new Date(e.refresh_token_expires||e.refreshTokenExpires),this.refreshTokenIssued=new Date(e.refresh_token_issued||e.refreshTokenIssued),this.tokenType=e.token_type||e.tokenType,this.userName=e.userName,this.widgetId=e.widgetId,this.widgetToken=e.widgetToken,this.invalid=!1}}class Q{get isAuthenticated(){return Boolean(this.token&&!this.isAuthenticating)}constructor({tokenServiceUrl:e,storage:s,tokenStorageKey:o,deviceInfo:l,clientId:f}){Object.defineProperty(this,"token",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isAuthenticating",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokenServiceUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokenStorageKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"deviceInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clientId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingUpdateTokenRequest",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"signOut",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.isAuthenticating||r((()=>this.token=null))}}),Object.defineProperty(this,"signIn",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if(this.isAuthenticating)return;r((()=>this.isAuthenticating=!0)),!1===e.agreedWithTerms&&(e={...e,agreedWithTerms:void 0});return this.fetchToken(e).then((e=>(r((()=>{this.token=e,this.isAuthenticating=!1})),e))).catch((e=>{throw r((()=>{this.isAuthenticating=!1})),e}))}}),Object.defineProperty(this,"invalidateToken",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.token&&r((()=>{this.token={...this.token,invalid:!0}}))}}),i(this,{token:n.ref,isAuthenticating:n,isAuthenticated:t,signOut:a,invalidateToken:a}),this.isAuthenticating=!0,this.storage=s,this.tokenServiceUrl=e,this.tokenStorageKey=o,this.deviceInfo=l,this.clientId=f;const b=function(e,r=!1){const i=t(e);return new g((e=>{const t=i.observe_((({newValue:t})=>e.next(t)),r);return()=>t()}))}((()=>this.token)),y=b.pipe(c((e=>{if(null===e)return u;const t=w(e).pipe(p((e=>e.widgetId?this.fetchWidgetToken(e):this.updateToken(e.refreshToken))),O((e=>e.pipe(p(((e,t)=>e.status&&![500,502,503,504].includes(e.status)?m((()=>e)):d(2**Math.min(t+1,6)*1e3)))))));if(!e.invalid){const r=Math.max(.75*(+e.accessTokenExpires-Date.now()),0);return d(r).pipe(p((()=>t)))}return t})),v((e=>(console.error(e),r((()=>this.token=null)),y))));y.subscribe((e=>{r((()=>this.token=e))})),b.pipe(j(null),P(),h((([e,t])=>!!(t||!t&&e))),I((([,e])=>this.storeToken(e)))).subscribe(),this.getInitialToken().then((e=>{r((()=>{this.token=e,this.isAuthenticating=!1}))}))}async getTokenFromStorage(){const e=await this.storage.getItem(this.tokenStorageKey);return e?new Y(JSON.parse(e)):null}async storeToken(e){return!e||e.invalid?this.storage.removeItem(this.tokenStorageKey):this.storage.setItem(this.tokenStorageKey,JSON.stringify(e.json))}async getInitialToken(){const e=await this.getTokenFromStorage();return e||null}async fetchToken(e){const t={clientId:this.clientId,device:this.deviceInfo,...e},r=new Headers;r.append("Content-Type","application/json"),r.append("accept","application/json");const i=await fetch(this.tokenServiceUrl,{method:"POST",headers:r,body:JSON.stringify(t)});try{const e=await i.json();return 200!==i.status?Promise.reject({status:i.status,data:e}):new Y(e)}catch(e){return Promise.reject(i)}}async updateToken(e){var t;try{return this.pendingUpdateTokenRequest&&this.pendingUpdateTokenRequest.refreshToken===e||(this.pendingUpdateTokenRequest={refreshToken:e,request:this.fetchToken({refreshToken:e})}),await this.pendingUpdateTokenRequest.request}finally{(null===(t=this.pendingUpdateTokenRequest)||void 0===t?void 0:t.refreshToken)===e&&(this.pendingUpdateTokenRequest=null)}}async fetchWidgetToken(e){const{widgetId:t,widgetToken:r}=e;if(!t||!r)throw new Error("token must contain widgetId and widgetToken");const i={widgetId:t,widgetToken:r},n=new Headers;n.append("Content-Type","application/json"),n.append("accept","application/json");const a=await fetch(this.tokenServiceUrl,{method:"POST",headers:n,body:JSON.stringify(i)});try{const e=await a.json();return 200!==a.status?Promise.reject({status:a.status,data:e}):new Y({widgetId:t,widgetToken:r,...e})}catch(e){return Promise.reject(a)}}}!function(e){e[e.Motion=0]="Motion",e[e.Tampering=1]="Tampering",e[e.PanTiltZoom=2]="PanTiltZoom",e[e.CrossLine=3]="CrossLine",e[e.Intrusion=4]="Intrusion",e[e.LicensePlate=5]="LicensePlate",e[e.FaceDetection=6]="FaceDetection",e[e.Audio=7]="Audio",e[e.Analytic=8]="Analytic",e[e.SpeedDetection=9]="SpeedDetection",e[e.PeopleCounter=10]="PeopleCounter",e[e.Temperature=11]="Temperature",e[e.PoS=12]="PoS",e[e.GPS=13]="GPS",e[e.DigitalInput=14]="DigitalInput",e[e.Normal=15]="Normal",e[e.Suspicious=16]="Suspicious",e[e.Loitering=17]="Loitering",e[e.Vandalism=18]="Vandalism",e[e.Trespass=19]="Trespass",e[e.Emergency=20]="Emergency",e[e.LifeInDanger=21]="LifeInDanger",e[e.ErroneousAlert=22]="ErroneousAlert",e[e.Misidentification=23]="Misidentification",e[e.Fire=24]="Fire",e[e.MedicalDuress=25]="MedicalDuress",e[e.HoldUp=26]="HoldUp",e[e.CheckIn=27]="CheckIn",e[e.CheckOut=28]="CheckOut",e[e.ClockIn=29]="ClockIn",e[e.ClockOut=30]="ClockOut",e[e.ParkingStart=31]="ParkingStart",e[e.ParkingEnd=32]="ParkingEnd",e[e.ParkingViolation=33]="ParkingViolation",e[e.GateAccess=34]="GateAccess",e[e.DoorAccess=35]="DoorAccess",e[e.TemperatureCheck=36]="TemperatureCheck",e[e.IDCheck=37]="IDCheck",e[e.PPECheck=38]="PPECheck",e[e.WelfareCheck=39]="WelfareCheck",e[e.Uncategorized=40]="Uncategorized",e[e.Unknown=999]="Unknown"}(K||(K={}));class X{constructor(){Object.defineProperty(this,"values",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}getItem(e){return this.values.get(e)||null}setItem(e,t){this.values.set(e,t)}removeItem(e){this.values.delete(e)}}let ee=[];class te{constructor(){Object.defineProperty(this,"api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"disposables",{enumerable:!0,configurable:!0,writable:!0,value:[]})}initWith(e){this.api=e,this.afterInit&&this.afterInit()}dispose(){this.disposables.forEach((e=>{e instanceof A?e.closed||e.unsubscribe():e()}))}}var re;!function(e){e.DEFAULT_VIDEO_RESIZE_MODE="defaultVideoResizeMode",e.RESIZE_MODE_PER_CAMERA="camerasResizeMode",e.FISHEYE_CAMERAS="fisheyeCameras"}(re||(re={}));class ie extends te{constructor(e){super(),Object.defineProperty(this,"notification",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"user",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"auth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setUser",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.user=e}}),Object.defineProperty(this,"updateCustomPreferences",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=w(null).pipe(R((()=>{if(!this.user)return m((()=>"user is not initialized"));const t={id:this.user.id,jsonField:JSON.stringify({...JSON.parse(this.user.jsonField||"{}"),...e}),version:this.user.version};return this.api.users.UserUpdateProfile(t)})),R((e=>e.success?w(e.resultItems[0]):m((()=>e.error)))),this.retryOnVersionMismatch(),D());return t.subscribe((e=>{this.setUser(e)})),t}}),Object.defineProperty(this,"getPreference",{enumerable:!0,configurable:!0,writable:!0,value:e=>{var t;try{return JSON.parse((null===(t=this.user)||void 0===t?void 0:t.jsonField)||"{}")[e]}catch{return null}}}),Object.defineProperty(this,"retryOnVersionMismatch",{enumerable:!0,configurable:!0,writable:!0,value:()=>U({delay:(e,t)=>t>1?m((()=>e)):-4===e.code?this.loadUser$():m((()=>e))})}),i(this,{user:n.ref,setUser:a,userDisplayName:t})}get userDisplayName(){return this.user?this.user.firstName&&this.user.firstName.trim()||this.user.lastName&&this.user.lastName.trim()?[this.user.firstName,this.user.lastName].filter(Boolean).join(" ").trim():this.user.email:null}afterInit(){this.disposables.push(this.api.events.pipe(q((({hub:e,event:t})=>"users"===e&&"OnUserUpdateProfile"===t)),M((({data:e})=>e.resultItems[0]))).subscribe(this.setUser))}loadUser$(){return this.api.users.GetUser().pipe(R((e=>e.success?w(e.resultItems[0]):m((()=>e.error)))),x(this.setUser),D(1))}setAuthStore(t){this.auth=t,this.disposables.push(e((()=>this.auth.isAuthenticated),(()=>{this.auth.isAuthenticated&&this.loadUser$().subscribe()})))}async updateUserPassword(e){var t,r;const i=(Array.isArray(ee)?ee[0]:ee).changePasswordUrl,n=null===(r=null===(t=this.auth)||void 0===t?void 0:t.token)||void 0===r?void 0:r.accessToken,a=JSON.stringify({currentPassword:e.previous,newPassword:e.new}),s=new Headers;s.append("content-type","application/json"),s.append("accept","application/json"),s.append("authorization",`bearer ${n}`);const o=await fetch(i,{method:"PUT",headers:s,body:a}),{status:l}=o;if(l!==E.OK){const e=await o.json();throw new Error(e.errors[0].message)}}updateUserSettings({firstName:e,lastName:t}){const r=w(null).pipe(R((()=>{if(!this.user)throw new Error("user is not initialized");return this.api.users.UserUpdateProfile({id:this.user.id,firstName:e,lastName:t,version:this.user.version})})),R((e=>e.success?w(e.resultItems[0]):m((()=>e.error)))),this.retryOnVersionMismatch(),D());return r.subscribe((e=>{this.setUser(e)})),r}setDefaultGroup(e){const t=w(null).pipe(R((()=>{if(!this.user)return m((()=>"user is not initialized"));const t={id:this.user.id,layoutStartId:e,layoutStartType:"camgroup",version:this.user.version};return this.api.users.UserUpdateProfile(t)})),R((e=>e.success?w(e.resultItems[0]):m((()=>e.error)))),this.retryOnVersionMismatch(),D());return t.subscribe({next:e=>{var t;this.setUser(e),null===(t=this.notification)||void 0===t||t.success("Successfully set default group")},error:e=>{var t;console.error(e),null===(t=this.notification)||void 0===t||t.error(e.message)}}),t}}class ne{constructor(e){Object.defineProperty(this,"json",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"startTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"endTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streamUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"duration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isLive",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"cameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.json=JSON.stringify(e,null,2),this.startTime=new Date(e.startTime),this.endTime=new Date(e.endTime),this.streamUrl=e.streamUrl,this.cameraId=e.cameraId,this.duration=e.duration,this.id=e.id}}class ae extends te{constructor(e){super(),Object.defineProperty(this,"camerasStore",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chunksByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chunksByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chunksByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chunksById",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"pendingRequests",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"knownIntervals",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"updates",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"getClosestChunkRight",{enumerable:!0,configurable:!0,writable:!0,value:({cameraId:e,time:t})=>{this.chunksByCameraId.filter(e),this.chunksByEnd.filter([t,1/0]);const r=this.chunksByStart.bottom(1);return this.chunksByCameraId.filterAll(),this.chunksByEnd.filterAll(),r[0]}}),Object.defineProperty(this,"getClosestChunkLeft",{enumerable:!0,configurable:!0,writable:!0,value:({cameraId:e,time:t})=>{this.chunksByCameraId.filter(e),this.chunksByStart.filter([-1/0,+t+5e-4]);const r=this.chunksByStart.top(1);return this.chunksByCameraId.filterAll(),this.chunksByEnd.filterAll(),r[0]}}),Object.defineProperty(this,"fetchNextChunk",{enumerable:!0,configurable:!0,writable:!0,value:({cameraId:e,time:t})=>{if(this.knownIntervals.has(e)){const[r,i]=this.knownIntervals.get(e);if(r<=t&&i>=t){const r=this.getClosestChunkRight({cameraId:e,time:t});if(r)return w(r)}}return w({result:[],time:t}).pipe(N((({result:t,time:r})=>{if(t.length||r>=new Date)return u;const i=new Date(+r+36e5);return this.fetch(e,r,i).pipe(M((e=>({result:e,time:i}))))})),F(),M((()=>this.getClosestChunkRight({cameraId:e,time:t}))))}}),Object.defineProperty(this,"fetchPrevChunk",{enumerable:!0,configurable:!0,writable:!0,value:({cameraId:e,time:t})=>{if(this.knownIntervals.has(e)){const[r,i]=this.knownIntervals.get(e);if(r<=t&&i>=t){const r=this.getClosestChunkLeft({cameraId:e,time:t});if(r)return w(r)}}const r=this.camerasStore.camerasById.get(e);if(!r)return w(void 0);const i=new Date(Date.now()-3600*r.archiveDuration*1e3);return this.knownIntervals.get(e)&&this.knownIntervals.get(e)[0]<=i?w(void 0):w({result:[],time:t}).pipe(N((({result:t,time:r})=>{if(t.length||r<=i)return u;const n=new Date(Math.max(+r-36e5,+i));return this.fetch(e,n,r).pipe(M((e=>({result:e,time:n}))))})),F(),M((()=>this.getClosestChunkRight({cameraId:e,time:t}))))}}),i(this,{updates:n,add:a.bound}),this.data=G(),this.chunksByCameraId=this.data.dimension((e=>e.cameraId)),this.chunksByStart=this.data.dimension((e=>+e.startTime)),this.chunksByEnd=this.data.dimension((e=>+e.endTime)),this.pendingRequests=G(),this.pendingRequestsByStart=this.pendingRequests.dimension((e=>+e.startTime)),this.pendingRequestsByEnd=this.pendingRequests.dimension((e=>+e.endTime)),this.pendingRequestsByCameraId=this.pendingRequests.dimension((e=>e.cameraId))}fetch(e,t,r){this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(r);const i=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),i)return i.request;if(this.knownIntervals.has(e)){const[i,n]=this.knownIntervals.get(e);if(i<=t&&n>=r)return w(this.getChunks({cameraId:e,from:t,to:r}));i<=t&&n<r&&(t=n),i>t&&n>=r&&(r=i),r<i&&(r=i),t>n&&(t=n)}const n=this.api.archives.PopulateArchive({cameraId:e,startTime:t,endTime:r}).pipe(M((e=>e.resultItems[0].chunks.map((e=>new ne(e))))),x(this.add),x((r=>this.extendKnownInterval(e,t,r))),D());return this.pendingRequests.add([{cameraId:e,startTime:t,endTime:r,request:n}]),n.pipe(x((()=>this.pendingRequests.remove((e=>e.request===n))))).subscribe(),n}extendKnownInterval(e,t,r){t=new Date(Math.min(+t,...r.map((e=>+e.startTime))));const i=new Date(Math.max(...r.map((e=>+e.endTime))));if(this.knownIntervals.has(e)){const r=this.knownIntervals.get(e);t<r[0]&&(r[0]=t),i>r[1]&&(r[1]=i)}else this.knownIntervals.set(e,[t,i])}add(e){const t=e.filter((e=>!this.chunksById.has(e.id)));t.forEach((e=>this.chunksById.set(e.id,e))),this.data.add(t),t.length&&this.updates++}getChunks({cameraId:e,from:t,to:r}){this.chunksByStart.filter([-1/0,+r+5e-4]),this.chunksByEnd.filter([t,1/0]),e&&this.chunksByCameraId.filter(e);const i=this.chunksByStart.top(1/0);return e&&this.chunksByCameraId.filterAll(),this.chunksByStart.filterAll(),this.chunksByEnd.filterAll(),i}afterInit(){this.api.events.pipe(q((({hub:e,event:t})=>"archives"===e&&"OnArchiveChunksCreated"===t))).subscribe((({data:e})=>{this.add(e.resultItems.map((e=>new ne(e))))}))}}class se{get isOnline(){return this.enabled&&"Started"===this.state}get supportsWebRTC(){return!!this.webRtcUrl}constructor(e){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"imageUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"streamUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dashStreamUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"address",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"archiveDuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dvrWindowLength",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stateUpdatedAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"enabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isMicEnabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"webRtcUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isPtz",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"permissions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"update",{enumerable:!0,configurable:!0,writable:!0,value: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)}}),i(this,{name:n,streamUrl:n,dashStreamUrl:n,enabled:n,isMicEnabled:n,state:n,pin:n,webRtcUrl:n,permissions:n,isOnline:t,update:a}),this.update(e)}}var oe;!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"}(oe||(oe={}));class le extends te{constructor(){super(),Object.defineProperty(this,"camerasById",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"loading",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"loaded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"load",{enumerable:!0,configurable:!0,writable:!0,value:()=>{if(this.loaded)return;r((()=>this.loading=!0));const e=this.api.cameras.GetCameras({},null).pipe(p((e=>e.success?w(e.resultItems):(console.error(e.error),m((()=>e.error))))),k());return e.subscribe((e=>{r((()=>{this.add(e),this.loading=!1,this.loaded=!0}))})),e}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:e=>{e.forEach((e=>{this.camerasById.has(e.id)?this.camerasById.get(e.id).update(e):this.camerasById.set(e.id,new se(e))})),this.data=Array.from(this.camerasById.values()).sort(((e,t)=>L(e.name,t.name,{caseInsensitive:!0})))}}),Object.defineProperty(this,"sync",{enumerable:!0,configurable:!0,writable:!0,value:()=>{const e=this.data.reduce(((e,t)=>Math.max(e,+t.stateUpdatedAt)),0);if(!e)return u;const t=this.api.cameras.GetCameras({},new Date(1e3*(Math.floor(e/1e3)+1))).pipe(p((e=>e.success?w(e.resultItems):(console.error(e.error),m((()=>e.error))))),T(1));return t.subscribe((e=>this.add(e))),t}}),i(this,{data:n.ref,loading:n,loaded:n,add:a}),this.disposables.push(s((()=>this.loaded),(()=>{this.api.connection$.pipe(B(1),S((()=>this.sync()))).subscribe()})))}afterInit(){this.disposables.push(this.api.events.pipe(h((({hub:e,event:t})=>"cameras"===e&&("OnCameraUpdated"===t||"OnSystemCameraUpdated"===t))),C((({data:e,event:t})=>e.resultItems?{data:e.resultItems[0],event:t}:{data:e,event:t}))).subscribe((({data:e,event:t})=>{const r=this.camerasById.get(e.id);if(!r)return console.warn("got update for unknown camera:",e.id);if("OnSystemCameraUpdated"===t){const t=r.raw;for(const[r,i]of Object.entries(e))null===i&&(e[r]=t[r])}r.update(e)})))}dispose(){super.dispose(),this.camerasById.clear(),this.data=[]}}const ce={amber:{50:"#fff8e1",100:"#ffecb3",200:"#ffe082",300:"#ffd54f",400:"#ffca28",500:"#ffc107",600:"#ffb300",700:"#ffa000",800:"#ff8f00",900:"#ff6f00",A100:"#ffe57f",A200:"#ffd740",A400:"#ffc400",A700:"#ffab00"},blue:{50:"#e3f2fd",100:"#bbdefb",200:"#90caf9",300:"#64b5f6",400:"#42a5f5",500:"#2196f3",600:"#1e88e5",700:"#1976d2",800:"#1565c0",900:"#0d47a1",A100:"#82b1ff",A200:"#448aff",A400:"#2979ff",A700:"#2962ff"},blueGrey:{50:"#eceff1",100:"#cfd8dc",200:"#b0bec5",300:"#90a4ae",400:"#78909c",500:"#607d8b",600:"#546e7a",700:"#455a64",800:"#37474f",900:"#263238",A100:"#cfd8dc",A200:"#b0bec5",A400:"#78909c",A700:"#455a64"},brown:{50:"#efebe9",100:"#d7ccc8",200:"#bcaaa4",300:"#a1887f",400:"#8d6e63",500:"#795548",600:"#6d4c41",700:"#5d4037",800:"#4e342e",900:"#3e2723",A100:"#d7ccc8",A200:"#bcaaa4",A400:"#8d6e63",A700:"#5d4037"},cyan:{50:"#e0f7fa",100:"#b2ebf2",200:"#80deea",300:"#4dd0e1",400:"#26c6da",500:"#00bcd4",600:"#00acc1",700:"#0097a7",800:"#00838f",900:"#006064",A100:"#84ffff",A200:"#18ffff",A400:"#00e5ff",A700:"#00b8d4"},deepOrange:{50:"#fbe9e7",100:"#ffccbc",200:"#ffab91",300:"#ff8a65",400:"#ff7043",500:"#ff5722",600:"#f4511e",700:"#e64a19",800:"#d84315",900:"#bf360c",A100:"#ff9e80",A200:"#ff6e40",A400:"#ff3d00",A700:"#dd2c00"},deepPurple:{50:"#ede7f6",100:"#d1c4e9",200:"#b39ddb",300:"#9575cd",400:"#7e57c2",500:"#673ab7",600:"#5e35b1",700:"#512da8",800:"#4527a0",900:"#311b92",A100:"#b388ff",A200:"#7c4dff",A400:"#651fff",A700:"#6200ea"},green:{50:"#e8f5e9",100:"#c8e6c9",200:"#a5d6a7",300:"#81c784",400:"#66bb6a",500:"#4caf50",600:"#43a047",700:"#388e3c",800:"#2e7d32",900:"#1b5e20",A100:"#b9f6ca",A200:"#69f0ae",A400:"#00e676",A700:"#00c853"},grey:{50:"#fafafa",100:"#f5f5f5",200:"#eeeeee",300:"#e0e0e0",400:"#bdbdbd",500:"#9e9e9e",600:"#757575",700:"#616161",800:"#424242",900:"#212121",A100:"#f5f5f5",A200:"#eeeeee",A400:"#bdbdbd",A700:"#616161"},indigo:{50:"#e8eaf6",100:"#c5cae9",200:"#9fa8da",300:"#7986cb",400:"#5c6bc0",500:"#3f51b5",600:"#3949ab",700:"#303f9f",800:"#283593",900:"#1a237e",A100:"#8c9eff",A200:"#536dfe",A400:"#3d5afe",A700:"#304ffe"},lightBlue:{50:"#e1f5fe",100:"#b3e5fc",200:"#81d4fa",300:"#4fc3f7",400:"#29b6f6",500:"#03a9f4",600:"#039be5",700:"#0288d1",800:"#0277bd",900:"#01579b",A100:"#80d8ff",A200:"#40c4ff",A400:"#00b0ff",A700:"#0091ea"},lightGreen:{50:"#f1f8e9",100:"#dcedc8",200:"#c5e1a5",300:"#aed581",400:"#9ccc65",500:"#8bc34a",600:"#7cb342",700:"#689f38",800:"#558b2f",900:"#33691e",A100:"#ccff90",A200:"#b2ff59",A400:"#76ff03",A700:"#64dd17"},lime:{50:"#f9fbe7",100:"#f0f4c3",200:"#e6ee9c",300:"#dce775",400:"#d4e157",500:"#cddc39",600:"#c0ca33",700:"#afb42b",800:"#9e9d24",900:"#827717",A100:"#f4ff81",A200:"#eeff41",A400:"#c6ff00",A700:"#aeea00"},orange:{50:"#fff3e0",100:"#ffe0b2",200:"#ffcc80",300:"#ffb74d",400:"#ffa726",500:"#ff9800",600:"#fb8c00",700:"#f57c00",800:"#ef6c00",900:"#e65100",A100:"#ffd180",A200:"#ffab40",A400:"#ff9100",A700:"#ff6d00"},pink:{50:"#fce4ec",100:"#f8bbd0",200:"#f48fb1",300:"#f06292",400:"#ec407a",500:"#e91e63",600:"#d81b60",700:"#c2185b",800:"#ad1457",900:"#880e4f",A100:"#ff80ab",A200:"#ff4081",A400:"#f50057",A700:"#c51162"},purple:{50:"#f3e5f5",100:"#e1bee7",200:"#ce93d8",300:"#ba68c8",400:"#ab47bc",500:"#9c27b0",600:"#8e24aa",700:"#7b1fa2",800:"#6a1b9a",900:"#4a148c",A100:"#ea80fc",A200:"#e040fb",A400:"#d500f9",A700:"#aa00ff"},red:{50:"#ffebee",100:"#ffcdd2",200:"#ef9a9a",300:"#e57373",400:"#ef5350",500:"#f44336",600:"#e53935",700:"#d32f2f",800:"#c62828",900:"#b71c1c",A100:"#ff8a80",A200:"#ff5252",A400:"#ff1744",A700:"#d50000"},teal:{50:"#e0f2f1",100:"#b2dfdb",200:"#80cbc4",300:"#4db6ac",400:"#26a69a",500:"#009688",600:"#00897b",700:"#00796b",800:"#00695c",900:"#004d40",A100:"#a7ffeb",A200:"#64ffda",A400:"#1de9b6",A700:"#00bfa5"},yellow:{50:"#fffde7",100:"#fff9c4",200:"#fff59d",300:"#fff176",400:"#ffee58",500:"#ffeb3b",600:"#fdd835",700:"#fbc02d",800:"#f9a825",900:"#f57f17",A100:"#ffff8d",A200:"#ffff00",A400:"#ffea00",A700:"#ffd600"}},ue={Person:"red",Car:"green",Animal:"blue",LicensePlate:"cyan",Fire:"deepOrange",Smoke:"deepPurple"},de=["green","red","blue","purple","teal","amber","pink","cyan","lightGreen","deepOrange","deepPurple","lime","indigo","lightBlue"];class he extends te{constructor(){super(),Object.defineProperty(this,"schemaDescription",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"fetchAnalyticEventSchema",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.api.cameras.GetSensorDataSchema("Analytic").subscribe({next:e=>{e.success?r((()=>{this.schemaDescription=e.resultItems})):console.error(e)},error:console.error})}}),i(this,{schemaDescription:n.ref,foundObjectTypes:t,foundObjectTypesForSelect:t,colorsByFoundObjectType:t})}get foundObjectTypes(){if(!this.schemaDescription.length)return[];const e=this.schemaDescription.filter((e=>"filter"===e.parameterType&&"Type"===e.fieldName&&"Analytic"===e.eventType))[0];return e?e.valueSet.includes("LicensePlate")?e.valueSet.split(", "):e.valueSet.split(", ").concat(["LicensePlate"]):[]}get foundObjectTypesForSelect(){const e=Object.entries(ue).filter((([e])=>this.foundObjectTypes.includes(e))).map((([,e])=>e)),t=de.filter((t=>!e.includes(t)));let r=0;return this.foundObjectTypes.map((e=>{const i=e in ue?ue[e]:t[r++],n=ce[i];return{id:e,name:e.toLowerCase(),color:n[500],highlightColor:n.A400,type:"detectedObject"}}))}get colorsByFoundObjectType(){const e=new Map;return this.foundObjectTypesForSelect.forEach((t=>{e.set(t.id,t.highlightColor)})),e}afterInit(){this.fetchAnalyticEventSchema()}dispose(){super.dispose(),this.schemaDescription=[]}}var fe="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function be(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pe=function(e,t,r,i){for(var n=-1,a=null==e?0:e.length;++n<a;){var s=e[n];t(i,s,r(s),e)}return i};var ve=function(e){return function(t,r,i){for(var n=-1,a=Object(t),s=i(t),o=s.length;o--;){var l=s[e?o:++n];if(!1===r(a[l],l,a))break}return t}}();var me=function(e,t){for(var r=-1,i=Array(e);++r<e;)i[r]=t(r);return i},ye="object"==typeof fe&&fe&&fe.Object===Object&&fe,ge=ye,we="object"==typeof self&&self&&self.Object===Object&&self,Oe=ge||we||Function("return this")(),je=Oe.Symbol,Pe=je,Ie=Object.prototype,Ae=Ie.hasOwnProperty,ke=Ie.toString,Te=Pe?Pe.toStringTag:void 0;var Be=function(e){var t=Ae.call(e,Te),r=e[Te];try{e[Te]=void 0;var i=!0}catch(e){}var n=ke.call(e);return i&&(t?e[Te]=r:delete e[Te]),n},Se=Object.prototype.toString;var Ce=Be,_e=function(e){return Se.call(e)},Ee=je?je.toStringTag:void 0;var Re=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Ee&&Ee in Object(e)?Ce(e):_e(e)};var De=function(e){return null!=e&&"object"==typeof e},Ue=Re,qe=De;var Me=function(e){return qe(e)&&"[object Arguments]"==Ue(e)},xe=De,Ne=Object.prototype,Fe=Ne.hasOwnProperty,ze=Ne.propertyIsEnumerable,Ge=Me(function(){return arguments}())?Me:function(e){return xe(e)&&Fe.call(e,"callee")&&!ze.call(e,"callee")},Le=Array.isArray,$e={exports:{}};var We=function(){return!1};!function(e,t){var r=Oe,i=We,n=t&&!t.nodeType&&t,a=n&&e&&!e.nodeType&&e,s=a&&a.exports===n?r.Buffer:void 0,o=(s?s.isBuffer:void 0)||i;e.exports=o}($e,$e.exports);var Ve=$e.exports,He=/^(?:0|[1-9]\d*)$/;var Je=function(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&He.test(e))&&e>-1&&e%1==0&&e<t};var Ke=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991},Ze=Re,Ye=Ke,Qe=De,Xe={};Xe["[object Float32Array]"]=Xe["[object Float64Array]"]=Xe["[object Int8Array]"]=Xe["[object Int16Array]"]=Xe["[object Int32Array]"]=Xe["[object Uint8Array]"]=Xe["[object Uint8ClampedArray]"]=Xe["[object Uint16Array]"]=Xe["[object Uint32Array]"]=!0,Xe["[object Arguments]"]=Xe["[object Array]"]=Xe["[object ArrayBuffer]"]=Xe["[object Boolean]"]=Xe["[object DataView]"]=Xe["[object Date]"]=Xe["[object Error]"]=Xe["[object Function]"]=Xe["[object Map]"]=Xe["[object Number]"]=Xe["[object Object]"]=Xe["[object RegExp]"]=Xe["[object Set]"]=Xe["[object String]"]=Xe["[object WeakMap]"]=!1;var et=function(e){return Qe(e)&&Ye(e.length)&&!!Xe[Ze(e)]};var tt=function(e){return function(t){return e(t)}},rt={exports:{}};!function(e,t){var r=ye,i=t&&!t.nodeType&&t,n=i&&e&&!e.nodeType&&e,a=n&&n.exports===i&&r.process,s=function(){try{var e=n&&n.require&&n.require("util").types;return e||a&&a.binding&&a.binding("util")}catch(e){}}();e.exports=s}(rt,rt.exports);var it=rt.exports,nt=et,at=tt,st=it&&it.isTypedArray,ot=st?at(st):nt,lt=me,ct=Ge,ut=Le,dt=Ve,ht=Je,ft=ot,bt=Object.prototype.hasOwnProperty;var pt=function(e,t){var r=ut(e),i=!r&&ct(e),n=!r&&!i&&dt(e),a=!r&&!i&&!n&&ft(e),s=r||i||n||a,o=s?lt(e.length,String):[],l=o.length;for(var c in e)!t&&!bt.call(e,c)||s&&("length"==c||n&&("offset"==c||"parent"==c)||a&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||ht(c,l))||o.push(c);return o},vt=Object.prototype;var mt=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||vt)};var yt=function(e,t){return function(r){return e(t(r))}}(Object.keys,Object),gt=mt,wt=yt,Ot=Object.prototype.hasOwnProperty;var jt=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)},Pt=Re,It=jt;var At=function(e){if(!It(e))return!1;var t=Pt(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t},kt=At,Tt=Ke;var Bt=function(e){return null!=e&&Tt(e.length)&&!kt(e)},St=pt,Ct=function(e){if(!gt(e))return wt(e);var t=[];for(var r in Object(e))Ot.call(e,r)&&"constructor"!=r&&t.push(r);return t},_t=Bt;var Et=function(e){return _t(e)?St(e):Ct(e)},Rt=ve,Dt=Et;var Ut=Bt;var qt=function(e,t){return function(r,i){if(null==r)return r;if(!Ut(r))return e(r,i);for(var n=r.length,a=t?n:-1,s=Object(r);(t?a--:++a<n)&&!1!==i(s[a],a,s););return r}}((function(e,t){return e&&Rt(e,t,Dt)}));var Mt=function(e,t,r,i){return qt(e,(function(e,n,a){t(i,e,r(e),a)})),i};var xt=function(){this.__data__=[],this.size=0};var Nt=function(e,t){return e===t||e!=e&&t!=t},Ft=Nt;var zt=function(e,t){for(var r=e.length;r--;)if(Ft(e[r][0],t))return r;return-1},Gt=zt,Lt=Array.prototype.splice;var $t=zt;var Wt=zt;var Vt=zt;var Ht=xt,Jt=function(e){var t=this.__data__,r=Gt(t,e);return!(r<0)&&(r==t.length-1?t.pop():Lt.call(t,r,1),--this.size,!0)},Kt=function(e){var t=this.__data__,r=$t(t,e);return r<0?void 0:t[r][1]},Zt=function(e){return Wt(this.__data__,e)>-1},Yt=function(e,t){var r=this.__data__,i=Vt(r,e);return i<0?(++this.size,r.push([e,t])):r[i][1]=t,this};function Qt(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Qt.prototype.clear=Ht,Qt.prototype.delete=Jt,Qt.prototype.get=Kt,Qt.prototype.has=Zt,Qt.prototype.set=Yt;var Xt=Qt,er=Xt;var tr=function(){this.__data__=new er,this.size=0};var rr=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r};var ir=function(e){return this.__data__.get(e)};var nr,ar=function(e){return this.__data__.has(e)},sr=Oe["__core-js_shared__"],or=(nr=/[^.]+$/.exec(sr&&sr.keys&&sr.keys.IE_PROTO||""))?"Symbol(src)_1."+nr:"";var lr=function(e){return!!or&&or in e},cr=Function.prototype.toString;var ur=function(e){if(null!=e){try{return cr.call(e)}catch(e){}try{return e+""}catch(e){}}return""},dr=At,hr=lr,fr=jt,br=ur,pr=/^\[object .+?Constructor\]$/,vr=Function.prototype,mr=Object.prototype,yr=vr.toString,gr=mr.hasOwnProperty,wr=RegExp("^"+yr.call(gr).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var Or=function(e){return!(!fr(e)||hr(e))&&(dr(e)?wr:pr).test(br(e))},jr=function(e,t){return null==e?void 0:e[t]};var Pr=function(e,t){var r=jr(e,t);return Or(r)?r:void 0},Ir=Pr(Oe,"Map"),Ar=Pr(Object,"create"),kr=Ar;var Tr=function(){this.__data__=kr?kr(null):{},this.size=0};var Br=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},Sr=Ar,Cr=Object.prototype.hasOwnProperty;var _r=function(e){var t=this.__data__;if(Sr){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return Cr.call(t,e)?t[e]:void 0},Er=Ar,Rr=Object.prototype.hasOwnProperty;var Dr=Ar;var Ur=Tr,qr=Br,Mr=_r,xr=function(e){var t=this.__data__;return Er?void 0!==t[e]:Rr.call(t,e)},Nr=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=Dr&&void 0===t?"__lodash_hash_undefined__":t,this};function Fr(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}Fr.prototype.clear=Ur,Fr.prototype.delete=qr,Fr.prototype.get=Mr,Fr.prototype.has=xr,Fr.prototype.set=Nr;var zr=Fr,Gr=Xt,Lr=Ir;var $r=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var Wr=function(e,t){var r=e.__data__;return $r(t)?r["string"==typeof t?"string":"hash"]:r.map},Vr=Wr;var Hr=Wr;var Jr=Wr;var Kr=Wr;var Zr=function(){this.size=0,this.__data__={hash:new zr,map:new(Lr||Gr),string:new zr}},Yr=function(e){var t=Vr(this,e).delete(e);return this.size-=t?1:0,t},Qr=function(e){return Hr(this,e).get(e)},Xr=function(e){return Jr(this,e).has(e)},ei=function(e,t){var r=Kr(this,e),i=r.size;return r.set(e,t),this.size+=r.size==i?0:1,this};function ti(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var i=e[t];this.set(i[0],i[1])}}ti.prototype.clear=Zr,ti.prototype.delete=Yr,ti.prototype.get=Qr,ti.prototype.has=Xr,ti.prototype.set=ei;var ri=ti,ii=Xt,ni=Ir,ai=ri;var si=Xt,oi=tr,li=rr,ci=ir,ui=ar,di=function(e,t){var r=this.__data__;if(r instanceof ii){var i=r.__data__;if(!ni||i.length<199)return i.push([e,t]),this.size=++r.size,this;r=this.__data__=new ai(i)}return r.set(e,t),this.size=r.size,this};function hi(e){var t=this.__data__=new si(e);this.size=t.size}hi.prototype.clear=oi,hi.prototype.delete=li,hi.prototype.get=ci,hi.prototype.has=ui,hi.prototype.set=di;var fi=hi;var bi=ri,pi=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this},vi=function(e){return this.__data__.has(e)};function mi(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new bi;++t<r;)this.add(e[t])}mi.prototype.add=mi.prototype.push=pi,mi.prototype.has=vi;var yi=mi;var gi=function(e,t){return e.has(t)},wi=yi,Oi=function(e,t){for(var r=-1,i=null==e?0:e.length;++r<i;)if(t(e[r],r,e))return!0;return!1},ji=gi;var Pi=function(e,t,r,i,n,a){var s=1&r,o=e.length,l=t.length;if(o!=l&&!(s&&l>o))return!1;var c=a.get(e),u=a.get(t);if(c&&u)return c==t&&u==e;var d=-1,h=!0,f=2&r?new wi:void 0;for(a.set(e,t),a.set(t,e);++d<o;){var b=e[d],p=t[d];if(i)var v=s?i(p,b,d,t,e,a):i(b,p,d,e,t,a);if(void 0!==v){if(v)continue;h=!1;break}if(f){if(!Oi(t,(function(e,t){if(!ji(f,t)&&(b===e||n(b,e,r,i,a)))return f.push(t)}))){h=!1;break}}else if(b!==p&&!n(b,p,r,i,a)){h=!1;break}}return a.delete(e),a.delete(t),h};var Ii=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e,i){r[++t]=[i,e]})),r};var Ai=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r},ki=Oe.Uint8Array,Ti=Nt,Bi=Pi,Si=Ii,Ci=Ai,_i=je?je.prototype:void 0,Ei=_i?_i.valueOf:void 0;var Ri=function(e,t,r,i,n,a,s){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!a(new ki(e),new ki(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return Ti(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var o=Si;case"[object Set]":var l=1&i;if(o||(o=Ci),e.size!=t.size&&!l)return!1;var c=s.get(e);if(c)return c==t;i|=2,s.set(e,t);var u=Bi(o(e),o(t),i,n,a,s);return s.delete(e),u;case"[object Symbol]":if(Ei)return Ei.call(e)==Ei.call(t)}return!1};var Di=function(e,t){for(var r=-1,i=t.length,n=e.length;++r<i;)e[n+r]=t[r];return e},Ui=Le;var qi=function(e,t,r){var i=t(e);return Ui(e)?i:Di(i,r(e))};var Mi=function(e,t){for(var r=-1,i=null==e?0:e.length,n=0,a=[];++r<i;){var s=e[r];t(s,r,e)&&(a[n++]=s)}return a},xi=function(){return[]},Ni=Object.prototype.propertyIsEnumerable,Fi=Object.getOwnPropertySymbols,zi=qi,Gi=Fi?function(e){return null==e?[]:(e=Object(e),Mi(Fi(e),(function(t){return Ni.call(e,t)})))}:xi,Li=Et;var $i=function(e){return zi(e,Li,Gi)},Wi=Object.prototype.hasOwnProperty;var Vi=function(e,t,r,i,n,a){var s=1&r,o=$i(e),l=o.length;if(l!=$i(t).length&&!s)return!1;for(var c=l;c--;){var u=o[c];if(!(s?u in t:Wi.call(t,u)))return!1}var d=a.get(e),h=a.get(t);if(d&&h)return d==t&&h==e;var f=!0;a.set(e,t),a.set(t,e);for(var b=s;++c<l;){var p=e[u=o[c]],v=t[u];if(i)var m=s?i(v,p,u,t,e,a):i(p,v,u,e,t,a);if(!(void 0===m?p===v||n(p,v,r,i,a):m)){f=!1;break}b||(b="constructor"==u)}if(f&&!b){var y=e.constructor,g=t.constructor;y==g||!("constructor"in e)||!("constructor"in t)||"function"==typeof y&&y instanceof y&&"function"==typeof g&&g instanceof g||(f=!1)}return a.delete(e),a.delete(t),f},Hi=Pr(Oe,"DataView"),Ji=Pr(Oe,"Promise"),Ki=Pr(Oe,"Set"),Zi=Hi,Yi=Ir,Qi=Ji,Xi=Ki,en=Pr(Oe,"WeakMap"),tn=Re,rn=ur,nn=rn(Zi),an=rn(Yi),sn=rn(Qi),on=rn(Xi),ln=rn(en),cn=tn;(Zi&&"[object DataView]"!=cn(new Zi(new ArrayBuffer(1)))||Yi&&"[object Map]"!=cn(new Yi)||Qi&&"[object Promise]"!=cn(Qi.resolve())||Xi&&"[object Set]"!=cn(new Xi)||en&&"[object WeakMap]"!=cn(new en))&&(cn=function(e){var t=tn(e),r="[object Object]"==t?e.constructor:void 0,i=r?rn(r):"";if(i)switch(i){case nn:return"[object DataView]";case an:return"[object Map]";case sn:return"[object Promise]";case on:return"[object Set]";case ln:return"[object WeakMap]"}return t});var un=fi,dn=Pi,hn=Ri,fn=Vi,bn=cn,pn=Le,vn=Ve,mn=ot,yn="[object Object]",gn=Object.prototype.hasOwnProperty;var wn=function(e,t,r,i,n,a){var s=pn(e),o=pn(t),l=s?"[object Array]":bn(e),c=o?"[object Array]":bn(t),u=(l="[object Arguments]"==l?yn:l)==yn,d=(c="[object Arguments]"==c?yn:c)==yn,h=l==c;if(h&&vn(e)){if(!vn(t))return!1;s=!0,u=!1}if(h&&!u)return a||(a=new un),s||mn(e)?dn(e,t,r,i,n,a):hn(e,t,l,r,i,n,a);if(!(1&r)){var f=u&&gn.call(e,"__wrapped__"),b=d&&gn.call(t,"__wrapped__");if(f||b){var p=f?e.value():e,v=b?t.value():t;return a||(a=new un),n(p,v,r,i,a)}}return!!h&&(a||(a=new un),fn(e,t,r,i,n,a))},On=De;var jn=function e(t,r,i,n,a){return t===r||(null==t||null==r||!On(t)&&!On(r)?t!=t&&r!=r:wn(t,r,i,n,e,a))},Pn=fi,In=jn;var An=jt;var kn=function(e){return e==e&&!An(e)},Tn=kn,Bn=Et;var Sn=function(e,t){return function(r){return null!=r&&(r[e]===t&&(void 0!==t||e in Object(r)))}},Cn=function(e,t,r,i){var n=r.length,a=n,s=!i;if(null==e)return!a;for(e=Object(e);n--;){var o=r[n];if(s&&o[2]?o[1]!==e[o[0]]:!(o[0]in e))return!1}for(;++n<a;){var l=(o=r[n])[0],c=e[l],u=o[1];if(s&&o[2]){if(void 0===c&&!(l in e))return!1}else{var d=new Pn;if(i)var h=i(c,u,l,e,t,d);if(!(void 0===h?In(u,c,3,i,d):h))return!1}}return!0},_n=function(e){for(var t=Bn(e),r=t.length;r--;){var i=t[r],n=e[i];t[r]=[i,n,Tn(n)]}return t},En=Sn;var Rn=function(e){var t=_n(e);return 1==t.length&&t[0][2]?En(t[0][0],t[0][1]):function(r){return r===e||Cn(r,e,t)}},Dn=Re,Un=De;var qn=function(e){return"symbol"==typeof e||Un(e)&&"[object Symbol]"==Dn(e)},Mn=Le,xn=qn,Nn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Fn=/^\w*$/;var zn=function(e,t){if(Mn(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!xn(e))||(Fn.test(e)||!Nn.test(e)||null!=t&&e in Object(t))},Gn=ri;function Ln(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var r=function(){var i=arguments,n=t?t.apply(this,i):i[0],a=r.cache;if(a.has(n))return a.get(n);var s=e.apply(this,i);return r.cache=a.set(n,s)||a,s};return r.cache=new(Ln.Cache||Gn),r}Ln.Cache=Gn;var $n=Ln;var Wn=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Vn=/\\(\\)?/g,Hn=function(e){var t=$n(e,(function(e){return 500===r.size&&r.clear(),e})),r=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(Wn,(function(e,r,i,n){t.push(i?n.replace(Vn,"$1"):r||e)})),t}));var Jn=function(e,t){for(var r=-1,i=null==e?0:e.length,n=Array(i);++r<i;)n[r]=t(e[r],r,e);return n},Kn=Le,Zn=qn,Yn=je?je.prototype:void 0,Qn=Yn?Yn.toString:void 0;var Xn=function e(t){if("string"==typeof t)return t;if(Kn(t))return Jn(t,e)+"";if(Zn(t))return Qn?Qn.call(t):"";var r=t+"";return"0"==r&&1/t==-Infinity?"-0":r},ea=Xn;var ta=Le,ra=zn,ia=Hn,na=function(e){return null==e?"":ea(e)};var aa=function(e,t){return ta(e)?e:ra(e,t)?[e]:ia(na(e))},sa=qn;var oa=function(e){if("string"==typeof e||sa(e))return e;var t=e+"";return"0"==t&&1/e==-Infinity?"-0":t},la=aa,ca=oa;var ua=function(e,t){for(var r=0,i=(t=la(t,e)).length;null!=e&&r<i;)e=e[ca(t[r++])];return r&&r==i?e:void 0},da=ua;var ha=aa,fa=Ge,ba=Le,pa=Je,va=Ke,ma=oa;var ya=function(e,t){return null!=e&&t in Object(e)},ga=function(e,t,r){for(var i=-1,n=(t=ha(t,e)).length,a=!1;++i<n;){var s=ma(t[i]);if(!(a=null!=e&&r(e,s)))break;e=e[s]}return a||++i!=n?a:!!(n=null==e?0:e.length)&&va(n)&&pa(s,n)&&(ba(e)||fa(e))};var wa=jn,Oa=function(e,t,r){var i=null==e?void 0:da(e,t);return void 0===i?r:i},ja=function(e,t){return null!=e&&ga(e,t,ya)},Pa=zn,Ia=kn,Aa=Sn,ka=oa;var Ta=ua;var Ba=function(e){return function(t){return null==t?void 0:t[e]}},Sa=function(e){return function(t){return Ta(t,e)}},Ca=zn,_a=oa;var Ea=Rn,Ra=function(e,t){return Pa(e)&&Ia(t)?Aa(ka(e),t):function(r){var i=Oa(r,e);return void 0===i&&i===t?ja(r,e):wa(t,i,3)}},Da=function(e){return e},Ua=Le,qa=function(e){return Ca(e)?Ba(_a(e)):Sa(e)};var Ma=function(e){return"function"==typeof e?e:null==e?Da:"object"==typeof e?Ua(e)?Ra(e[0],e[1]):Ea(e):qa(e)},xa=pe,Na=Mt,Fa=Ma,za=Le;var Ga=be(function(e,t){return function(r,i){var n=za(r)?xa:Na,a=t?t():{};return n(r,e,Fa(i),a)}}((function(e,t,r){e[r?0:1].push(t)}),(function(){return[[],[]]})));var La=function(e,t,r,i){for(var n=e.length,a=r+(i?1:-1);i?a--:++a<n;)if(t(e[a],a,e))return a;return-1},$a=function(e){return e!=e},Wa=function(e,t,r){for(var i=r-1,n=e.length;++i<n;)if(e[i]===t)return i;return-1};var Va=function(e,t,r){return t==t?Wa(e,t,r):La(e,$a,r)};var Ha=function(e,t){return!!(null==e?0:e.length)&&Va(e,t,0)>-1};var Ja=function(e,t,r){for(var i=-1,n=null==e?0:e.length;++i<n;)if(r(t,e[i]))return!0;return!1};var Ka=Ki,Za=function(){},Ya=Ka&&1/Ai(new Ka([,-0]))[1]==1/0?function(e){return new Ka(e)}:Za,Qa=yi,Xa=Ha,es=Ja,ts=gi,rs=Ya,is=Ai;var ns=function(e,t,r){var i=-1,n=Xa,a=e.length,s=!0,o=[],l=o;if(r)s=!1,n=es;else if(a>=200){var c=t?null:rs(e);if(c)return is(c);s=!1,n=ts,l=new Qa}else l=t?[]:o;e:for(;++i<a;){var u=e[i],d=t?t(u):u;if(u=r||0!==u?u:0,s&&d==d){for(var h=l.length;h--;)if(l[h]===d)continue e;t&&l.push(d),o.push(u)}else n(l,d,r)||(l!==o&&l.push(d),o.push(u))}return o},as=Ma,ss=ns;var os=be((function(e,t){return e&&e.length?ss(e,as(t)):[]}));const ls=new Set(["LicensePlate","FaceDetection","Analytic","SpeedDetection","Temperature","PoS","GPS","DigitalInput"]);class cs{get id(){return this.raw.id}get startTime(){return new Date(this.raw.startTime)}get endTime(){return new Date(this.raw.endTime)}get isLive(){return!ls.has(this.type)&&+this.startTime==+this.endTime}get acknowledged(){return"sensorId"in this.raw&&!!this.raw.ackEventType}constructor(e){if(Object.defineProperty(this,"cameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"thumbnailUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"detectedObjects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"faces",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"instant",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),i(this,{id:t,startTime:t,endTime:t,acknowledged:t,isLive:t,raw:n.ref}),this.raw=e,this.type=e.eventType,this.cameraId=e.sensorId,("Analytic"===this.type||"FaceDetection"===this.type)&&e.data)try{const t=JSON.parse(e.data);t.FoundObjects&&(this.type="Analytic",this.detectedObjects=t.FoundObjects),t.Faces&&(this.type="FaceDetection",this.faces=t.Faces),this.thumbnailUrl=t.ThumbnailUrl}catch{console.warn("invalid data",e.data),this.type="Motion"}this.instant=ls.has(this.type),this.detectedObjects||(this.detectedObjects=[])}}function us(e){if(e.length<2)return e;const t=[e[0]];for(let r=1;r<e.length;r++){const i=t.length-1,n=t[i],a=e[r];a[0]>n[1]?t.push(a):t[i]=[n[0],new Date(Math.max(+n[1],+a[1]))]}return t}const ds=()=>!0;/Mac|iPod|iPhone|iPad/.test(window.navigator.platform);class hs extends te{constructor(e){super(),Object.defineProperty(this,"camerasStore",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByFoundObjects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByColor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsByLiveliness",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequests",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"knownIntervals",{enumerable:!0,configurable:!0,writable:!0,value:G()}),Object.defineProperty(this,"knownIntervalsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"knownIntervalsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"knownIntervalsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"eventsById",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"updates",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"recentAdditions",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"update",{enumerable:!0,configurable:!0,writable:!0,value:e=>{e.forEach((e=>{const t=this.eventsById.get(e.id);t&&(t.raw=e.raw,this.data.remove((t=>t.id===e.id)),this.data.add([t]))}))}}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=e.filter((e=>!this.eventsById.has(e.id)));t.forEach((e=>this.eventsById.set(e.id,e))),this.data.add(t),t.length&&this.updates++}}),Object.defineProperty(this,"processNewEvents",{enumerable:!0,configurable:!0,writable:!0,value:({data:e})=>{const t=os(e.filter((e=>this.camerasStore.camerasById.has(e.sensorId))).reverse(),"id").map((e=>new cs(e))),[r,i]=Ga(t,(e=>this.eventsById.has(e.id)));this.update(r),this.add(i),i.length&&(this.recentAdditions=i.map((e=>e.id)))}}),i(this,{updates:n,recentAdditions:n.ref,processNewEvents:a,update:a,add:a,dispose:a}),this.data=G(),this.eventsByCameraId=this.data.dimension((e=>e.cameraId)),this.eventsByStart=this.data.dimension((e=>+e.startTime)),this.eventsByEnd=this.data.dimension((e=>+e.endTime)),this.eventsByType=this.data.dimension((e=>e.type)),this.eventsByFoundObjects=this.data.dimension((e=>e.detectedObjects.map((e=>e.Type))),!0),this.eventsByColor=this.data.dimension((e=>e.detectedObjects.reduce(((e,t)=>{var r,i;return e.concat(...null!==(i=null===(r=t.Colors)||void 0===r?void 0:r.map((e=>e.Color)))&&void 0!==i?i:[])}),[])),!0),this.eventsByLiveliness=this.data.dimension((e=>e.isLive)),this.pendingRequests=G(),this.pendingRequestsByStart=this.pendingRequests.dimension((e=>+e.startTime)),this.pendingRequestsByEnd=this.pendingRequests.dimension((e=>+e.endTime)),this.pendingRequestsByCameraId=this.pendingRequests.dimension((e=>e.cameraId)),this.knownIntervalsByCameraId=this.knownIntervals.dimension((e=>e.cameraId)),this.knownIntervalsByStart=this.knownIntervals.dimension((e=>+e.from)),this.knownIntervalsByEnd=this.knownIntervals.dimension((e=>+e.to))}populateEvents(e,t,r){const i=null===r?new Date(Date.now()-6e5):r;-1===e?this.knownIntervalsByCameraId.filter(-1):this.knownIntervalsByCameraId.filter((t=>-1===t||t===e)),this.knownIntervalsByStart.filter([-1/0,i]),this.knownIntervalsByEnd.filter([t,1/0]);const n=this.knownIntervalsByStart.bottom(1/0),a=[];if(this.knownIntervalsByCameraId.filterAll(),this.knownIntervalsByStart.filterAll(),this.knownIntervalsByEnd.filterAll(),n.length){const s=us(n.map((e=>[e.from,e.to])));s[0][0]>t&&a.push([t,s[0][0]]);for(let e=0;e<s.length-1;e++)a.push([s[e][1],s[e+1][0]]);s[us.length-1][1]<i&&a.push([s[us.length-1][1],i]),a.length&&(t=a[0][0],+a[a.length-1][1]<=+i&&(r=a[a.length-1][1]),this.knownIntervals.add([{cameraId:e,from:t,to:i}]))}else this.knownIntervals.add([{cameraId:e,from:t,to:i}]);this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(i);const s=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),s)return;if(n.length&&!a.length)return;const o=i=>this.api.cameras.GetSensorEventsPage({sensorIds:[e],sensorType:"camera",sensorEventTypes:[],startTime:t,endTime:r,rowsLimit:100,isDescending:!0,pageToken:i},null,[]).pipe(R((e=>e.success?w(e):(console.error(e.error),m((()=>e.error)))))),l=o().pipe(N((e=>e.pageInfo.haveMore?o(e.pageInfo.nextPageToken):u)),M((e=>e.resultItems.map((e=>new cs(e))))),z());this.pendingRequests.add([{cameraId:e,startTime:t,endTime:r||new Date,request:l}]),l.subscribe({next:this.add,error:e=>{console.error(e),this.pendingRequests.remove((e=>e.request===l))},complete:()=>{this.pendingRequests.remove((e=>e.request===l))}})}getEvents({cameraIds:e,from:t,to:r,detectedObjectTypes:i,eventTypes:n,colors:a,probability:s}){this.eventsByStart.filter([+t,r?+r+5e-4:1/0]),(null==e?void 0:e.length)&&this.eventsByCameraId.filter((t=>e.includes(t))),(null==n?void 0:n.length)&&this.eventsByType.filter((e=>n.includes(e))),(null==i?void 0:i.length)&&this.eventsByFoundObjects.filter((e=>i.includes(e))),(null==a?void 0:a.size)&&this.eventsByColor.filter((e=>a.has(e)));let o=this.eventsByStart.top(1/0);return(null==n?void 0:n.length)&&this.eventsByType.filterAll(),(null==e?void 0:e.length)&&this.eventsByCameraId.filterAll(),(null==i?void 0:i.length)&&this.eventsByFoundObjects.filterAll(),(null==a?void 0:a.size)&&this.eventsByColor.filterAll(),this.eventsByStart.filterAll(),void 0!==s&&(null==i?void 0:i.length)&&(o=o.filter((e=>e.detectedObjects.some((e=>e.Probability>=s&&i.includes(e.Type)))))),o}getOverlappedEvents({cameraId:e,from:t,to:r}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([-1/0,+r+5e-4]),this.eventsByEnd.filter([+t,1/0]);const i=this.eventsByStart.top(1/0);return this.eventsByCameraId.filterAll(),this.eventsByStart.filterAll(),this.eventsByStart.filterAll(),i}getLastNonAnalyticEventBefore({cameraId:e,date:t}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([-1/0,+t]),this.eventsByType.filter((e=>"Analytic"!==e));const r=this.eventsByStart.top(1);return this.eventsByType.filterAll(),this.eventsByStart.filterAll(),this.eventsByCameraId.filterAll(),r[0]}getLastObjectBefore({cameraId:e,date:t,objectFilters:r}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([-1/0,+t]),this.eventsByType.filter((e=>"Analytic"===e));const{cars:i,people:n,misc:a}=r;n&&i&&a||this.eventsByFoundObjects.filter((e=>a?n||i?!(!n||!i)||(n?"Car"!==e:"Person"!==e):"Person"!==e&&"Car"!==e:n&&i?"Person"===e||"Car"===e:n?"Person"===e:"Car"===e));const s=this.eventsByStart.top(1);return this.eventsByFoundObjects.filterAll(),this.eventsByType.filterAll(),this.eventsByStart.filterAll(),this.eventsByCameraId.filterAll(),s[0]}getFirstNonAnalyticEventAfter({cameraId:e,date:t}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([+t+5e-4,1/0]),this.eventsByType.filter((e=>"Analytic"!==e));const r=this.eventsByEnd.bottom(1);return this.eventsByType.filterAll(),this.eventsByCameraId.filterAll(),this.eventsByStart.filterAll(),r[0]}getFirstObjectAfter({cameraId:e,date:t,objectFilters:r}){this.eventsByCameraId.filter(e),this.eventsByStart.filter([+t+5e-4,1/0]),this.eventsByType.filter((e=>"Analytic"===e));const{cars:i,people:n,misc:a}=r;n&&i&&a||this.eventsByFoundObjects.filter((e=>a?n||i?!(!n||!i)||(n?"Car"!==e:"Person"!==e):"Person"!==e&&"Car"!==e:n&&i?"Person"===e||"Car"===e:n?"Person"===e:"Car"===e));const s=this.eventsByStart.bottom(1);return this.eventsByFoundObjects.filterAll(),this.eventsByType.filterAll(),this.eventsByStart.filterAll(),this.eventsByCameraId.filterAll(),s[0]}afterInit(){this.api.events.pipe(q((({hub:e,event:t})=>"cameras"===e&&"OnCameraMotionEvent"===t))).subscribe(this.processNewEvents)}dispose(){super.dispose(),this.data.remove(ds),this.updates++}}class fs extends te{constructor(){super(),Object.defineProperty(this,"thumbnails",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"thumbnailsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"thumbnailsByDate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequests",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pendingRequestsByCount",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"toThumbnail",{enumerable:!0,configurable:!0,writable:!0,value:e=>({realtimestamp:t,url:r,width:i,height:n})=>({cameraId:e,url:r,width:i,height:n,timestamp:new Date(t)})}),this.thumbnails=G(),this.thumbnailsByCameraId=this.thumbnails.dimension((e=>e.cameraId)),this.thumbnailsByDate=this.thumbnails.dimension((e=>+e.timestamp)),this.pendingRequests=G(),this.pendingRequestsByStart=this.pendingRequests.dimension((e=>+e.from)),this.pendingRequestsByEnd=this.pendingRequests.dimension((e=>+e.to)),this.pendingRequestsByCameraId=this.pendingRequests.dimension((e=>e.cameraId)),this.pendingRequestsByCount=this.pendingRequests.dimension((e=>e.count))}fetchThumbnails(e,t,r,i){this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter(t),this.pendingRequestsByEnd.filter(r),this.pendingRequestsByCount.filter(i);const n=this.pendingRequests.allFiltered()[0];if(this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),this.pendingRequestsByCount.filterAll(),n)return n.request;const a=this.api.thumbnails.GetThumbnailsInfo({cameraId:e,from:t,to:r,count:i}).pipe(M((t=>t.resultItems.filter((e=>e.url)).map(this.toThumbnail(e)))),D());return this.pendingRequests.add([{cameraId:e,from:t,to:r,count:i,request:a}]),a.subscribe((e=>{this.thumbnails.add(e),this.pendingRequests.remove((e=>e.request===a))})),a}getIntervalState(e,t,r){const i=this.getThumbnail({cameraId:e,from:t,to:r});if(i)return{state:"fullfilled",data:i};this.pendingRequestsByCameraId.filter(e),this.pendingRequestsByStart.filter([-1/0,+r+5e-4]),this.pendingRequestsByEnd.filter([t,1/0]);let n=this.pendingRequests.allFiltered();return this.pendingRequestsByCameraId.filterAll(),this.pendingRequestsByStart.filterAll(),this.pendingRequestsByEnd.filterAll(),n=n.filter((e=>1===e.count?+e.from==+t&&+e.to==+r:Math.abs((+e.to-+e.from)/e.count-(+r-+t))<=1)),n.length?{state:"pending",request:n[0].request}:null}fetchThumbnail(e,t,r){const i=this.getIntervalState(e,t,r);if(null!==i){if("fullfilled"===i.state)return w(i.data);if("pending"===i.state)return i.request.pipe(M((()=>this.getThumbnail({cameraId:e,from:t,to:r}))))}const n=this.api.thumbnails.GetThumbnailInfo({cameraId:e,from:t,to:r}).pipe(M((e=>e.resultItems)),D());return n.subscribe((t=>{const r=t.filter((e=>e.url)).map(this.toThumbnail(e));this.thumbnails.add(r),this.pendingRequests.remove((e=>e.request===n))})),this.pendingRequests.add([{cameraId:e,from:t,to:r,count:1,request:n}]),n.pipe(M((()=>this.getThumbnail({cameraId:e,from:t,to:r}))))}getThumbnail({cameraId:e,from:t,to:r}){this.thumbnailsByCameraId.filter(e),this.thumbnailsByDate.filter([+t,+r+(+t==+r?5e-4:0)]);const i=this.thumbnails.allFiltered()[0];return this.thumbnailsByDate.filterAll(),this.thumbnailsByCameraId.filterAll(),i}getThumbnails({cameraId:e,from:t,to:r}){this.thumbnailsByCameraId.filter(e),this.thumbnailsByDate.filter([+t,+r+5e-4]);const i=this.thumbnails.allFiltered();return this.thumbnailsByDate.filterAll(),this.thumbnailsByCameraId.filterAll(),i}}const bs=$.createInstance();class ps{constructor(e){Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"startTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"endTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"createdAt",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"duration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chunks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"description",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"raw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isDownloading",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"archives",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),i(this,{name:n,clipUrl:n,isDownloading:n}),this.update(e)}get isTimelapse(){return this.type.startsWith("Timelaps")}update(e){this.raw=e,this.id=e.id,this.createdAt=new Date(e.timeCreated),this.startTime=new Date(e.startTime),this.endTime=new Date(e.endTime),this.type=e.recordType,this.duration=e.duration,this.cameraId=e.cameraId,this.name=e.name||e.tagName,this.description=e.description,this.clipUrl=e.clipUrl,this.version=e.version}}class vs extends te{constructor(e){super(),Object.defineProperty(this,"notification",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsByCameraId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsByCreationDate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsByStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsByEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsByType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsById",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"clipsMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"loaded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"loading",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"updates",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"add",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=e.filter((e=>!this.clipsMap.has(e.id)));t.forEach((e=>this.clipsMap.set(e.id,e))),this.data.add(t),t.length&&this.updates++}}),Object.defineProperty(this,"addOrUpdate",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const[t,r]=Ga(e,(e=>this.clipsMap.has(e.id)));r.forEach((e=>this.clipsMap.set(e.id,e))),this.data.add(r),t.forEach((e=>{var t;return null===(t=this.clipsMap.get(e.id))||void 0===t?void 0:t.update(e.raw)})),r.length&&this.updates++}}),Object.defineProperty(this,"removeFromStore",{enumerable:!0,configurable:!0,writable:!0,value:e=>{e.length&&(e.forEach((({id:e})=>{this.data.remove((t=>t.id===e)),this.clipsMap.delete(e)})),this.updates++)}}),Object.defineProperty(this,"createClip",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.api.archives.SaveArchive({...e,recordType:"Archive"}).pipe(R((e=>e.success?w(e.resultItems.map((e=>new ps(e)))):m((()=>e.error))))).subscribe({next:t=>{var r;null===(r=this.notification)||void 0===r||r.success(bs.t("archiveManager.clipCreatedMessage",{name:e.name}),{autoClose:3e3}),this.add(t)},error:t=>{var r;console.error(t),null===(r=this.notification)||void 0===r||r.error(bs.t("archiveManager.clipNotSavedMessage",{name:e.name}))}})}}),Object.defineProperty(this,"createTimelapse",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.api.archives.SaveArchive({...e,recordType:"Timelaps"}).pipe(R((e=>e.success?w(e.resultItems.map((e=>new ps(e)))):m((()=>e.error))))).subscribe({next:t=>{var r;null===(r=this.notification)||void 0===r||r.success(bs.t("archiveManager.timelapseSavedMessage",{name:e.name})),this.add(t)},error:t=>{var r;console.error(t),null===(r=this.notification)||void 0===r||r.error(bs.t("archiveManager.timelapseNotSavedMessage",{name:e.name}))}})}}),i(this,{loaded:n,loading:n,updates:n,add:a,addOrUpdate:a,removeFromStore:a}),this.data=G(),this.clipsByCameraId=this.data.dimension((e=>e.cameraId)),this.clipsByCreationDate=this.data.dimension((e=>+e.createdAt)),this.clipsByStart=this.data.dimension((e=>+e.startTime)),this.clipsByEnd=this.data.dimension((e=>+e.endTime)),this.clipsByType=this.data.dimension((e=>e.type)),this.clipsById=this.data.dimension((e=>e.id))}fetch(){this.loaded||this.loading||(this.loading=!0);const e=this.api.archives.GetArchives({}).pipe(R((e=>e.success?w(e.resultItems.map((e=>new ps(e)))):(console.error(e.error),[]))),D());return e.subscribe((e=>{r((()=>{this.loaded=!0,this.loading=!1,this.add(e)}))})),e}getClips({cameraId:e,from:t,to:r}){this.clipsByStart.filter([-1/0,+r+5e-4]),this.clipsByEnd.filter([t,1/0]),this.clipsByType.filter("Archive"),e&&this.clipsByCameraId.filter(e);const i=this.clipsByStart.top(1/0);return e&&this.clipsByCameraId.filterAll(),this.clipsByStart.filterAll(),this.clipsByEnd.filterAll(),this.clipsByType.filterAll(),i}getTimelapses(){this.clipsByType.filterFunction((e=>e.startsWith("Timelaps")));const e=this.clipsByStart.top(1/0);return this.clipsByType.filterAll(),e}getRecentlyAdded(){const e=Date.now()-864e5;this.clipsByCreationDate.filterFunction((t=>t>e));const t=this.clipsByCreationDate.top(1/0);return this.clipsByCreationDate.filterAll(),t}all(){return this.clipsByStart.top(1/0)}getOnly(e,t="asc"){if(null===e){return"desc"===t?this.clipsByStart.top(1/0):this.clipsByStart.bottom(1/0)}this.clipsByType.filterFunction((t=>"clips"===e?!t.startsWith("Timelaps"):t.startsWith("Timelaps")));const r="desc"===t?this.clipsByStart.top(1/0):this.clipsByStart.bottom(1/0);return this.clipsByType.filterAll(),r}rename(e,t){this.api.archives.SaveArchive({...e.raw,name:t}).pipe(R((e=>e.success?w(e.resultItems.map((e=>new ps(e)))):m((()=>e.error))))).subscribe({next:t=>{var r,i;null===(r=this.clipsMap.get(e.id))||void 0===r||r.update(t[0]),null===(i=this.notification)||void 0===i||i.success(bs.t("clips.renameSuccess"),{autoClose:3e3})},error:e=>{var t;console.error(e),null===(t=this.notification)||void 0===t||t.error(bs.t("clips.renameError"))}})}delete(e){this.api.archives.DeleteArchive({id:e.id,version:e.version,cameraId:e.cameraId}).pipe(R((e=>e.success?w(e.resultItems.map((e=>new ps(e)))):m((()=>e.error))))).subscribe({next:()=>{var t;this.removeFromStore([e]),null===(t=this.notification)||void 0===t||t.success(bs.t("clipDeleted",{name:e.name}))},error:t=>{var r;console.error(t),null===(r=this.notification)||void 0===r||r.error(bs.t("archiveManager.archiveNotDeletedMessage",{name:e.name}))}})}afterInit(){this.api.events.pipe(q((({hub:e,event:t})=>"archives"===e&&"OnArchiveAdded"===t))).subscribe((({data:e})=>{this.add(e.resultItems.map((e=>new ps(e))))})),this.api.events.pipe(q((({hub:e,event:t})=>"archives"===e&&"OnTimelapsAdded"===t))).subscribe((({data:e})=>{this.addOrUpdate(e.resultItems.map((e=>new ps({...e,recordType:"Timelaps"}))))})),this.api.events.pipe(q((({hub:e,event:t})=>"archives"===e&&"OnArchiveDeleted"===t))).subscribe((({data:e})=>{this.removeFromStore(e.resultItems)}))}dispose(){super.dispose(),this.data.remove(ds),this.updates++}}class ms{constructor(e){Object.defineProperty(this,"notifier",{enumerable:!0,configurable:!0,writable:!0,value:e})}error(e){this.notifier.error(e)}success(e,t){this.notifier.success(e,t)}warn(e){this.notifier.warn(e)}}const ys=new Map;class gs{constructor(t){Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"initialized",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"cameras",{enumerable:!0,configurable:!0,writable:!0,value:new le}),Object.defineProperty(this,"archives",{enumerable:!0,configurable:!0,writable:!0,value:new ae(this.cameras)}),Object.defineProperty(this,"events",{enumerable:!0,configurable:!0,writable:!0,value:new hs(this.cameras)}),Object.defineProperty(this,"eventSchema",{enumerable:!0,configurable:!0,writable:!0,value:new he}),Object.defineProperty(this,"thumbnails",{enumerable:!0,configurable:!0,writable:!0,value:new fs}),Object.defineProperty(this,"account",{enumerable:!0,configurable:!0,writable:!0,value:new ie}),Object.defineProperty(this,"notification",{enumerable:!0,configurable:!0,writable:!0,value:new ms({success:console.log,warn:console.warn,error:console.error})}),Object.defineProperty(this,"library",{enumerable:!0,configurable:!0,writable:!0,value:new vs(this.notification)}),Object.defineProperty(this,"auth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"api",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"disposables",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"tokenUpdateReactions",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"dispose",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.disposables.forEach((e=>{e instanceof A?e.closed||e.unsubscribe():e()})),this.tokenUpdateReactions.forEach((e=>e())),this.tokenUpdateReactions.clear(),this.auth.signOut(),this.cameras.dispose(),this.events.dispose(),this.thumbnails.dispose(),this.eventSchema.dispose(),this.account.dispose(),this.library.dispose(),ys.delete(this.name)}}),Object.defineProperty(this,"onTokenUpdate",{enumerable:!0,configurable:!0,writable:!0,value:t=>{if(!this.auth)throw new Error("app has to be inited first");const r=e((()=>this.auth.token),(e=>t((null==e?void 0:e.json)||null)));return this.tokenUpdateReactions.add(r),()=>{r(),this.tokenUpdateReactions.delete(r)}}}),i(this,{initialized:n}),this.disposables.push(s((()=>!!this.account.user),(()=>{this.cameras.load()})))}init({token:e,tokenStorage:t=new X,tokenStorageKey:i,apiUrl:n="https://services.3deye.me/reactiveapi",tokenServiceUrl:a="https://admin.3deye.me/webapi/v3/auth/token"},s="default"){if(i||(i=`@3deye-toolkit/${s}/token`),ys.has(s))return console.warn("Can`t init two apps with the same name"),ys.get(s);if(this.auth&&s===this.name)return console.warn("Can`t init already inited app"),this;if(this.auth||"default"===this.name&&"default"!==s)return new gs(s).init({token:e,tokenStorage:t,tokenStorageKey:i,apiUrl:n,tokenServiceUrl:a},s);const o=e&&"clientId"in e?e.clientId:"WebApp";return e&&t.setItem(i,JSON.stringify(e)),this.auth=new Q({tokenServiceUrl:a,tokenStorageKey:i,storage:t,clientId:o,deviceInfo:null}),this.api=Z.create(V,this.auth,(e=>_(n,{qs:{access_token:e}}))),this.cameras.initWith(this.api),this.archives.initWith(this.api),this.library.initWith(this.api),this.events.initWith(this.api),this.eventSchema.initWith(this.api),this.thumbnails.initWith(this.api),this.account.initWith(this.api),this.account.setAuthStore(this.auth),r((()=>{this.initialized=!0})),ys.set(s,this),this}}const ws=new gs("default"),Os=W.createContext(null);export{Os as AppContext,ws as app};
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.34.8"
9
+ }
10
+ ]
11
+ }
package/package.json CHANGED
@@ -1,15 +1,30 @@
1
1
  {
2
2
  "name": "@3deye-toolkit/core",
3
- "version": "0.0.1-alpha.9",
3
+ "version": "0.0.2",
4
4
  "module": "dist/core.js",
5
- "files": ["dist"],
5
+ "types": "dist/core.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
6
9
  "dependencies": {
7
- "rxjs": "^6.5.4",
8
- "mobx": "^5.15.1",
9
- "crossfilter2": "^1.5.2",
10
+ "crossfilter2": "^1.5.4",
11
+ "date-fns": "^2.28.0",
12
+ "http-status-codes": "^2.2.0",
13
+ "i18next": "21.6.11",
10
14
  "jqueryless-signalr": "1.0.0",
11
- "object-assign": "4.1.1"
15
+ "lodash": "4.17.21",
16
+ "mobx": "^6.3.13",
17
+ "rxjs": "^7.5.3",
18
+ "string-natural-compare": "^3.0.1"
19
+ },
20
+ "peerDependencies": {
21
+ "react": "^16.8.0 || ^17 || ^18",
22
+ "react-dom": "^16.8.0 || ^17 || ^18"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public",
26
+ "registry": "https://registry.npmjs.org/"
12
27
  },
13
28
  "sideEffects": false,
14
29
  "license": "mit"
15
- }
30
+ }