@koi-design/callkit 2.0.4 → 2.0.5-beta.1

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.
@@ -3668,6 +3668,18 @@ var WebCall = (() => {
3668
3668
  interval: 5e3,
3669
3669
  maxSize: 8192
3670
3670
  };
3671
+ var SOCKET_RECONNECT_CONFIG = {
3672
+ enabled: true,
3673
+ maxAttempts: 3,
3674
+ delay: 1e3,
3675
+ pingInterval: 3e4,
3676
+ pingTimeout: 5e3
3677
+ };
3678
+ var SIP_RECONNECT_CONFIG = {
3679
+ enabled: true,
3680
+ maxAttempts: 3,
3681
+ delay: 1e3
3682
+ };
3671
3683
 
3672
3684
  // core/call.ts
3673
3685
  var Call = class {
@@ -3810,14 +3822,14 @@ var WebCall = (() => {
3810
3822
  // package.json
3811
3823
  var package_default = {
3812
3824
  name: "@koi-design/callkit",
3813
- version: "2.0.4",
3825
+ version: "2.0.5-beta.1",
3814
3826
  description: "callkit",
3815
3827
  author: "koi",
3816
3828
  license: "ISC",
3817
3829
  scripts: {
3818
3830
  build: "tsup",
3819
- "build:watch": "tsup --watch",
3820
- dev: "vite",
3831
+ sraet: "vite",
3832
+ dev: "tsup --watch",
3821
3833
  lint: "eslint -c ../../.eslintrc.js --ext .jsx,.js,.tsx,.ts ./package --fix",
3822
3834
  release: "tsup && node scripts/pkg.js"
3823
3835
  },
@@ -3874,6 +3886,10 @@ var WebCall = (() => {
3874
3886
  audioRef: void 0,
3875
3887
  constrains: constrainsDefault,
3876
3888
  socket: "",
3889
+ reconnect: {
3890
+ sip: SIP_RECONNECT_CONFIG,
3891
+ incall: SOCKET_RECONNECT_CONFIG
3892
+ },
3877
3893
  userInfo: {
3878
3894
  wsUrl: "",
3879
3895
  logGather: false,
@@ -3958,7 +3974,16 @@ var WebCall = (() => {
3958
3974
  return true;
3959
3975
  }
3960
3976
  getTrackLogsConfig() {
3961
- return this.config?.trackLogs ?? trackLogsDefaultConfig;
3977
+ return {
3978
+ ...trackLogsDefaultConfig,
3979
+ ...this.config?.trackLogs
3980
+ };
3981
+ }
3982
+ getReconnectConfig(type) {
3983
+ const config = this.config?.reconnect?.[type] ?? (type === "sip" ? SIP_RECONNECT_CONFIG : SOCKET_RECONNECT_CONFIG);
3984
+ return {
3985
+ ...config
3986
+ };
3962
3987
  }
3963
3988
  enableTrackLogs(enabled) {
3964
3989
  this.config.trackLogs.enabled = enabled;
@@ -18519,10 +18544,6 @@ var WebCall = (() => {
18519
18544
  };
18520
18545
 
18521
18546
  // core/connect.ts
18522
- var DEFAULT_RECONNECT_CONFIG = {
18523
- maxAttempts: 3,
18524
- delay: 500
18525
- };
18526
18547
  var MAX_HEARTBEAT_COUNT = 6;
18527
18548
  function convertObjectStringToJSON(input) {
18528
18549
  const corrected = input.replace(/(\w+):\s*'(.*?)'/g, '"$1": "$2"').replace(/'/g, '"');
@@ -18554,10 +18575,6 @@ var WebCall = (() => {
18554
18575
  };
18555
18576
  var Connect = class {
18556
18577
  callKit;
18557
- /**
18558
- *@description Reconnect config
18559
- */
18560
- reconnectConfig;
18561
18578
  /**
18562
18579
  *@description Whether muted
18563
18580
  */
@@ -18597,11 +18614,9 @@ var WebCall = (() => {
18597
18614
  hasInvite = false;
18598
18615
  constructor(callKit) {
18599
18616
  this.callKit = callKit;
18600
- const { reconnect = {} } = this.callKit.config.getConfig();
18601
- this.reconnectConfig = {
18602
- ...DEFAULT_RECONNECT_CONFIG,
18603
- ...reconnect
18604
- };
18617
+ }
18618
+ get reconnectConfig() {
18619
+ return this.callKit.config.getReconnectConfig("sip");
18605
18620
  }
18606
18621
  // current call id for invite data
18607
18622
  currentCallId = null;
@@ -19110,7 +19125,6 @@ var WebCall = (() => {
19110
19125
  });
19111
19126
  },
19112
19127
  onDisconnect: (error) => {
19113
- console.log("onDisconnect", error);
19114
19128
  if (error) {
19115
19129
  this.callKit.logger.info("SIP User Agent Disconnected with error", {
19116
19130
  caller: "Connect.register",
@@ -19244,6 +19258,7 @@ var WebCall = (() => {
19244
19258
  }
19245
19259
  });
19246
19260
  });
19261
+ this.setRegister(false);
19247
19262
  }
19248
19263
  async call(callback) {
19249
19264
  this.callKit.logger.info("connect call", {
@@ -19267,6 +19282,8 @@ var WebCall = (() => {
19267
19282
  * @param register
19268
19283
  */
19269
19284
  setRegister(register) {
19285
+ if (this.isRegister === register)
19286
+ return;
19270
19287
  this.callKit.logger.info("connect setRegister", {
19271
19288
  caller: "Connect.setRegister",
19272
19289
  type: "SIP",
@@ -19479,33 +19496,47 @@ var WebCall = (() => {
19479
19496
  };
19480
19497
 
19481
19498
  // core/socket.ts
19482
- var RECONNECT_CONFIG = {
19483
- enabled: true,
19484
- maxAttempts: 3,
19485
- delay: 1e3,
19486
- pingInterval: 3e4,
19487
- pingTimeout: 5e3
19488
- };
19489
19499
  var Socket = class {
19490
19500
  callKit;
19491
19501
  ws;
19492
- socketConfig;
19493
19502
  lastPingTime = void 0;
19494
- isConnected = false;
19495
19503
  pingTimer;
19496
- // Whether received start confirmation
19497
- satrtConfirm = false;
19504
+ /**
19505
+ * @description reconnect timer
19506
+ */
19498
19507
  reconnectTimer;
19499
- isReconnecting = false;
19508
+ /**
19509
+ * @description reconnect attempts
19510
+ */
19500
19511
  reconnectAttempts = 0;
19501
- socketError = false;
19512
+ /**
19513
+ * @description connect auth state
19514
+ * @default {
19515
+ * satrtConfirm: false,
19516
+ * isConnected: false,
19517
+ * isReconnecting: false,
19518
+ * isAuthenticated: false,
19519
+ * isError: false
19520
+ * }
19521
+ */
19522
+ connectAuthState = {
19523
+ satrtConfirm: false,
19524
+ isConnected: false,
19525
+ isReconnecting: false,
19526
+ isAuthenticated: false,
19527
+ isError: false
19528
+ };
19529
+ get satrtConfirm() {
19530
+ return this.connectAuthState.satrtConfirm;
19531
+ }
19532
+ get isError() {
19533
+ return this.connectAuthState.isError;
19534
+ }
19502
19535
  constructor(callKit) {
19503
19536
  this.callKit = callKit;
19504
- const { reconnect } = this.callKit.config.getConfig();
19505
- this.socketConfig = {
19506
- ...RECONNECT_CONFIG,
19507
- ...reconnect
19508
- };
19537
+ }
19538
+ get reconnectConfig() {
19539
+ return this.callKit.config.getReconnectConfig("incall");
19509
19540
  }
19510
19541
  init() {
19511
19542
  const { socket } = this.callKit.config.getConfig();
@@ -19518,19 +19549,22 @@ var WebCall = (() => {
19518
19549
  });
19519
19550
  this.connect(socket);
19520
19551
  }
19552
+ setConnectAuthState(key, value) {
19553
+ if (this.connectAuthState[key] === value)
19554
+ return;
19555
+ this.connectAuthState[key] = value;
19556
+ }
19521
19557
  handleDisconnect() {
19522
- this.isConnected = false;
19523
- if (!this.callKit.config.isLogin() || !this.socketConfig.enabled) {
19524
- this.reset();
19558
+ this.setConnectAuthState("isConnected", false);
19559
+ const { enabled } = this.reconnectConfig;
19560
+ if (!this.callKit.config.isLogin() || !enabled) {
19561
+ this.callKit.reset();
19525
19562
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19526
19563
  event: "INCALL_NOT_CONNECTED"
19527
19564
  });
19528
19565
  return;
19529
19566
  }
19530
- if (this.socketError) {
19531
- return;
19532
- }
19533
- if (this.isReconnecting) {
19567
+ if (this.connectAuthState.isReconnecting) {
19534
19568
  return;
19535
19569
  }
19536
19570
  this.attemptReconnect();
@@ -19551,7 +19585,7 @@ var WebCall = (() => {
19551
19585
  });
19552
19586
  }
19553
19587
  this.ws = void 0;
19554
- this.isConnected = false;
19588
+ this.setConnectAuthState("isConnected", false);
19555
19589
  }
19556
19590
  connect(socketUrl) {
19557
19591
  if (this.ws) {
@@ -19569,11 +19603,11 @@ var WebCall = (() => {
19569
19603
  type: "INCALL",
19570
19604
  content: { ev }
19571
19605
  });
19572
- this.socketError = false;
19573
- this.isConnected = true;
19606
+ this.setConnectAuthState("isConnected", true);
19574
19607
  this.lastPingTime = Date.now();
19575
19608
  this.checkPing();
19576
- if (this.isReconnecting) {
19609
+ if (this.connectAuthState.isReconnecting) {
19610
+ this.setConnectAuthState("isReconnecting", false);
19577
19611
  this.callKit.logger.info("reconnect success", {
19578
19612
  caller: "Socket.onOpen",
19579
19613
  type: "INCALL",
@@ -19586,15 +19620,28 @@ var WebCall = (() => {
19586
19620
  event: "INCALL_RECONNECT_SUCCESS"
19587
19621
  });
19588
19622
  }
19589
- this.resetReconnectState();
19590
19623
  }
19591
- resetReconnectState() {
19592
- this.isReconnecting = false;
19624
+ resetConnectState() {
19625
+ this.connectAuthState = {
19626
+ satrtConfirm: false,
19627
+ isConnected: false,
19628
+ isReconnecting: false,
19629
+ isAuthenticated: false,
19630
+ isError: false
19631
+ };
19593
19632
  this.reconnectAttempts = 0;
19594
19633
  if (this.reconnectTimer) {
19595
19634
  clearTimeout(this.reconnectTimer);
19596
19635
  this.reconnectTimer = void 0;
19597
19636
  }
19637
+ this.callKit.logger.info("reset connect state", {
19638
+ caller: "Socket.resetConnectState",
19639
+ type: "INCALL",
19640
+ content: {
19641
+ reconnectAttempts: this.reconnectAttempts,
19642
+ connectAuthState: this.connectAuthState
19643
+ }
19644
+ });
19598
19645
  }
19599
19646
  onClose(ev) {
19600
19647
  this.callKit.logger.info("socket onClose", {
@@ -19605,7 +19652,6 @@ var WebCall = (() => {
19605
19652
  this.handleDisconnect();
19606
19653
  }
19607
19654
  onError(ev) {
19608
- this.socketError = true;
19609
19655
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19610
19656
  event: "INCALL_CONNECT_ERROR",
19611
19657
  err: ev
@@ -19644,7 +19690,7 @@ var WebCall = (() => {
19644
19690
  });
19645
19691
  content = data.data;
19646
19692
  }
19647
- this.callKit.logger.info("socket onMessage", {
19693
+ this.callKit.logger.info(`socket onMessage: ${data.event}`, {
19648
19694
  caller: "Socket.onMessage",
19649
19695
  type: "INCALL",
19650
19696
  content: {
@@ -19658,134 +19704,38 @@ var WebCall = (() => {
19658
19704
  return;
19659
19705
  }
19660
19706
  if (data.event === SocketReceiveEvent.START_CONFIRM) {
19661
- this.callKit.logger.info("start confirm success", {
19662
- caller: "Socket.onMessage",
19663
- type: "INCALL",
19664
- content: {
19665
- data: content,
19666
- event: SocketReceiveEvent.START_CONFIRM
19667
- }
19668
- });
19669
- this.satrtConfirm = true;
19670
- }
19671
- if (data.event === SocketReceiveEvent.CALL_SUCCESS) {
19672
- this.callKit.logger.info("call success", {
19673
- caller: "Socket.onMessage",
19674
- type: "INCALL",
19675
- content: {
19676
- data: content,
19677
- event: SocketReceiveEvent.CALL_SUCCESS
19678
- }
19679
- });
19680
- }
19681
- if (data.event === SocketReceiveEvent.CALL_FAILED) {
19682
- this.callKit.logger.info(data.msg, {
19683
- caller: "Socket.onMessage",
19684
- type: "INCALL",
19685
- content: {
19686
- data: content,
19687
- errCode: ErrorCode.SOCKET_CALL_ERROR
19688
- }
19689
- });
19707
+ this.setConnectAuthState("satrtConfirm", true);
19690
19708
  }
19691
19709
  if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
19692
19710
  this.callKit.trigger(KitEvent.CALL_RINGING, /* @__PURE__ */ new Date());
19693
- this.callKit.logger.info(data.msg, {
19694
- caller: `Socket.onMessage:${data.event}`,
19695
- type: "INCALL",
19696
- content: {
19697
- data: content,
19698
- event: SocketReceiveEvent.CUSTOMER_RINGING
19699
- }
19700
- });
19701
19711
  }
19702
19712
  if (data.event === SocketReceiveEvent.CUSTOMER_PICK_UP) {
19703
- this.callKit.logger.info(data.msg, {
19704
- caller: "Socket.onMessage",
19705
- type: "INCALL",
19706
- content: {
19707
- data: content,
19708
- event: SocketReceiveEvent.CUSTOMER_PICK_UP
19709
- }
19710
- });
19711
19713
  this.callKit.trigger(KitEvent.CALL_PICK_UP, /* @__PURE__ */ new Date());
19712
19714
  }
19713
19715
  if (data.event === SocketReceiveEvent.AGENT_PICK_UP) {
19714
- this.callKit.logger.info(data.msg, {
19715
- caller: "Socket.onMessage",
19716
- type: "INCALL",
19717
- content: {
19718
- data: content,
19719
- event: SocketReceiveEvent.AGENT_PICK_UP
19720
- }
19721
- });
19722
19716
  this.callKit.trigger(KitEvent.AGENT_PICK_UP, /* @__PURE__ */ new Date());
19723
19717
  }
19724
19718
  if (data.event === SocketReceiveEvent.CUSTOMER_HANG_UP) {
19725
- this.callKit.logger.info(data.msg, {
19726
- caller: `Socket.onMessage:${data.event}`,
19727
- type: "INCALL",
19728
- content: {
19729
- data: content,
19730
- event: SocketReceiveEvent.CUSTOMER_HANG_UP
19731
- }
19732
- });
19733
19719
  this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
19734
19720
  if (content?.callUuid) {
19735
19721
  this.callKit.connect.socketTriggerHangup(content.callUuid);
19736
19722
  }
19737
19723
  }
19738
19724
  if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
19739
- this.callKit.logger.info(data.msg, {
19740
- caller: "Socket.onMessage",
19741
- type: "INCALL",
19742
- content: {
19743
- data: content,
19744
- event: SocketReceiveEvent.CUSTOMER_NO_ANSWER
19745
- }
19746
- });
19747
19725
  this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
19748
19726
  if (content?.callUuid) {
19749
19727
  this.callKit.connect.socketTriggerHangup(content.callUuid);
19750
19728
  }
19751
19729
  }
19752
19730
  if (data.event === SocketReceiveEvent.CALL_CDR) {
19753
- this.callKit.logger.info(data.msg, {
19754
- caller: `Socket.onMessage:${data.event}`,
19755
- type: "INCALL",
19756
- content: {
19757
- data: content,
19758
- event: SocketReceiveEvent.CALL_CDR
19759
- }
19760
- });
19761
19731
  this.callKit.trigger(KitEvent.CALL_CDR, content);
19762
19732
  }
19763
- if (data.event === SocketReceiveEvent.STOP_CONFIRM) {
19764
- this.callKit.logger.info(data.msg, {
19765
- caller: `Socket.onMessage:${data.event}`,
19766
- type: "INCALL",
19767
- content: {
19768
- data: content,
19769
- event: SocketReceiveEvent.STOP_CONFIRM
19770
- }
19771
- });
19772
- }
19773
19733
  if (data.event === SocketReceiveEvent.CLOSE) {
19774
19734
  const { userInfo } = this.callKit.config.getConfig();
19775
- this.callKit.logger.info(data.msg, {
19776
- caller: `Socket.onMessage:${data.event}`,
19777
- type: "INCALL",
19778
- content: {
19779
- data: content,
19780
- event: SocketReceiveEvent.CLOSE
19781
- }
19782
- });
19783
- this.send(SocketSendEvent.END, {
19784
- agentId: userInfo.agentId
19785
- });
19735
+ this.send(SocketSendEvent.END, { agentId: userInfo.agentId });
19786
19736
  }
19787
19737
  if (data.event === SocketReceiveEvent.ERROR) {
19788
- this.socketError = true;
19738
+ this.setConnectAuthState("isError", true);
19789
19739
  this.callKit.reset();
19790
19740
  this.callKit.logger.error(data.msg, {
19791
19741
  caller: `Socket.onMessage:${data.event}`,
@@ -19797,7 +19747,7 @@ var WebCall = (() => {
19797
19747
  });
19798
19748
  }
19799
19749
  if (data.event === SocketReceiveEvent.SESSION_ERROR) {
19800
- this.socketError = true;
19750
+ this.setConnectAuthState("isError", true);
19801
19751
  this.callKit.reset();
19802
19752
  this.callKit.logger.error(data.msg, {
19803
19753
  caller: `Socket.onMessage:${data.event}`,
@@ -19809,14 +19759,6 @@ var WebCall = (() => {
19809
19759
  });
19810
19760
  }
19811
19761
  if (data.event === SocketReceiveEvent.AGENT_NO_ANSWER) {
19812
- this.callKit.logger.info(data.msg, {
19813
- caller: `Socket.onMessage:${data.event}`,
19814
- type: "INCALL",
19815
- content: {
19816
- data: content,
19817
- event: SocketReceiveEvent.AGENT_NO_ANSWER
19818
- }
19819
- });
19820
19762
  if (content?.callUuid) {
19821
19763
  this.callKit.connect.socketTriggerHangup(content.callUuid);
19822
19764
  }
@@ -19824,7 +19766,7 @@ var WebCall = (() => {
19824
19766
  this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
19825
19767
  }
19826
19768
  send(event, message) {
19827
- if (!this.isConnected) {
19769
+ if (!this.connectAuthState.isConnected) {
19828
19770
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19829
19771
  event: "INCALL_NOT_CONNECTED"
19830
19772
  });
@@ -19883,23 +19825,16 @@ var WebCall = (() => {
19883
19825
  }
19884
19826
  }
19885
19827
  ping() {
19886
- if (!this.isConnected)
19828
+ if (!this.connectAuthState.isConnected)
19887
19829
  return;
19888
19830
  this.send(SocketSendEvent.PING);
19889
- this.callKit.logger.info(`socket ping`, {
19890
- caller: "Socket.ping",
19891
- type: "INCALL",
19892
- content: {
19893
- lastPingTime: this.lastPingTime
19894
- }
19895
- });
19896
19831
  const now = Date.now();
19897
- const { pingInterval, pingTimeout } = this.socketConfig;
19832
+ const { pingInterval, pingTimeout } = this.reconnectConfig;
19898
19833
  if (now - this.lastPingTime > pingInterval + pingTimeout) {
19899
- if (this.ws && this.isConnected) {
19834
+ if (this.ws && this.connectAuthState.isConnected) {
19900
19835
  this.ws.close(4001, "ping timeout");
19901
19836
  } else {
19902
- this.reset();
19837
+ this.callKit.reset();
19903
19838
  }
19904
19839
  this.callKit.logger.error("socket ping timeout", {
19905
19840
  caller: "Socket.ping",
@@ -19915,21 +19850,29 @@ var WebCall = (() => {
19915
19850
  clearInterval(this.pingTimer);
19916
19851
  }
19917
19852
  this.ping();
19853
+ const { pingInterval } = this.reconnectConfig;
19918
19854
  this.pingTimer = setInterval(() => {
19919
19855
  this.ping();
19920
- }, this.socketConfig.pingInterval);
19856
+ }, pingInterval);
19921
19857
  }
19922
19858
  /**
19923
19859
  * reset socket connection and all states
19924
19860
  */
19925
- async reset() {
19861
+ async reset(config) {
19862
+ const { focus = false } = config || {};
19926
19863
  if (this.pingTimer) {
19927
19864
  clearInterval(this.pingTimer);
19928
19865
  this.pingTimer = void 0;
19929
19866
  }
19930
- this.resetReconnectState();
19867
+ if (focus) {
19868
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19869
+ event: "INCALL_RESET"
19870
+ });
19871
+ this.resetConnectState();
19872
+ this.setConnectAuthState("isConnected", false);
19873
+ }
19931
19874
  this.lastPingTime = void 0;
19932
- this.satrtConfirm = false;
19875
+ this.setConnectAuthState("satrtConfirm", false);
19933
19876
  this.clearWebSocket();
19934
19877
  }
19935
19878
  attemptReconnect() {
@@ -19937,11 +19880,12 @@ var WebCall = (() => {
19937
19880
  clearTimeout(this.reconnectTimer);
19938
19881
  this.reconnectTimer = void 0;
19939
19882
  }
19940
- if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
19883
+ const { maxAttempts } = this.reconnectConfig;
19884
+ if (this.reconnectAttempts >= maxAttempts) {
19941
19885
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19942
19886
  event: "INCALL_RECONNECT_ERROR"
19943
19887
  });
19944
- this.reset();
19888
+ this.callKit.reset();
19945
19889
  this.callKit.logger.error("Maximum reconnection attempts reached", {
19946
19890
  caller: "Socket.attemptReconnect",
19947
19891
  type: "INCALL",
@@ -19957,17 +19901,17 @@ var WebCall = (() => {
19957
19901
  event: "INCALL_RECONNECT_START"
19958
19902
  });
19959
19903
  }
19960
- this.isReconnecting = true;
19904
+ this.setConnectAuthState("isReconnecting", true);
19961
19905
  this.reconnectAttempts += 1;
19962
- const { delay } = this.socketConfig;
19906
+ const { delay } = this.reconnectConfig;
19963
19907
  this.callKit.logger.info(
19964
- `Preparing reconnection attempt ${this.reconnectAttempts}/${this.socketConfig.maxAttempts}, delay: ${delay}ms`,
19908
+ `Preparing reconnection attempt ${this.reconnectAttempts}/${maxAttempts}, delay: ${delay}ms`,
19965
19909
  {
19966
19910
  caller: "Socket.attemptReconnect",
19967
19911
  type: "INCALL",
19968
19912
  content: {
19969
19913
  reconnectAttempts: this.reconnectAttempts,
19970
- maxAttempts: this.socketConfig.maxAttempts,
19914
+ maxAttempts,
19971
19915
  delay
19972
19916
  }
19973
19917
  }
@@ -19994,17 +19938,34 @@ var WebCall = (() => {
19994
19938
  this.connect = new Connect(this);
19995
19939
  this.callCenter = new Call(this);
19996
19940
  this.socket = new Socket(this);
19997
- this.config.setConfig("log", options.log);
19998
- this.config.setConfig("trackLogs", options.trackLogs);
19999
- this.config.setConfig("audioRef", options.audioRef);
20000
- this.config.setConfig("host", options.host);
19941
+ this.logger = new Logger(this, options.log);
19942
+ if (options.log) {
19943
+ this.config.setConfig("log", options.log);
19944
+ }
19945
+ if (options.trackLogs) {
19946
+ this.config.setConfig("trackLogs", {
19947
+ ...trackLogsDefaultConfig,
19948
+ ...options.trackLogs
19949
+ });
19950
+ }
19951
+ if (options.audioRef) {
19952
+ this.config.setConfig("audioRef", options.audioRef);
19953
+ }
19954
+ if (options.host) {
19955
+ this.config.setConfig("host", options.host);
19956
+ }
20001
19957
  this.config.setConfig(
20002
19958
  "constrains",
20003
19959
  options.constrains || constrainsDefault
20004
19960
  );
20005
19961
  this.config.setConfig("socket", options.socket);
20006
- this.config.setConfig("reconnect", options.reconnect);
20007
- this.logger = new Logger(this, options.log);
19962
+ this.config.setConfig("reconnect", {
19963
+ sip: { ...SIP_RECONNECT_CONFIG, ...options.reconnect?.sip || {} },
19964
+ incall: {
19965
+ ...SOCKET_RECONNECT_CONFIG,
19966
+ ...options.reconnect?.incall || {}
19967
+ }
19968
+ });
20008
19969
  this.logger.info("callKit init", {
20009
19970
  caller: "CallKit.init",
20010
19971
  content: options
@@ -20042,6 +20003,13 @@ var WebCall = (() => {
20042
20003
  encryptionPassword
20043
20004
  }
20044
20005
  });
20006
+ if (this.socket.isError) {
20007
+ this.logger.warn("socket is error", {
20008
+ caller: "CallKit.login",
20009
+ content: { username, password, extra, socketError: this.socket.isError }
20010
+ });
20011
+ return;
20012
+ }
20045
20013
  try {
20046
20014
  const user = await this.api.login({
20047
20015
  userName: username,
@@ -20093,7 +20061,7 @@ var WebCall = (() => {
20093
20061
  try {
20094
20062
  await this.api.loginOut({ sessionId });
20095
20063
  } catch (error) {
20096
- this.logger.error(error, {
20064
+ this.logger.warn(error, {
20097
20065
  caller: "CallKit.logout",
20098
20066
  content: {
20099
20067
  errCode: ErrorCode.API_USER_LOGOUT_ERROR
@@ -20103,8 +20071,9 @@ var WebCall = (() => {
20103
20071
  }
20104
20072
  if (isReset) {
20105
20073
  await this.reset();
20074
+ } else {
20075
+ this.config.reset();
20106
20076
  }
20107
- this.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
20108
20077
  }
20109
20078
  async call(extno = "", options = {
20110
20079
  sourceType: CallSourceType.phoneNum,
@@ -20169,9 +20138,6 @@ var WebCall = (() => {
20169
20138
  });
20170
20139
  this.connect.unregister();
20171
20140
  }
20172
- async stop() {
20173
- await this.connect.stop();
20174
- }
20175
20141
  async hangup() {
20176
20142
  if (!this.config.check())
20177
20143
  return;
@@ -20254,11 +20220,19 @@ var WebCall = (() => {
20254
20220
  userStatus: status
20255
20221
  });
20256
20222
  }
20257
- async reset() {
20223
+ /**
20224
+ * reset callkit
20225
+ * @description recover the callkit to the initial state
20226
+ * @default focus is false
20227
+ * @param config.focus is true, the callkit reset socket connection and all states
20228
+ */
20229
+ async reset(config) {
20230
+ const { focus = false } = config || {};
20258
20231
  this.logger.info("reset", {
20259
20232
  caller: "CallKit.reset",
20260
20233
  content: {
20261
- connectStatus: this.connect.connectStatus
20234
+ connectStatus: this.connect.connectStatus,
20235
+ focus
20262
20236
  }
20263
20237
  });
20264
20238
  if (this.connect.isCalling()) {
@@ -20267,9 +20241,10 @@ var WebCall = (() => {
20267
20241
  await this.connect.reset();
20268
20242
  if (this.config.isLogin()) {
20269
20243
  await this.logout({ isReset: false });
20244
+ } else {
20245
+ await this.config.reset();
20270
20246
  }
20271
- await this.config.reset();
20272
- await this.socket.reset();
20247
+ await this.socket.reset({ focus });
20273
20248
  }
20274
20249
  on(event, callback) {
20275
20250
  this.listener.push({