This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
admin-panel/graphql-types/node_modules/sse-z/dist/sse-z.min.js

2 lines
1.4 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).SSEZ={})}(this,(function(e){"use strict";e.Subscription=class{constructor(e){var t;this.keepAliveLastReceivedAt=Date.now(),this.options=e;const i=new URL(e.url),o=new URLSearchParams(Object.entries(e.searchParams||{}).reduce(((e,[t,i])=>(void 0===i||(e[t]=i),e)),{}));i.search=o.toString(),this.url=i.toString(),this.eventSource=this.connect();const n=null===(t=this.options.keepAlive)||void 0===t?void 0:t.intervalMs;n&&(this.keepAliveTimer=setInterval((()=>{Date.now()-this.keepAliveLastReceivedAt>n&&(this.eventSource=this.connect())}),1e3))}connect(){var e;this.eventSource&&this.eventSource.close();const t=new EventSource(this.url,{...this.options.eventSourceOptions||{}});return t.addEventListener("message",(e=>{this.options.onNext&&this.options.onNext(e.data)})),t.addEventListener("error",(()=>{this.options.onError&&this.options.onError(new Error("Event source error."))})),t.addEventListener((null===(e=this.options.keepAlive)||void 0===e?void 0:e.eventType)||"keepAlive",(()=>{this.keepAliveLastReceivedAt=Date.now()})),t}get closed(){return!1}unsubscribe(){"undefined"!==this.keepAliveTimer&&clearInterval(this.keepAliveTimer),this.eventSource.close(),this.options.onComplete&&this.options.onComplete()}},Object.defineProperty(e,"__esModule",{value:!0})}));