Files
Migu2.0/MiGu.Server/wwwroot/assets/useProjectionStream-C_klWvmm.js
T
zhaowei.huangandCursor e2269e430d feat(platform): 合并车辆运维页并优化 3D 画布嵌入体验
将维护策略与车队生命周期并入车辆运维 Tab,补充旧路由重定向与 RBAC 页面 key 迁移;改进 Workspace3D 就绪探测与 wwwroot 静态资源。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-31 14:39:50 +08:00

2 lines
1.2 KiB
JavaScript

import{b6 as S,bf as h}from"./index-CC_hCGHZ.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","workspace-shortcut","viewport-style-updated"];function w(a={}){const y=a.url??"/api/sl/projection/stream",j=a.reconnectDelayMs??3e3,r=h(!1),u=h(null),s=new Set;let e=null,c=null,l=!1;function i(){if(l||e)return;try{e=new EventSource(y)}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,s.forEach(k=>{try{k(v)}catch{}})}catch{}}function f(){if(e){try{e.close()}catch{}e=null}}function p(){l||c||(c=setTimeout(()=>{c=null,i()},j))}function m(){l=!0,c&&(clearTimeout(c),c=null),f(),r.value=!1}function b(n){s.add(n)}function E(n){s.delete(n)}return a.autoConnect!==!1&&i(),S(()=>{m(),s.clear()}),{connected:r,lastEvent:u,connect:i,disconnect:m,on:b,off:E}}export{w as u};