UNPKG

n8n-editor-ui

Version:

Workflow Editor UI for n8n

2 lines 4.4 kB
(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`n8n@2.13.4`}}catch{}})();try{(function(){var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`d0c6d3e2-2961-415a-ab45-699b182514c9`,e._sentryDebugIdIdentifier=`sentry-dbid-d0c6d3e2-2961-415a-ab45-699b182514c9`)})()}catch{}import{Ft as e,S as t,gt as n}from"./vue.runtime.esm-bundler-D9KLAxvJ.js";import{As as r,sl as i}from"./users.store-BHWXXawf.js";import{gl as a,oi as o,wl as s}from"./constants-CIP7tKq1.js";import{j as c,r as l}from"./_baseOrderBy-CaKruttV.js";const u=t=>{let{interval:n,onHeartbeat:r}=t,i=e(null);return{startHeartbeat:()=>{i.value=setInterval(r,n)},stopHeartbeat:()=>{i.value&&=(clearInterval(i.value),null)}}},d=({onAttempt:t,onAttemptScheduled:n})=>{let r=e(null),i=e(0);return{scheduleReconnect:()=>{let e=Math.min(1e3*2**i.value,15e3);i.value++,n(e),r.value=setTimeout(()=>{t()},e)},stopReconnectTimer:()=>{r.value&&=(clearTimeout(r.value),null)},resetConnectionAttempts:()=>{i.value=0}}},f=t=>{let n=e(!1),r=e(null),{startHeartbeat:i,stopHeartbeat:a}=u({interval:3e4,onHeartbeat:()=>{r.value?.send(JSON.stringify(o()))}}),s=()=>{r.value?.removeEventListener(`open`,s),n.value=!0,i(),h.resetConnectionAttempts()},c=e=>{console.warn(`[WebSocketClient] Connection lost, code=${e.code??`unknown`}`),p(),h.scheduleReconnect()},l=e=>{t.onMessage(e.data)},f=e=>{console.warn(`[WebSocketClient] Connection error:`,e)},p=()=>{r.value&&=(a(),h.stopReconnectTimer(),r.value.removeEventListener(`message`,l),r.value.removeEventListener(`error`,f),r.value.removeEventListener(`close`,c),r.value.close(1e3),null),n.value=!1},m=()=>{p(),r.value=new WebSocket(t.url),r.value.addEventListener(`open`,s),r.value.addEventListener(`message`,l),r.value.addEventListener(`error`,f),r.value.addEventListener(`close`,c),r.value.binaryType=`arraybuffer`},h=d({onAttempt:m,onAttemptScheduled:e=>{console.log(`[WebSocketClient] Attempting to reconnect in ${e}ms`)}});return{isConnected:n,connect:m,disconnect:p,sendMessage:e=>{if(!n.value||!r.value)throw Error(`Not connected to the server`);r.value.send(e)}}},p=t=>{let n=e(!1),r=e(null),i=()=>{n.value=!0,l.resetConnectionAttempts()},a=()=>{console.warn(`[EventSourceClient] Connection lost`),n.value=!1,l.scheduleReconnect()},o=e=>{t.onMessage(e.data)},s=()=>{r.value&&=(l.stopReconnectTimer(),r.value.close(),null),n.value=!1},c=()=>{s(),r.value=new EventSource(t.url,{withCredentials:!0}),r.value.addEventListener(`open`,i),r.value.addEventListener(`message`,o),r.value.addEventListener(`close`,a)},l=d({onAttempt:c,onAttemptScheduled:e=>{console.log(`[EventSourceClient] Attempting to reconnect in ${e}ms`)}});return{isConnected:n,connect:c,disconnect:s,sendMessage:e=>{}}},m=c(i.PUSH,()=>{let i=l(),o=r(),c=e([]),u=e(!1),d=e(!1),m=e([]),h=e=>(m.value.push(e),()=>{let t=m.value.indexOf(e);t!==-1&&m.value.splice(t,1)}),g=t(()=>o.pushBackend===`websocket`),_=()=>{let e=i.restUrl,t=`/push?pushRef=${i.pushRef}`;if(g.value){let{protocol:n,host:r}=window.location;return`${e.startsWith(`http`)?e.replace(/^http/,`ws`):`${n===`https:`?`wss`:`ws`}://${r+e}`}${t}`}else return`${e}${t}`};async function v(e){e instanceof ArrayBuffer&&(e=new TextDecoder(`utf-8`).decode(new Uint8Array(e)));let t;try{t=JSON.parse(e)}catch{return}m.value.forEach(e=>{e(t)})}let y=_(),b=t(()=>g.value?f({url:y,onMessage:v}):p({url:y,onMessage:v}));function x(e){b.value.isConnected.value?b.value.sendMessage(JSON.stringify(e)):c.value.push(e)}let S=()=>s(a.CONNECTION.WEBSOCKET_DISCONNECT),C=!1,w=null,T=null;return n(()=>b.value.isConnected.value,e=>{if(e&&(d.value=!1),e&&c.value.length){for(let e of c.value)x(e);c.value=[]}}),{isConnected:t(()=>b.value.isConnected.value),isConnecting:d,isConnectionRequested:u,onMessageReceivedHandlers:m,addEventListener:h,pushConnect:()=>{C=!0,w&&clearTimeout(w),w=setTimeout(()=>{C=!1,w=null},S()),T&&=(clearTimeout(T),null),u.value=!0,d.value=!0,b.value.connect()},pushDisconnect:()=>{C||(T&&clearTimeout(T),T=setTimeout(()=>{if(C){T=null;return}u.value=!1,d.value=!1,b.value.disconnect(),T=null},S()))},send:x,clearQueue:()=>{c.value=[]}}});export{u as n,m as t}; //# sourceMappingURL=pushConnection.store-L5aofOKN.js.map