mezon-js 2.13.58 → 2.13.60

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.
@@ -721,7 +721,7 @@ function safeJSONParse(jsonStr) {
721
721
  if (jsonStr !== "") {
722
722
  console.error("Error parsing JSON:", jsonStr, error);
723
723
  }
724
- return null;
724
+ return { t: jsonStr };
725
725
  }
726
726
  }
727
727
 
@@ -7476,6 +7476,7 @@ var _DefaultSocket = class _DefaultSocket {
7476
7476
  this.cIds = {};
7477
7477
  this.nextCid = 1;
7478
7478
  this._heartbeatTimeoutMs = _DefaultSocket.DefaultHeartbeatTimeoutMs;
7479
+ this.hasConnectedBefore = false;
7479
7480
  }
7480
7481
  generatecid() {
7481
7482
  const cid = this.nextCid.toString();
@@ -7714,8 +7715,13 @@ var _DefaultSocket = class _DefaultSocket {
7714
7715
  if (this.verbose && window && window.console) {
7715
7716
  console.log(evt);
7716
7717
  }
7718
+ const isReconnect = this.hasConnectedBefore;
7719
+ this.hasConnectedBefore = true;
7717
7720
  this.pingPong();
7718
7721
  resolve(session);
7722
+ if (isReconnect) {
7723
+ this.onreconnect(evt);
7724
+ }
7719
7725
  };
7720
7726
  this.adapter.onError = (evt) => {
7721
7727
  reject(evt);
@@ -7740,6 +7746,11 @@ var _DefaultSocket = class _DefaultSocket {
7740
7746
  getHeartbeatTimeoutMs() {
7741
7747
  return this._heartbeatTimeoutMs;
7742
7748
  }
7749
+ onreconnect(evt) {
7750
+ if (this.verbose && window && window.console) {
7751
+ console.log(evt);
7752
+ }
7753
+ }
7743
7754
  ondisconnect(evt) {
7744
7755
  if (this.verbose && window && window.console) {
7745
7756
  console.log(evt);
@@ -687,7 +687,7 @@ function safeJSONParse(jsonStr) {
687
687
  if (jsonStr !== "") {
688
688
  console.error("Error parsing JSON:", jsonStr, error);
689
689
  }
690
- return null;
690
+ return { t: jsonStr };
691
691
  }
692
692
  }
693
693
 
@@ -7442,6 +7442,7 @@ var _DefaultSocket = class _DefaultSocket {
7442
7442
  this.cIds = {};
7443
7443
  this.nextCid = 1;
7444
7444
  this._heartbeatTimeoutMs = _DefaultSocket.DefaultHeartbeatTimeoutMs;
7445
+ this.hasConnectedBefore = false;
7445
7446
  }
7446
7447
  generatecid() {
7447
7448
  const cid = this.nextCid.toString();
@@ -7680,8 +7681,13 @@ var _DefaultSocket = class _DefaultSocket {
7680
7681
  if (this.verbose && window && window.console) {
7681
7682
  console.log(evt);
7682
7683
  }
7684
+ const isReconnect = this.hasConnectedBefore;
7685
+ this.hasConnectedBefore = true;
7683
7686
  this.pingPong();
7684
7687
  resolve(session);
7688
+ if (isReconnect) {
7689
+ this.onreconnect(evt);
7690
+ }
7685
7691
  };
7686
7692
  this.adapter.onError = (evt) => {
7687
7693
  reject(evt);
@@ -7706,6 +7712,11 @@ var _DefaultSocket = class _DefaultSocket {
7706
7712
  getHeartbeatTimeoutMs() {
7707
7713
  return this._heartbeatTimeoutMs;
7708
7714
  }
7715
+ onreconnect(evt) {
7716
+ if (this.verbose && window && window.console) {
7717
+ console.log(evt);
7718
+ }
7719
+ }
7709
7720
  ondisconnect(evt) {
7710
7721
  if (this.verbose && window && window.console) {
7711
7722
  console.log(evt);
package/dist/socket.d.ts CHANGED
@@ -964,6 +964,7 @@ export interface Socket {
964
964
  writeActiveArchivedThread(clan_id: string, channel_id: string): Promise<void>;
965
965
  setHeartbeatTimeoutMs(ms: number): void;
966
966
  getHeartbeatTimeoutMs(): number;
967
+ onreconnect: (evt: Event) => void;
967
968
  checkDuplicateName(name: string, condition_id: string, type: number): Promise<CheckNameExistedEvent>;
968
969
  handleMessageButtonClick: (message_id: string, channel_id: string, button_id: string, sender_id: string, user_id: string, extra_data: string) => Promise<MessageButtonClicked>;
969
970
  handleDropdownBoxSelected: (message_id: string, channel_id: string, selectbox_id: string, sender_id: string, user_id: string, value: Array<string>) => Promise<DropdownBoxSelected>;
@@ -1086,6 +1087,7 @@ export declare class DefaultSocket implements Socket {
1086
1087
  private readonly cIds;
1087
1088
  private nextCid;
1088
1089
  private _heartbeatTimeoutMs;
1090
+ private hasConnectedBefore;
1089
1091
  constructor(host: string, port: string, useSSL?: boolean, verbose?: boolean, adapter?: WebSocketAdapter, sendTimeoutMs?: number);
1090
1092
  generatecid(): string;
1091
1093
  isOpen(): boolean;
@@ -1093,6 +1095,7 @@ export declare class DefaultSocket implements Socket {
1093
1095
  disconnect(fireDisconnectEvent?: boolean): void;
1094
1096
  setHeartbeatTimeoutMs(ms: number): void;
1095
1097
  getHeartbeatTimeoutMs(): number;
1098
+ onreconnect(evt: Event): void;
1096
1099
  ondisconnect(evt: Event): void;
1097
1100
  onerror(evt: Event): void;
1098
1101
  onmessagetyping(messagetyping: MessageTypingEvent): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mezon-js",
3
- "version": "2.13.58",
3
+ "version": "2.13.60",
4
4
  "scripts": {
5
5
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
6
6
  },
package/socket.ts CHANGED
@@ -1609,6 +1609,8 @@ export interface Socket {
1609
1609
  /* Get the heartbeat timeout used by the socket to detect if it has lost connectivity to the server. */
1610
1610
  getHeartbeatTimeoutMs(): number;
1611
1611
 
1612
+ onreconnect: (evt: Event) => void;
1613
+
1612
1614
  checkDuplicateName(
1613
1615
  name: string,
1614
1616
  condition_id: string,
@@ -1865,6 +1867,7 @@ export class DefaultSocket implements Socket {
1865
1867
  private readonly cIds: { [key: string]: PromiseExecutor };
1866
1868
  private nextCid: number;
1867
1869
  private _heartbeatTimeoutMs: number;
1870
+ private hasConnectedBefore: boolean;
1868
1871
 
1869
1872
  constructor(
1870
1873
  readonly host: string,
@@ -1877,6 +1880,7 @@ export class DefaultSocket implements Socket {
1877
1880
  this.cIds = {};
1878
1881
  this.nextCid = 1;
1879
1882
  this._heartbeatTimeoutMs = DefaultSocket.DefaultHeartbeatTimeoutMs;
1883
+ this.hasConnectedBefore = false;
1880
1884
  }
1881
1885
 
1882
1886
  generatecid(): string {
@@ -2132,8 +2136,15 @@ export class DefaultSocket implements Socket {
2132
2136
  console.log(evt);
2133
2137
  }
2134
2138
 
2139
+ const isReconnect = this.hasConnectedBefore;
2140
+ this.hasConnectedBefore = true;
2141
+
2135
2142
  this.pingPong();
2136
2143
  resolve(session);
2144
+
2145
+ if (isReconnect) {
2146
+ this.onreconnect(evt);
2147
+ }
2137
2148
  };
2138
2149
  this.adapter.onError = (evt: Event) => {
2139
2150
  reject(evt);
@@ -2164,6 +2175,12 @@ export class DefaultSocket implements Socket {
2164
2175
  return this._heartbeatTimeoutMs;
2165
2176
  }
2166
2177
 
2178
+ onreconnect(evt: Event) {
2179
+ if (this.verbose && window && window.console) {
2180
+ console.log(evt);
2181
+ }
2182
+ }
2183
+
2167
2184
  ondisconnect(evt: Event) {
2168
2185
  if (this.verbose && window && window.console) {
2169
2186
  console.log(evt);
package/utils.ts CHANGED
@@ -56,6 +56,6 @@ export function safeJSONParse(jsonStr: string) {
56
56
  if (jsonStr !== "") {
57
57
  console.error('Error parsing JSON:', jsonStr, error);
58
58
  }
59
- return null; // Handle the error gracefully or throw an exception if necessary
59
+ return {t: jsonStr}; // Handle the error gracefully or throw an exception if necessary
60
60
  }
61
61
  }