@koi-design/callkit 2.0.0 → 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.0",
3788
+ version: "2.0.2",
3789
3789
  description: "callkit",
3790
3790
  author: "koi",
3791
3791
  license: "ISC",
@@ -3842,7 +3842,7 @@ var WebCall = (() => {
3842
3842
  this.callKit = callKit;
3843
3843
  }
3844
3844
  config = {
3845
- version: `v${package_default.version}`,
3845
+ version: `V${package_default.version}`,
3846
3846
  host: "",
3847
3847
  log: "info",
3848
3848
  trackLogs: trackLogsDefaultConfig,
@@ -19066,14 +19066,11 @@ var WebCall = (() => {
19066
19066
  caller: "Connect.register",
19067
19067
  type: "SIP",
19068
19068
  content: {
19069
- version: `V${this.callKit.config.getConfig().version}`
19069
+ version: `${this.callKit.config.getConfig().version}`
19070
19070
  }
19071
19071
  });
19072
- const version = `V${this.callKit.config.getConfig().version}`;
19073
19072
  await this.registerer.register().then(() => {
19074
- this.callKit.socket.send(SocketSendEvent.START, {
19075
- version
19076
- });
19073
+ this.callKit.socket.send(SocketSendEvent.START);
19077
19074
  }).catch(async (err) => {
19078
19075
  this.callKit.reset();
19079
19076
  this.callKit.logger.error(err?.message, {
@@ -19490,9 +19487,33 @@ var WebCall = (() => {
19490
19487
  });
19491
19488
  return;
19492
19489
  }
19490
+ if (this.isReconnecting) {
19491
+ return;
19492
+ }
19493
19493
  this.attemptReconnect();
19494
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
+ }
19495
19513
  connect(socketUrl) {
19514
+ if (this.ws) {
19515
+ this.clearWebSocket();
19516
+ }
19496
19517
  this.ws = new WebSocket(socketUrl);
19497
19518
  this.ws.onopen = (ev) => this.onOpen(ev);
19498
19519
  this.ws.onclose = (ev) => this.onClose(ev);
@@ -19538,10 +19559,6 @@ var WebCall = (() => {
19538
19559
  type: "INCALL",
19539
19560
  content: { ev }
19540
19561
  });
19541
- this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19542
- event: "INCALL_CONNECT_ERROR",
19543
- err: ev
19544
- });
19545
19562
  if (this.socketError) {
19546
19563
  return;
19547
19564
  }
@@ -19549,6 +19566,10 @@ var WebCall = (() => {
19549
19566
  }
19550
19567
  onError(ev) {
19551
19568
  this.socketError = true;
19569
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19570
+ event: "INCALL_CONNECT_ERROR",
19571
+ err: ev
19572
+ });
19552
19573
  this.callKit.logger.error("socket onError", {
19553
19574
  caller: "Socket.onError",
19554
19575
  type: "INCALL",
@@ -19870,17 +19891,13 @@ var WebCall = (() => {
19870
19891
  this.lastPingTime = void 0;
19871
19892
  this.satrtConfirm = false;
19872
19893
  this.socketError = false;
19873
- if (this.ws && this.isConnected) {
19874
- this.callKit.logger.info("Closing socket connection", {
19875
- caller: "Socket.reset",
19876
- type: "INCALL",
19877
- content: {}
19878
- });
19879
- this.ws.close();
19880
- this.isConnected = false;
19881
- }
19894
+ this.clearWebSocket();
19882
19895
  }
19883
19896
  attemptReconnect() {
19897
+ if (this.reconnectTimer) {
19898
+ clearTimeout(this.reconnectTimer);
19899
+ this.reconnectTimer = void 0;
19900
+ }
19884
19901
  if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
19885
19902
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19886
19903
  event: "INCALL_RECONNECT_ERROR"