Files
Migu2.0/MiGu.Server/wwwroot/assets/useProjectionStream-BoSdoSNC.js
T
zhaowei.huang 3356c2cd12 chore(web): 重新构建前端静态资源
- 更新 MiGu.Server/wwwroot/assets 产物与 index.html 入口哈希,对应本次前端源码改动
2026-05-29 23:53:00 +08:00

2 lines
1.2 KiB
JavaScript

import{b3 as k,bc as h}from"./index-C6ULY2Si.js";const g=["snapshot-tick","selection-detail","alarm","object-created","object-deleted","object-patched","object-batch-changed","pick-result","project-saved","project-loaded","car-state","mission-status","monitor-config-updated"];function D(a={}){const j=a.url??"/api/sl/projection/stream",y=a.reconnectDelayMs??3e3,r=h(!1),u=h(null),l=new Set;let e=null,o=null,s=!1;function i(){if(s||e)return;try{e=new EventSource(j)}catch{p();return}e.onopen=()=>{r.value=!0},e.onerror=()=>{r.value=!1,f(),p()},e.onmessage=t=>{d(void 0,t.data)};const n=new Set([...g,...a.extraEventKinds??[]]);for(const t of n)e.addEventListener(t,c=>{d(t,c.data)})}function d(n,t){if(!(typeof t!="string"||!t))try{const c=JSON.parse(t),v=typeof c=="object"&&c!==null&&"kind"in c?c:{kind:n??"message",payload:c};u.value=v,l.forEach(S=>{try{S(v)}catch{}})}catch{}}function f(){if(e){try{e.close()}catch{}e=null}}function p(){s||o||(o=setTimeout(()=>{o=null,i()},y))}function m(){s=!0,o&&(clearTimeout(o),o=null),f(),r.value=!1}function b(n){l.add(n)}function E(n){l.delete(n)}return a.autoConnect!==!1&&i(),k(()=>{m(),l.clear()}),{connected:r,lastEvent:u,connect:i,disconnect:m,on:b,off:E}}export{D as u};