zxq-com 0.0.33 → 0.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/zxq-com.cjs +1 -1
- package/dist/zxq-com.js +1 -1
- package/dist/zxq-ws.cjs +1 -1
- package/dist/zxq-ws.js +1 -1
- package/dist/zxqWs-CWqr1Fcn.js +137 -0
- package/dist/zxqWs-giUG6U-1.cjs +1 -0
- package/package.json +1 -1
- package/dist/zxqWs-CqPwXiEq.cjs +0 -1
- package/dist/zxqWs-DuCpomkY.js +0 -128
package/dist/zxq-com.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./zxqWs-
|
|
1
|
+
Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./zxqWs-giUG6U-1.cjs`);let t=require(`vue`);const n={iconApi:`https://api.iconify.design`};function r(e){Object.assign(n,e)}function i(e){let t=`.`,n=`__`,r=`--`,i;if(e){let i=e.blockPrefix;i&&(t=i),i=e.elementPrefix,i&&(n=i),i=e.modifierPrefix,i&&(r=i)}let a={install(e){i=e.c;let t=e.context;t.bem={},t.bem.b=null,t.bem.els=null}};function o(e){let n,r;return{before(e){n=e.bem.b,r=e.bem.els,e.bem.els=null},after(e){e.bem.b=n,e.bem.els=r},$({context:n,props:r}){return e=typeof e==`string`?e:e({context:n,props:r}),n.bem.b=e,`${r?.bPrefix||t}${n.bem.b}`}}}function s(e){let r;return{before(e){r=e.bem.els},after(e){e.bem.els=r},$({context:r,props:i}){return e=typeof e==`string`?e:e({context:r,props:i}),r.bem.els=e.split(`,`).map(e=>e.trim()),r.bem.els.map(e=>`${i?.bPrefix||t}${r.bem.b}${n}${e}`).join(`, `)}}}function c(e){return{$({context:i,props:a}){e=typeof e==`string`?e:e({context:i,props:a});let o=e.split(`,`).map(e=>e.trim());function s(e){return o.map(o=>`&${a?.bPrefix||t}${i.bem.b}${e===void 0?``:`${n}${e}`}${r}${o}`).join(`, `)}let c=i.bem.els;if(c!==null){if(process.env.NODE_ENV!==`production`&&c.length>=2)throw Error(`[css-render/plugin-bem]: m(${e}) is invalid, using modifier inside multiple elements is not allowed`);return s(c[0])}else return s()}}}function l(e){return{$({context:i,props:a}){e=typeof e==`string`?e:e({context:i,props:a});let o=i.bem.els;if(process.env.NODE_ENV!==`production`&&o!==null&&o.length>=2)throw Error(`[css-render/plugin-bem]: notM(${e}) is invalid, using modifier inside multiple elements is not allowed`);return`&:not(${a?.bPrefix||t}${i.bem.b}${o!==null&&o.length>0?`${n}${o[0]}`:``}${r}${e})`}}}return Object.assign(a,{cB:((...e)=>i(o(e[0]),e[1],e[2])),cE:((...e)=>i(s(e[0]),e[1],e[2])),cM:((...e)=>i(c(e[0]),e[1],e[2])),cNotM:((...e)=>i(l(e[0]),e[1],e[2]))}),a}function a(e){let t=0;for(let n=0;n<e.length;++n)e[n]===`&`&&++t;return t}var o=/\s*,(?![^(]*\))\s*/g,s=/\s+/g;function c(e,t){let n=[];return t.split(o).forEach(t=>{let r=a(t);if(r){if(r===1){e.forEach(e=>{n.push(t.replace(`&`,e))});return}}else{e.forEach(e=>{n.push((e&&e+` `)+t)});return}let i=[t];for(;r--;){let t=[];i.forEach(n=>{e.forEach(e=>{t.push(n.replace(`&`,e))})}),i=t}i.forEach(e=>n.push(e))}),n}function l(e,t){let n=[];return t.split(o).forEach(t=>{e.forEach(e=>{n.push((e&&e+` `)+t)})}),n}function u(e){let t=[``];return e.forEach(e=>{e&&=e.trim(),e&&(t=e.includes(`&`)?c(t,e):l(t,e))}),t.join(`, `).replace(s,` `)}function d(e){if(!e)return;let t=e.parentElement;t&&t.removeChild(e)}function f(e,t){return(t??document.head).querySelector(`style[cssr-id="${e}"]`)}function p(e){let t=document.createElement(`style`);return t.setAttribute(`cssr-id`,e),t}function m(e){return e?/^\s*@(s|m)/.test(e):!1}var h=/[A-Z]/g;function g(e){return e.replace(h,e=>`-`+e.toLowerCase())}function _(e,t=` `){return typeof e==`object`&&e?` {
|
|
2
2
|
`+Object.entries(e).map(e=>t+` ${g(e[0])}: ${e[1]};`).join(`
|
|
3
3
|
`)+`
|
|
4
4
|
`+t+`}`:`: ${e};`}function v(e,t,n){return typeof e==`function`?e({context:t.context,props:n}):e}function y(e,t,n,r){if(!t)return``;let i=v(t,n,r);if(!i)return``;if(typeof i==`string`)return`${e} {\n${i}\n}`;let a=Object.keys(i);if(a.length===0)return n.config.keepEmptyBlock?e+` {
|
package/dist/zxq-com.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as zwqWs, i as ws, n as log, r as useWs, t as EVENT_TYPE } from "./zxqWs-
|
|
1
|
+
import { a as zwqWs, i as ws, n as log, r as useWs, t as EVENT_TYPE } from "./zxqWs-CWqr1Fcn.js";
|
|
2
2
|
import { Comment, Fragment, Teleport, Text, Transition, TransitionGroup, cloneVNode, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, getCurrentInstance, h, inject, isVNode, mergeProps, nextTick, normalizeClass, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onMounted, onUnmounted, openBlock, provide, reactive, readonly, ref, renderList, renderSlot, resolveComponent, resolveDynamicComponent, shallowRef, toDisplayString, toRef, unref, useCssVars, useModel, vShow, watch, watchEffect, withCtx, withDirectives } from "vue";
|
|
3
3
|
const globalConfig = { iconApi: "https://api.iconify.design" };
|
|
4
4
|
function setConfig(e) {
|
package/dist/zxq-ws.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./zxqWs-
|
|
1
|
+
const e=require(`./zxqWs-giUG6U-1.cjs`);exports.EVENT_TYPE=e.t,exports.log=e.n,exports.useWs=e.r,exports.ws=e.i,exports.zwqWs=e.a;
|
package/dist/zxq-ws.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as zwqWs, i as ws, n as log, r as useWs, t as EVENT_TYPE } from "./zxqWs-
|
|
1
|
+
import { a as zwqWs, i as ws, n as log, r as useWs, t as EVENT_TYPE } from "./zxqWs-CWqr1Fcn.js";
|
|
2
2
|
export { EVENT_TYPE, log, useWs, ws, zwqWs };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { onBeforeUnmount, ref, watch } from "vue";
|
|
2
|
+
import { useWebSocket } from "@vueuse/core";
|
|
3
|
+
function getUUID(e = "") {
|
|
4
|
+
return e + (crypto?.randomUUID?.() || `${Date.now()}_${Math.random().toString(16).slice(2)}`);
|
|
5
|
+
}
|
|
6
|
+
function isDevelopment() {
|
|
7
|
+
return typeof process < "u" && process?.env && typeof process.env.NODE_ENV == "string" ? process.env.NODE_ENV === "development" : typeof __DEV__ < "u" ? typeof __DEV__ == "boolean" ? __DEV__ : !1 : !!(typeof window < "u" && window.__VUE_DEVTOOLS_GLOBAL_HOOK__);
|
|
8
|
+
}
|
|
9
|
+
var eventType = "ZXQ_SYNC_MESSAGE";
|
|
10
|
+
function askParent(e, y = 5e3) {
|
|
11
|
+
let b = getUUID();
|
|
12
|
+
e.messageId = b;
|
|
13
|
+
let x = new AbortController(), C = !1;
|
|
14
|
+
return new Promise((S) => {
|
|
15
|
+
window.addEventListener("message", (e) => {
|
|
16
|
+
let { type: y, payload: x } = e.data;
|
|
17
|
+
y === eventType && x.messageId === b && x.isReply && (E(), S(x));
|
|
18
|
+
}, { signal: x.signal });
|
|
19
|
+
let T = setTimeout(() => {
|
|
20
|
+
C || (E(), S({}));
|
|
21
|
+
}, y);
|
|
22
|
+
function E() {
|
|
23
|
+
C || (C = !0, x.abort(), clearTimeout(T));
|
|
24
|
+
}
|
|
25
|
+
window.parent.postMessage({
|
|
26
|
+
type: eventType,
|
|
27
|
+
payload: e
|
|
28
|
+
}, "*");
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
var wsConfig = {};
|
|
32
|
+
function log(...e) {
|
|
33
|
+
(isDevelopment() || wsConfig.debug) && console.log("【zxqWs】", ...e);
|
|
34
|
+
}
|
|
35
|
+
const EVENT_TYPE = {
|
|
36
|
+
CLIENT_NAME: "__client-name",
|
|
37
|
+
DEV1: "dev-1",
|
|
38
|
+
DEV2: "dev-2"
|
|
39
|
+
};
|
|
40
|
+
var initialized = !1, urlRef = ref(), { status, data, send, close, open } = useWebSocket(urlRef, {
|
|
41
|
+
immediate: !1,
|
|
42
|
+
autoConnect: !1,
|
|
43
|
+
heartbeat: {
|
|
44
|
+
message: "ping",
|
|
45
|
+
interval: 5e3,
|
|
46
|
+
pongTimeout: 15e3
|
|
47
|
+
},
|
|
48
|
+
autoReconnect: {
|
|
49
|
+
retries: 3,
|
|
50
|
+
delay: 1e4,
|
|
51
|
+
onFailed() {
|
|
52
|
+
console.error("超过重连次数");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}), clientId = "";
|
|
56
|
+
async function getClientId() {
|
|
57
|
+
if (!clientId) {
|
|
58
|
+
let e = await askParent({ action: "getClientId" });
|
|
59
|
+
e.clientId && (clientId = e.clientId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
var sendClientNameCompleted = !1;
|
|
63
|
+
function sendClientName() {
|
|
64
|
+
sendClientNameCompleted || (sendClientNameCompleted = !0, sendMsg({
|
|
65
|
+
event: EVENT_TYPE.CLIENT_NAME,
|
|
66
|
+
payload: { name: wsConfig.name }
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
async function sendMsg(e) {
|
|
70
|
+
sendClientName(), await getClientId(), e.clientId = clientId, send(JSON.stringify(e));
|
|
71
|
+
}
|
|
72
|
+
const ws = {
|
|
73
|
+
sendMsg,
|
|
74
|
+
close,
|
|
75
|
+
status
|
|
76
|
+
};
|
|
77
|
+
var subscribeMap = /* @__PURE__ */ new Map();
|
|
78
|
+
function zwqWs(e, y) {
|
|
79
|
+
initialized || (initialized = !0, Object.assign(wsConfig, y), urlRef.value = y.url, open(), watch(status, (e) => {
|
|
80
|
+
log("ws status", e), e === "OPEN" && sendClientName();
|
|
81
|
+
}), watch(data, (e) => {
|
|
82
|
+
if (e !== "pong") try {
|
|
83
|
+
let { sourceIp: b, event: x, payload: S } = JSON.parse(e);
|
|
84
|
+
if (y?.trustIp && b !== y.trustIp) return;
|
|
85
|
+
let C = subscribeMap.get(x);
|
|
86
|
+
C && C.forEach(({ fn: e, off: y }) => {
|
|
87
|
+
e(S), y && y();
|
|
88
|
+
});
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error("ws 数据格式有误", e);
|
|
91
|
+
}
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
function useWs(y, b) {
|
|
95
|
+
b && zwqWs(null, b), status.value === "CLOSED" && urlRef.value && !initialized && open();
|
|
96
|
+
let x = getUUID();
|
|
97
|
+
function C(e) {
|
|
98
|
+
let b = subscribeMap.get(y);
|
|
99
|
+
if (b) b.set(x, { fn: e });
|
|
100
|
+
else {
|
|
101
|
+
let b = (/* @__PURE__ */ new Map()).set(x, { fn: e });
|
|
102
|
+
subscribeMap.set(y, b);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function w() {
|
|
106
|
+
let e = subscribeMap.get(y);
|
|
107
|
+
e && e.has(x) && (e.delete(x), e.size === 0 && subscribeMap.delete(y));
|
|
108
|
+
}
|
|
109
|
+
function T(e) {
|
|
110
|
+
log("ws once");
|
|
111
|
+
let b = subscribeMap.get(y);
|
|
112
|
+
if (b) b.set(x, {
|
|
113
|
+
fn: e,
|
|
114
|
+
off: w
|
|
115
|
+
});
|
|
116
|
+
else {
|
|
117
|
+
let b = (/* @__PURE__ */ new Map()).set(x, {
|
|
118
|
+
fn: e,
|
|
119
|
+
off: w
|
|
120
|
+
});
|
|
121
|
+
subscribeMap.set(y, b);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
onBeforeUnmount(() => {
|
|
125
|
+
w();
|
|
126
|
+
});
|
|
127
|
+
function E(e) {
|
|
128
|
+
sendMsg(e);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
on: C,
|
|
132
|
+
off: w,
|
|
133
|
+
once: T,
|
|
134
|
+
emit: E
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export { zwqWs as a, ws as i, log as n, useWs as r, EVENT_TYPE as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require(`vue`),t=require(`@vueuse/core`);function n(e=``){return e+(crypto?.randomUUID?.()||`${Date.now()}_${Math.random().toString(16).slice(2)}`)}function r(){return typeof process<`u`&&process?.env&&typeof process.env.NODE_ENV==`string`?process.env.NODE_ENV===`development`:typeof __DEV__<`u`?typeof __DEV__==`boolean`?__DEV__:!1:!!(typeof window<`u`&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__)}var i=`ZXQ_SYNC_MESSAGE`;function a(e,t=5e3){let r=n();e.messageId=r;let a=new AbortController,o=!1;return new Promise(n=>{window.addEventListener(`message`,e=>{let{type:t,payload:a}=e.data;t===i&&a.messageId===r&&a.isReply&&(c(),n(a))},{signal:a.signal});let s=setTimeout(()=>{o||(c(),n({}))},t);function c(){o||(o=!0,a.abort(),clearTimeout(s))}window.parent.postMessage({type:i,payload:e},`*`)})}var o={};function s(...e){(r()||o.debug)&&console.log(`【zxqWs】`,...e)}const c={CLIENT_NAME:`__client-name`,DEV1:`dev-1`,DEV2:`dev-2`};var l=!1,u=(0,e.ref)(),{status:d,data:f,send:p,close:m,open:h}=(0,t.useWebSocket)(u,{immediate:!1,autoConnect:!1,heartbeat:{message:`ping`,interval:5e3,pongTimeout:15e3},autoReconnect:{retries:3,delay:1e4,onFailed(){console.error(`超过重连次数`)}}}),g=``;async function _(){if(!g){let e=await a({action:`getClientId`});e.clientId&&(g=e.clientId)}}var v=!1;function y(){v||(v=!0,b({event:c.CLIENT_NAME,payload:{name:o.name}}))}async function b(e){y(),await _(),e.clientId=g,p(JSON.stringify(e))}const x={sendMsg:b,close:m,status:d};var S=new Map;function C(t,n){l||(l=!0,Object.assign(o,n),u.value=n.url,h(),(0,e.watch)(d,e=>{s(`ws status`,e),e===`OPEN`&&y()}),(0,e.watch)(f,e=>{if(e!==`pong`)try{let{sourceIp:t,event:r,payload:i}=JSON.parse(e);if(n?.trustIp&&t!==n.trustIp)return;let a=S.get(r);a&&a.forEach(({fn:e,off:t})=>{e(i),t&&t()})}catch(e){console.error(`ws 数据格式有误`,e)}}))}function w(t,r){r&&C(null,r),d.value===`CLOSED`&&u.value&&!l&&h();let i=n();function a(e){let n=S.get(t);if(n)n.set(i,{fn:e});else{let n=new Map().set(i,{fn:e});S.set(t,n)}}function o(){let e=S.get(t);e&&e.has(i)&&(e.delete(i),e.size===0&&S.delete(t))}function c(e){s(`ws once`);let n=S.get(t);if(n)n.set(i,{fn:e,off:o});else{let n=new Map().set(i,{fn:e,off:o});S.set(t,n)}}(0,e.onBeforeUnmount)(()=>{o()});function f(e){b(e)}return{on:a,off:o,once:c,emit:f}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
package/package.json
CHANGED
package/dist/zxqWs-CqPwXiEq.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
let e=require(`vue`),t=require(`@vueuse/core`);function n(e=``){return e+(crypto?.randomUUID?.()||`${Date.now()}_${Math.random().toString(16).slice(2)}`)}function r(){return typeof process<`u`&&process?.env&&typeof process.env.NODE_ENV==`string`?process.env.NODE_ENV===`development`:typeof __DEV__<`u`?typeof __DEV__==`boolean`?__DEV__:!1:!!(typeof window<`u`&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__)}var i=`ZXQ_SYNC_MESSAGE`;function a(e,t=5e3){let r=n();e.messageId=r;let a=new AbortController,o=!1;return new Promise(n=>{window.addEventListener(`message`,e=>{console.log(`askParent`,e);let{type:t,payload:a}=e.data;t===i&&a.messageId===r&&(c(),n(a))},{signal:a.signal});let s=setTimeout(()=>{o||(c(),n({}))},t);function c(){o||(o=!0,a.abort(),clearTimeout(s))}window.parent.postMessage({type:i,payload:e},`*`)})}var o={};function s(...e){(r()||o.debug)&&console.log(`【zxqWs】`,...e)}const c={CLIENT_NAME:`__client-name`,DEV1:`dev-1`,DEV2:`dev-2`};var l=!1,u=(0,e.ref)(),{status:d,data:f,send:p,close:m,open:h}=(0,t.useWebSocket)(u,{immediate:!1,autoConnect:!1,heartbeat:{message:`ping`,interval:5e3,pongTimeout:15e3},autoReconnect:{retries:3,delay:1e4,onFailed(){console.error(`超过重连次数`)}}}),g=``;async function _(e){g||=(await a({action:`getClientId`})).clientId||``,e.clientId=g,p(JSON.stringify(e))}const v={sendMsg:_,close:m,status:d};var y=new Map;function b(t,n){l||(l=!0,Object.assign(o,n),u.value=n.url,h(),(0,e.watch)(d,e=>{s(`ws status`,e),e===`OPEN`&&_({event:c.CLIENT_NAME,payload:{name:n.name}})}),(0,e.watch)(f,e=>{if(e!==`pong`)try{let{sourceIp:t,event:r,payload:i}=JSON.parse(e);if(n?.trustIp&&t!==n.trustIp)return;let a=y.get(r);a&&a.forEach(({fn:e,off:t})=>{e(i),t&&t()})}catch(e){console.error(`ws 数据格式有误`,e)}}))}function x(t,r){r&&b(null,r),d.value===`CLOSED`&&u.value&&!l&&h();let i=n();function a(e){let n=y.get(t);if(n)n.set(i,{fn:e});else{let n=new Map().set(i,{fn:e});y.set(t,n)}}function o(){let e=y.get(t);e&&e.has(i)&&(e.delete(i),e.size===0&&y.delete(t))}function c(e){s(`ws once`);let n=y.get(t);if(n)n.set(i,{fn:e,off:o});else{let n=new Map().set(i,{fn:e,off:o});y.set(t,n)}}(0,e.onBeforeUnmount)(()=>{o()});function f(e){_(e)}return{on:a,off:o,once:c,emit:f}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return c}});
|
package/dist/zxqWs-DuCpomkY.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { onBeforeUnmount, ref, watch } from "vue";
|
|
2
|
-
import { useWebSocket } from "@vueuse/core";
|
|
3
|
-
function getUUID(e = "") {
|
|
4
|
-
return e + (crypto?.randomUUID?.() || `${Date.now()}_${Math.random().toString(16).slice(2)}`);
|
|
5
|
-
}
|
|
6
|
-
function isDevelopment() {
|
|
7
|
-
return typeof process < "u" && process?.env && typeof process.env.NODE_ENV == "string" ? process.env.NODE_ENV === "development" : typeof __DEV__ < "u" ? typeof __DEV__ == "boolean" ? __DEV__ : !1 : !!(typeof window < "u" && window.__VUE_DEVTOOLS_GLOBAL_HOOK__);
|
|
8
|
-
}
|
|
9
|
-
var eventType = "ZXQ_SYNC_MESSAGE";
|
|
10
|
-
function askParent(e, g = 5e3) {
|
|
11
|
-
let _ = getUUID();
|
|
12
|
-
e.messageId = _;
|
|
13
|
-
let v = new AbortController(), b = !1;
|
|
14
|
-
return new Promise((y) => {
|
|
15
|
-
window.addEventListener("message", (e) => {
|
|
16
|
-
console.log("askParent", e);
|
|
17
|
-
let { type: g, payload: v } = e.data;
|
|
18
|
-
g === eventType && v.messageId === _ && (C(), y(v));
|
|
19
|
-
}, { signal: v.signal });
|
|
20
|
-
let S = setTimeout(() => {
|
|
21
|
-
b || (C(), y({}));
|
|
22
|
-
}, g);
|
|
23
|
-
function C() {
|
|
24
|
-
b || (b = !0, v.abort(), clearTimeout(S));
|
|
25
|
-
}
|
|
26
|
-
window.parent.postMessage({
|
|
27
|
-
type: eventType,
|
|
28
|
-
payload: e
|
|
29
|
-
}, "*");
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
var wsConfig = {};
|
|
33
|
-
function log(...e) {
|
|
34
|
-
(isDevelopment() || wsConfig.debug) && console.log("【zxqWs】", ...e);
|
|
35
|
-
}
|
|
36
|
-
const EVENT_TYPE = {
|
|
37
|
-
CLIENT_NAME: "__client-name",
|
|
38
|
-
DEV1: "dev-1",
|
|
39
|
-
DEV2: "dev-2"
|
|
40
|
-
};
|
|
41
|
-
var initialized = !1, urlRef = ref(), { status, data, send, close, open } = useWebSocket(urlRef, {
|
|
42
|
-
immediate: !1,
|
|
43
|
-
autoConnect: !1,
|
|
44
|
-
heartbeat: {
|
|
45
|
-
message: "ping",
|
|
46
|
-
interval: 5e3,
|
|
47
|
-
pongTimeout: 15e3
|
|
48
|
-
},
|
|
49
|
-
autoReconnect: {
|
|
50
|
-
retries: 3,
|
|
51
|
-
delay: 1e4,
|
|
52
|
-
onFailed() {
|
|
53
|
-
console.error("超过重连次数");
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}), clientId = "";
|
|
57
|
-
async function sendMsg(e) {
|
|
58
|
-
clientId ||= (await askParent({ action: "getClientId" })).clientId || "", e.clientId = clientId, send(JSON.stringify(e));
|
|
59
|
-
}
|
|
60
|
-
const ws = {
|
|
61
|
-
sendMsg,
|
|
62
|
-
close,
|
|
63
|
-
status
|
|
64
|
-
};
|
|
65
|
-
var subscribeMap = /* @__PURE__ */ new Map();
|
|
66
|
-
function zwqWs(e, g) {
|
|
67
|
-
initialized || (initialized = !0, Object.assign(wsConfig, g), urlRef.value = g.url, open(), watch(status, (e) => {
|
|
68
|
-
log("ws status", e), e === "OPEN" && sendMsg({
|
|
69
|
-
event: EVENT_TYPE.CLIENT_NAME,
|
|
70
|
-
payload: { name: g.name }
|
|
71
|
-
});
|
|
72
|
-
}), watch(data, (e) => {
|
|
73
|
-
if (e !== "pong") try {
|
|
74
|
-
let { sourceIp: _, event: v, payload: y } = JSON.parse(e);
|
|
75
|
-
if (g?.trustIp && _ !== g.trustIp) return;
|
|
76
|
-
let b = subscribeMap.get(v);
|
|
77
|
-
b && b.forEach(({ fn: e, off: g }) => {
|
|
78
|
-
e(y), g && g();
|
|
79
|
-
});
|
|
80
|
-
} catch (e) {
|
|
81
|
-
console.error("ws 数据格式有误", e);
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
function useWs(g, _) {
|
|
86
|
-
_ && zwqWs(null, _), status.value === "CLOSED" && urlRef.value && !initialized && open();
|
|
87
|
-
let v = getUUID();
|
|
88
|
-
function b(e) {
|
|
89
|
-
let _ = subscribeMap.get(g);
|
|
90
|
-
if (_) _.set(v, { fn: e });
|
|
91
|
-
else {
|
|
92
|
-
let _ = (/* @__PURE__ */ new Map()).set(v, { fn: e });
|
|
93
|
-
subscribeMap.set(g, _);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
function x() {
|
|
97
|
-
let e = subscribeMap.get(g);
|
|
98
|
-
e && e.has(v) && (e.delete(v), e.size === 0 && subscribeMap.delete(g));
|
|
99
|
-
}
|
|
100
|
-
function S(e) {
|
|
101
|
-
log("ws once");
|
|
102
|
-
let _ = subscribeMap.get(g);
|
|
103
|
-
if (_) _.set(v, {
|
|
104
|
-
fn: e,
|
|
105
|
-
off: x
|
|
106
|
-
});
|
|
107
|
-
else {
|
|
108
|
-
let _ = (/* @__PURE__ */ new Map()).set(v, {
|
|
109
|
-
fn: e,
|
|
110
|
-
off: x
|
|
111
|
-
});
|
|
112
|
-
subscribeMap.set(g, _);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
onBeforeUnmount(() => {
|
|
116
|
-
x();
|
|
117
|
-
});
|
|
118
|
-
function C(e) {
|
|
119
|
-
sendMsg(e);
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
on: b,
|
|
123
|
-
off: x,
|
|
124
|
-
once: S,
|
|
125
|
-
emit: C
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
export { zwqWs as a, ws as i, log as n, useWs as r, EVENT_TYPE as t };
|