@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.js CHANGED
@@ -620,7 +620,7 @@ var Call = class {
620
620
  // package.json
621
621
  var package_default = {
622
622
  name: "@koi-design/callkit",
623
- version: "2.0.0",
623
+ version: "2.0.2",
624
624
  description: "callkit",
625
625
  author: "koi",
626
626
  license: "ISC",
@@ -677,7 +677,7 @@ var Config = class {
677
677
  this.callKit = callKit;
678
678
  }
679
679
  config = {
680
- version: `v${package_default.version}`,
680
+ version: `V${package_default.version}`,
681
681
  host: "",
682
682
  log: "info",
683
683
  trackLogs: trackLogsDefaultConfig,
@@ -1503,14 +1503,11 @@ var Connect = class {
1503
1503
  caller: "Connect.register",
1504
1504
  type: "SIP",
1505
1505
  content: {
1506
- version: `V${this.callKit.config.getConfig().version}`
1506
+ version: `${this.callKit.config.getConfig().version}`
1507
1507
  }
1508
1508
  });
1509
- const version = `V${this.callKit.config.getConfig().version}`;
1510
1509
  await this.registerer.register().then(() => {
1511
- this.callKit.socket.send(SocketSendEvent.START, {
1512
- version
1513
- });
1510
+ this.callKit.socket.send(SocketSendEvent.START);
1514
1511
  }).catch(async (err) => {
1515
1512
  this.callKit.reset();
1516
1513
  this.callKit.logger.error(err?.message, {
@@ -1927,9 +1924,33 @@ var Socket = class {
1927
1924
  });
1928
1925
  return;
1929
1926
  }
1927
+ if (this.isReconnecting) {
1928
+ return;
1929
+ }
1930
1930
  this.attemptReconnect();
1931
1931
  }
1932
+ clearWebSocket() {
1933
+ if (this.ws) {
1934
+ this.ws.onopen = null;
1935
+ this.ws.onclose = null;
1936
+ this.ws.onerror = null;
1937
+ this.ws.onmessage = null;
1938
+ }
1939
+ if (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN) {
1940
+ this.ws.close();
1941
+ this.callKit.logger.info("socket clear", {
1942
+ caller: "Socket.clearWebSocket",
1943
+ type: "INCALL",
1944
+ content: {}
1945
+ });
1946
+ }
1947
+ this.ws = void 0;
1948
+ this.isConnected = false;
1949
+ }
1932
1950
  connect(socketUrl) {
1951
+ if (this.ws) {
1952
+ this.clearWebSocket();
1953
+ }
1933
1954
  this.ws = new WebSocket(socketUrl);
1934
1955
  this.ws.onopen = (ev) => this.onOpen(ev);
1935
1956
  this.ws.onclose = (ev) => this.onClose(ev);
@@ -1975,10 +1996,6 @@ var Socket = class {
1975
1996
  type: "INCALL",
1976
1997
  content: { ev }
1977
1998
  });
1978
- this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
1979
- event: "INCALL_CONNECT_ERROR",
1980
- err: ev
1981
- });
1982
1999
  if (this.socketError) {
1983
2000
  return;
1984
2001
  }
@@ -1986,6 +2003,10 @@ var Socket = class {
1986
2003
  }
1987
2004
  onError(ev) {
1988
2005
  this.socketError = true;
2006
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2007
+ event: "INCALL_CONNECT_ERROR",
2008
+ err: ev
2009
+ });
1989
2010
  this.callKit.logger.error("socket onError", {
1990
2011
  caller: "Socket.onError",
1991
2012
  type: "INCALL",
@@ -2307,17 +2328,13 @@ var Socket = class {
2307
2328
  this.lastPingTime = void 0;
2308
2329
  this.satrtConfirm = false;
2309
2330
  this.socketError = false;
2310
- if (this.ws && this.isConnected) {
2311
- this.callKit.logger.info("Closing socket connection", {
2312
- caller: "Socket.reset",
2313
- type: "INCALL",
2314
- content: {}
2315
- });
2316
- this.ws.close();
2317
- this.isConnected = false;
2318
- }
2331
+ this.clearWebSocket();
2319
2332
  }
2320
2333
  attemptReconnect() {
2334
+ if (this.reconnectTimer) {
2335
+ clearTimeout(this.reconnectTimer);
2336
+ this.reconnectTimer = void 0;
2337
+ }
2321
2338
  if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
2322
2339
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2323
2340
  event: "INCALL_RECONNECT_ERROR"