@koi-design/callkit 2.0.0-beta.4 → 2.0.0-beta.5

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
@@ -142,7 +142,8 @@ declare const KitEvent: {
142
142
  * User status change
143
143
  */
144
144
  USER_STATUS_CHANGE: string;
145
- CONNECT_EVENT: string;
145
+ INCALL_CONNECT_EVENT: string;
146
+ SIP_CONNECT_EVENT: string;
146
147
  SIP_REGISTERER_EVENT: string;
147
148
  SIP_SESSION_EVENT: string;
148
149
  };
@@ -255,6 +256,7 @@ declare class Socket {
255
256
  private reconnectTimer?;
256
257
  private isReconnecting;
257
258
  private reconnectAttempts;
259
+ private socketError;
258
260
  constructor(callKit: CallKit);
259
261
  init(): void;
260
262
  private handleDisconnect;
@@ -270,8 +272,7 @@ declare class Socket {
270
272
  private ping;
271
273
  private checkPing;
272
274
  /**
273
- * 重置 socket 连接和所有状态
274
- * @param isWaitConfirm Whether need to wait for close confirmation
275
+ * reset socket connection and all states
275
276
  */
276
277
  reset(): Promise<void>;
277
278
  private attemptReconnect;
@@ -3408,7 +3408,8 @@ var WebCall = (() => {
3408
3408
  * User status change
3409
3409
  */
3410
3410
  USER_STATUS_CHANGE: "userStatusChange",
3411
- CONNECT_EVENT: "CONNECT_EVENT",
3411
+ INCALL_CONNECT_EVENT: "IncallConnectEvent",
3412
+ SIP_CONNECT_EVENT: "sipConnectEvent",
3412
3413
  SIP_REGISTERER_EVENT: "sipRegistererEvent",
3413
3414
  SIP_SESSION_EVENT: "sipSessionEvent"
3414
3415
  };
@@ -3733,7 +3734,7 @@ var WebCall = (() => {
3733
3734
  });
3734
3735
  return;
3735
3736
  }
3736
- this.callKit.connect.setHold(true);
3737
+ this.callKit.connect.setHold(false);
3737
3738
  }
3738
3739
  async callMute() {
3739
3740
  if (!this.callKit.config.check())
@@ -18490,7 +18491,7 @@ var WebCall = (() => {
18490
18491
  if (this.connectStatus !== CallStatus.init) {
18491
18492
  this.setConnectStatus(CallStatus.init);
18492
18493
  }
18493
- if (this.isRegistered) {
18494
+ if (this.isRegistered()) {
18494
18495
  this.unregister();
18495
18496
  }
18496
18497
  this.currentSession = void 0;
@@ -18594,7 +18595,7 @@ var WebCall = (() => {
18594
18595
  this.heartbeatFlag -= 1;
18595
18596
  if (this.heartbeatFlag <= 0) {
18596
18597
  this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
18597
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
18598
+ this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
18598
18599
  event: "OPTIONS_HEARTBEAT_EXPIRED"
18599
18600
  });
18600
18601
  }
@@ -18758,6 +18759,10 @@ var WebCall = (() => {
18758
18759
  }
18759
18760
  });
18760
18761
  this.setRegister(true);
18762
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
18763
+ registererState: state,
18764
+ isRegistered: this.isRegistered()
18765
+ });
18761
18766
  break;
18762
18767
  case RegistererState.Terminated:
18763
18768
  this.callKit.logger.info("registerer stateChange Terminated", {
@@ -18770,6 +18775,10 @@ var WebCall = (() => {
18770
18775
  });
18771
18776
  this.setRegister(false);
18772
18777
  this.setConnectStatus(CallStatus.init);
18778
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
18779
+ registererState: state,
18780
+ isRegistered: this.isRegistered()
18781
+ });
18773
18782
  break;
18774
18783
  case RegistererState.Unregistered:
18775
18784
  this.callKit.logger.info("registerer stateChange Unregistered", {
@@ -18782,6 +18791,10 @@ var WebCall = (() => {
18782
18791
  });
18783
18792
  this.setRegister(false);
18784
18793
  this.setConnectStatus(CallStatus.init);
18794
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
18795
+ registererState: state,
18796
+ isRegistered: this.isRegistered()
18797
+ });
18785
18798
  break;
18786
18799
  default:
18787
18800
  break;
@@ -18871,7 +18884,6 @@ var WebCall = (() => {
18871
18884
  };
18872
18885
  if (this.isOutgoing) {
18873
18886
  this.currentSession.accept(options);
18874
- this.setConnectStatus(CallStatus.connecting);
18875
18887
  this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
18876
18888
  getInviteData: () => {
18877
18889
  const { request: request2 } = this.currentSession;
@@ -19352,7 +19364,7 @@ var WebCall = (() => {
19352
19364
  // package/socket.ts
19353
19365
  var RECONNECT_CONFIG = {
19354
19366
  enabled: true,
19355
- maxAttempts: 1,
19367
+ maxAttempts: 3,
19356
19368
  delay: 500,
19357
19369
  backoffMultiplier: 1.5,
19358
19370
  pingInterval: 3e4,
@@ -19370,6 +19382,7 @@ var WebCall = (() => {
19370
19382
  reconnectTimer;
19371
19383
  isReconnecting = false;
19372
19384
  reconnectAttempts = 0;
19385
+ socketError = false;
19373
19386
  constructor(callKit) {
19374
19387
  this.callKit = callKit;
19375
19388
  const { reconnect } = this.callKit.config.getConfig();
@@ -19393,7 +19406,7 @@ var WebCall = (() => {
19393
19406
  this.isConnected = false;
19394
19407
  if (!this.callKit.config.isLogin() || !this.socketConfig.enabled) {
19395
19408
  this.reset();
19396
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19409
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19397
19410
  event: "INCALL_NOT_CONNECTED"
19398
19411
  });
19399
19412
  return;
@@ -19413,6 +19426,7 @@ var WebCall = (() => {
19413
19426
  type: "INCALL",
19414
19427
  content: { ev }
19415
19428
  });
19429
+ this.socketError = false;
19416
19430
  this.isConnected = true;
19417
19431
  this.lastPingTime = Date.now();
19418
19432
  this.checkPing();
@@ -19425,7 +19439,7 @@ var WebCall = (() => {
19425
19439
  reconnectAttempts: this.reconnectAttempts
19426
19440
  }
19427
19441
  });
19428
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19442
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19429
19443
  event: "INCALL_RECONNECT_SUCCESS"
19430
19444
  });
19431
19445
  }
@@ -19445,10 +19459,13 @@ var WebCall = (() => {
19445
19459
  type: "INCALL",
19446
19460
  content: { ev }
19447
19461
  });
19448
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19462
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19449
19463
  event: "INCALL_CONNECT_ERROR",
19450
19464
  err: ev
19451
19465
  });
19466
+ if (this.socketError) {
19467
+ return;
19468
+ }
19452
19469
  this.handleDisconnect();
19453
19470
  }
19454
19471
  onError(ev) {
@@ -19460,6 +19477,7 @@ var WebCall = (() => {
19460
19477
  data: ev
19461
19478
  }
19462
19479
  });
19480
+ this.socketError = true;
19463
19481
  }
19464
19482
  confirmAck(data) {
19465
19483
  const { ack, messageId } = data;
@@ -19617,7 +19635,7 @@ var WebCall = (() => {
19617
19635
  }
19618
19636
  send(event, message) {
19619
19637
  if (!this.isConnected) {
19620
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19638
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19621
19639
  event: "INCALL_NOT_CONNECTED"
19622
19640
  });
19623
19641
  this.callKit.logger.error("socket not connected", {
@@ -19676,7 +19694,7 @@ var WebCall = (() => {
19676
19694
  }
19677
19695
  async sendMessage(event, message) {
19678
19696
  if (!this.isConnected) {
19679
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19697
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19680
19698
  event: "INCALL_NOT_CONNECTED"
19681
19699
  });
19682
19700
  this.callKit.logger.error("socket not connected", {
@@ -19730,8 +19748,7 @@ var WebCall = (() => {
19730
19748
  }, this.socketConfig.pingInterval);
19731
19749
  }
19732
19750
  /**
19733
- * 重置 socket 连接和所有状态
19734
- * @param isWaitConfirm Whether need to wait for close confirmation
19751
+ * reset socket connection and all states
19735
19752
  */
19736
19753
  async reset() {
19737
19754
  if (this.pingTimer) {
@@ -19741,6 +19758,7 @@ var WebCall = (() => {
19741
19758
  this.resetReconnectState();
19742
19759
  this.lastPingTime = void 0;
19743
19760
  this.satrtConfirm = false;
19761
+ this.socketError = false;
19744
19762
  if (this.ws && this.isConnected) {
19745
19763
  this.callKit.logger.info("Closing socket connection", {
19746
19764
  caller: "Socket.reset",
@@ -19761,14 +19779,14 @@ var WebCall = (() => {
19761
19779
  reconnectAttempts: this.reconnectAttempts
19762
19780
  }
19763
19781
  });
19764
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19782
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19765
19783
  event: "INCALL_RECONNECT_ERROR"
19766
19784
  });
19767
19785
  this.reset();
19768
19786
  return;
19769
19787
  }
19770
19788
  if (this.reconnectAttempts === 0) {
19771
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19789
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
19772
19790
  event: "INCALL_RECONNECT_START"
19773
19791
  });
19774
19792
  }