@koi-design/callkit 2.0.1 → 2.0.2

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/index.d.ts CHANGED
@@ -72,6 +72,7 @@ declare class Socket {
72
72
  constructor(callKit: CallKit);
73
73
  init(): void;
74
74
  private handleDisconnect;
75
+ private clearWebSocket;
75
76
  private connect;
76
77
  private onOpen;
77
78
  private resetReconnectState;
@@ -3785,7 +3785,7 @@ var WebCall = (() => {
3785
3785
  // package.json
3786
3786
  var package_default = {
3787
3787
  name: "@koi-design/callkit",
3788
- version: "2.0.1",
3788
+ version: "2.0.2",
3789
3789
  description: "callkit",
3790
3790
  author: "koi",
3791
3791
  license: "ISC",
@@ -19487,9 +19487,33 @@ var WebCall = (() => {
19487
19487
  });
19488
19488
  return;
19489
19489
  }
19490
+ if (this.isReconnecting) {
19491
+ return;
19492
+ }
19490
19493
  this.attemptReconnect();
19491
19494
  }
19495
+ clearWebSocket() {
19496
+ if (this.ws) {
19497
+ this.ws.onopen = null;
19498
+ this.ws.onclose = null;
19499
+ this.ws.onerror = null;
19500
+ this.ws.onmessage = null;
19501
+ }
19502
+ if (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN) {
19503
+ this.ws.close();
19504
+ this.callKit.logger.info("socket clear", {
19505
+ caller: "Socket.clearWebSocket",
19506
+ type: "INCALL",
19507
+ content: {}
19508
+ });
19509
+ }
19510
+ this.ws = void 0;
19511
+ this.isConnected = false;
19512
+ }
19492
19513
  connect(socketUrl) {
19514
+ if (this.ws) {
19515
+ this.clearWebSocket();
19516
+ }
19493
19517
  this.ws = new WebSocket(socketUrl);
19494
19518
  this.ws.onopen = (ev) => this.onOpen(ev);
19495
19519
  this.ws.onclose = (ev) => this.onClose(ev);
@@ -19867,17 +19891,13 @@ var WebCall = (() => {
19867
19891
  this.lastPingTime = void 0;
19868
19892
  this.satrtConfirm = false;
19869
19893
  this.socketError = false;
19870
- if (this.ws && this.isConnected) {
19871
- this.callKit.logger.info("Closing socket connection", {
19872
- caller: "Socket.reset",
19873
- type: "INCALL",
19874
- content: {}
19875
- });
19876
- this.ws.close();
19877
- this.isConnected = false;
19878
- }
19894
+ this.clearWebSocket();
19879
19895
  }
19880
19896
  attemptReconnect() {
19897
+ if (this.reconnectTimer) {
19898
+ clearTimeout(this.reconnectTimer);
19899
+ this.reconnectTimer = void 0;
19900
+ }
19881
19901
  if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
19882
19902
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19883
19903
  event: "INCALL_RECONNECT_ERROR"