@zyzgroup/core-web 0.1.83 → 0.1.85

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.
@@ -21699,50 +21699,52 @@ 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.ping(), this.pingTimerID = setInterval(this.ping.bind(this), this.pingInterval), this.reconnectTimerID && (clearTimeout(this.reconnectTimerID), this.reconnectTimerID = void 0);
21702
+ oe(`ws(${this.url}) onopen`), this.state = me.OPEN, this.reconnectTimerID && (clearTimeout(this.reconnectTimerID), this.reconnectTimerID = void 0);
21703
21703
  const t = this.messageQueue.slice();
21704
- this.messageQueue = [], t.forEach(this._send.bind(this)), this.onopen?.();
21704
+ this.messageQueue = [], t.forEach(this._send.bind(this)), this.ping(), this.pingTimerID = setInterval(this.ping.bind(this), this.pingInterval), this.onopen?.();
21705
21705
  }, this.socket.onclose = (t) => {
21706
21706
  const { code: e, reason: s, wasClean: r } = t;
21707
21707
  oe(
21708
21708
  `ws(${this.url}) onclose: code(${e}) reason(${s}) wasClean(${r})`
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(
21709
+ ), this.state = me.CLOSED, this.socket = void 0, this.pingTimerID && (clearInterval(this.pingTimerID), this.pingTimerID = void 0), this.onclose?.(t), this.reconnect && this.reconnectAttempts < this.maxReconnectAttempts && (this.reconnectTimerID = setTimeout(
21710
21710
  this._connect.bind(this),
21711
21711
  Fa(this.reconnectAttempts++)
21712
21712
  ));
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}`), this.onerror?.(t);
21715
21715
  }, this.socket.onmessage = (t) => {
21716
21716
  if (oe(`ws(${this.url}) onmessage: { type: ${t.type}, data: ${t.data} }`), typeof t.data == "string") {
21717
21717
  let e;
21718
+ const s = t.data.substring(1);
21718
21719
  try {
21719
- e = JSON.parse(t.data.substring(1));
21720
- } catch (s) {
21720
+ e = JSON.parse(s);
21721
+ } catch (r) {
21721
21722
  e = [
21722
21723
  JSON.stringify({
21723
21724
  type: "err",
21724
- failureType: s.toString(),
21725
- message: t.data
21725
+ failureCode: "fe-json-parse-error",
21726
+ failureType: r.toString(),
21727
+ message: s
21726
21728
  })
21727
21729
  ];
21728
21730
  }
21729
- e.forEach((s) => {
21730
- const r = JSON.parse(s);
21731
- if (r.body && Object.prototype.hasOwnProperty.call(r.body, "requestid")) {
21732
- const i = this.waitings[r.body.requestid];
21733
- i ? i.resolve?.(r.body) : _n(
21731
+ e.forEach((r) => {
21732
+ const i = JSON.parse(r);
21733
+ if (i.body && Object.prototype.hasOwnProperty.call(i.body, "requestid")) {
21734
+ const o = this.waitings[i.body.requestid];
21735
+ o ? o.resolve?.(i.body) : _n(
21734
21736
  `ws(${this.url}) onmessage: found no associated request, already timed out`
21735
21737
  );
21736
- } else if (this.listeners[r.address]) {
21737
- const i = this.listeners[r.address];
21738
- for (let o = 0; o < i.length; o++)
21739
- r.type === "err" ? i[o]({
21740
- failureCode: r.failureCode,
21741
- failureType: r.failureType,
21742
- message: r.message
21743
- }) : i[o](null, r.body);
21738
+ } else if (this.listeners[i.address]) {
21739
+ const o = this.listeners[i.address];
21740
+ for (let a = 0; a < o.length; a++)
21741
+ i.type === "err" ? o[a]({
21742
+ failureCode: i.failureCode,
21743
+ failureType: i.failureType,
21744
+ message: i.message
21745
+ }) : o[a](null, i.body);
21744
21746
  } else
21745
- this.onunhandled(r);
21747
+ this.onunhandled(i);
21746
21748
  });
21747
21749
  } else
21748
21750
  t.data instanceof ArrayBuffer ? _n(`ws(${this.url}) onmessage: unhandle ArrayBuffer`) : t.data instanceof Blob && _n(`ws(${this.url}) onmessage: unhandle Blob`);