Files
Migu2.0/MiGu.Server/wwwroot/assets/useProjectionStream-DMf_8m8X.js
T
zhaowei.huangandCursor 42978930ca feat: 迁入 MiGu.Server、平台前端与车辆列表 reflection 回退
从 Simple-FR 拆出 Platform.Server 并重命名为 MiGu.Server;frontends 源码与构建脚本迁入本仓库。地图监控在 projection/cars 失败或为空时回退 reflection 车辆列表;Simple 仓库已移除旧 Platform.Server。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-29 18:16:34 +08:00

2 lines
1.2 KiB
JavaScript

import{b2 as k,bb as h}from"./index-DrvLDslf.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 b=a.url??"/api/sl/projection/stream",j=a.reconnectDelayMs??3e3,r=h(!1),u=h(null),l=new Set;let e=null,c=null,s=!1;function i(){if(s||e)return;try{e=new EventSource(b)}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,o=>{d(t,o.data)})}function d(n,t){if(!(typeof t!="string"||!t))try{const o=JSON.parse(t),v=typeof o=="object"&&o!==null&&"kind"in o?o:{kind:n??"message",payload:o};u.value=v,l.forEach(S=>{try{S(v)}catch{}})}catch{}}function f(){if(e){try{e.close()}catch{}e=null}}function p(){s||c||(c=setTimeout(()=>{c=null,i()},j))}function m(){s=!0,c&&(clearTimeout(c),c=null),f(),r.value=!1}function y(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:y,off:E}}export{D as u};