@zyzgroup/core-web 0.1.71 → 0.1.73

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.
@@ -21681,9 +21681,9 @@ class me {
21681
21681
  requestid = 0;
21682
21682
  waitings = {};
21683
21683
  listeners = {};
21684
- // wss://echo.websocket.org
21684
+ // wss://echo.websocket.org/
21685
21685
  // wss://xinge.ruolin-link.com/
21686
- // wss://tstxg.ruolin-link.com/
21686
+ // wss://test.xinge.me/
21687
21687
  constructor(t = "", e) {
21688
21688
  this.url = t, this.socketCreatorProtocols = e?.socketCreatorProtocols, this.socketCreatorOptions = e?.socketCreatorOptions || {}, this.socketCreator = e?.socketCreator || s0, this.pingInterval = e?.pingInterval || 5e3, this.onopen = e?.onopen, this.onclose = e?.onclose, this.onerror = e?.onerror, this.reconnect = typeof e?.reconnect == "boolean" ? e.reconnect : !0, this.maxReconnectAttempts = typeof e?.maxReconnectAttempts == "number" ? e.maxReconnectAttempts : 1 / 0, this._connect();
21689
21689
  }
@@ -21699,35 +21699,35 @@ class me {
21699
21699
  this.socketCreatorProtocols,
21700
21700
  this.socketCreatorOptions
21701
21701
  ), this.socket.onopen = () => {
21702
- oe(`ws(${this.url}) onopen`), this.state = me.OPEN, this.reconnectTimerID && (clearTimeout(this.reconnectTimerID), this.reconnectTimerID = void 0, this.reconnectAttempts = 0), this.ping(), this.pingTimerID = setInterval(this.ping, this.pingInterval);
21702
+ oe(`ws(${this.url}) onopen`), this.state = me.OPEN, this.ping(), this.pingTimerID = setInterval(this.ping.bind(this), this.pingInterval), this.reconnectTimerID && (clearTimeout(this.reconnectTimerID), this.reconnectTimerID = void 0, this.reconnectAttempts = 0);
21703
21703
  const t = this.messageQueue.slice();
21704
21704
  this.messageQueue = [], t.forEach(this._send), this.onopen?.();
21705
21705
  }, this.socket.onclose = (t) => {
21706
21706
  const { code: e, reason: s, wasClean: r } = t;
21707
21707
  oe(
21708
- `ws(${this.url}) onclose : code(${e}) reason(${s}) wasClean(${r})`
21708
+ `ws(${this.url}) onclose: code(${e}) reason(${s}) wasClean(${r})`
21709
21709
  ), this.state = me.CLOSED, this.pingTimerID && (clearInterval(this.pingTimerID), this.pingTimerID = void 0), this.onclose?.(t), this.reconnect && this.reconnectAttempts < this.maxReconnectAttempts && (this.socket = void 0, this.reconnectTimerID = setTimeout(
21710
21710
  this._connect.bind(this),
21711
21711
  Fa(this.reconnectAttempts++)
21712
- ));
21712
+ ), console.log(this.reconnectAttempts));
21713
21713
  }, this.socket.onerror = (t) => {
21714
- oe(`ws(${this.url}) onerror : ${t.type} ${t}`), this.onerror?.(t);
21714
+ oe(`ws(${this.url}) onerror: ${t.type} ${t}`), this.onerror?.(t);
21715
21715
  }, this.socket.onmessage = (t) => {
21716
- if (oe(`ws(${this.url}) onmessage type(${t.type}): ${Ue(t)}`), typeof t.data == "string") {
21716
+ if (oe(`ws(${this.url}) onmessage: { type: ${t.type}, data: ${t.data}}`), typeof t.data == "string") {
21717
21717
  let e;
21718
21718
  try {
21719
- e = JSON.parse(t.data);
21719
+ e = JSON.parse(t.data.substring(1));
21720
21720
  } catch (s) {
21721
- Ke(`ws(${this.url}) onmessage : parse error : ${s}`), e = {
21721
+ e = {
21722
21722
  type: "err",
21723
21723
  failureType: s.toString(),
21724
21724
  message: t.data
21725
- };
21725
+ }, Ke(`${Ue(e)}`);
21726
21726
  }
21727
21727
  if (e.body && Object.prototype.hasOwnProperty.call(e.body, "requestid")) {
21728
21728
  const s = this.waitings[e.body.requestid];
21729
21729
  s ? s.resolve?.(e.body) : Ke(
21730
- `ws(${this.url}) onmessage : but found no associated request, already timed out`
21730
+ `ws(${this.url}) onmessage: found no associated request, already timed out`
21731
21731
  );
21732
21732
  } else if (this.listeners[e.address]) {
21733
21733
  const s = this.listeners[e.address];
@@ -21738,9 +21738,9 @@ class me {
21738
21738
  message: e.message
21739
21739
  }) : s[r](null, e.body);
21740
21740
  } else
21741
- Ke(`ws(${this.url}) onmessage : unhandle string`), this.onunhandled(e);
21741
+ Ke(`ws(${this.url}) onmessage: unhandle string`), this.onunhandled(e);
21742
21742
  } else
21743
- t.data instanceof ArrayBuffer ? Ke(`ws(${this.url}) onmessage : unhandle ArrayBuffer`) : t.data instanceof Blob && Ke(`ws(${this.url}) onmessage : unhandle Blob`);
21743
+ t.data instanceof ArrayBuffer ? Ke(`ws(${this.url}) onmessage: unhandle ArrayBuffer`) : t.data instanceof Blob && Ke(`ws(${this.url}) onmessage: unhandle Blob`);
21744
21744
  });
21745
21745
  }
21746
21746
  onunhandled(t) {
@@ -21755,7 +21755,7 @@ class me {
21755
21755
  }
21756
21756
  // 可能需要根据协议变更传输格式
21757
21757
  _send(t) {
21758
- this.socket?.readyState === me.OPEN ? this.socket.send(JSON.stringify(t)) : (this.messageQueue.push(t), this._connect());
21758
+ this.socket && this.socket.readyState === me.OPEN ? this.socket.send(JSON.stringify(t)) : (this.messageQueue.push(t), this._connect());
21759
21759
  }
21760
21760
  ping() {
21761
21761
  this._send({ type: "ping" });