@koi-design/callkit 1.0.24-beta.17 → 1.0.24-beta.19

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
@@ -179,6 +179,10 @@ declare const SocketSendEvent: {
179
179
  * AGENT_TRANSFER
180
180
  */
181
181
  AGENT_TRANSFER: string;
182
+ /**
183
+ * AGENT_TRANSFER
184
+ */
185
+ HANG_UP_REASON: string;
182
186
  };
183
187
  declare const EncryptionMethod: {
184
188
  NONE: string;
@@ -451,7 +455,6 @@ declare class CallKit {
451
455
  connect: Connect;
452
456
  socket: Socket;
453
457
  user: User;
454
- reconnect?: SocketConfig;
455
458
  listener: Listener[];
456
459
  constructor(options: ConfigEntity);
457
460
  login(username: string, password: string, extra?: {
@@ -3510,7 +3510,11 @@ var WebCall = (() => {
3510
3510
  /**
3511
3511
  * AGENT_TRANSFER
3512
3512
  */
3513
- AGENT_TRANSFER: "AGENT_TRANSFER"
3513
+ AGENT_TRANSFER: "AGENT_TRANSFER",
3514
+ /**
3515
+ * AGENT_TRANSFER
3516
+ */
3517
+ HANG_UP_REASON: "HANG_UP_REASON"
3514
3518
  };
3515
3519
  var SocketReceiveEvent = {
3516
3520
  /**
@@ -3592,8 +3596,10 @@ var WebCall = (() => {
3592
3596
  var ConnectEvent = {
3593
3597
  SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
3594
3598
  SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
3599
+ SIP_RECONNECT_SUCCESS: "SIP_RECONNECT_SUCCESS",
3595
3600
  INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
3596
3601
  INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR",
3602
+ INCALL_RECONNECT_SUCCESS: "INCALL_RECONNECT_SUCCESS",
3597
3603
  OPTIONS_HEARTBEAT_EXPIRED: "OPTIONS_HEARTBEAT_EXPIRED",
3598
3604
  USER_AGENT_START_ERROR: "USER_AGENT_START_ERROR"
3599
3605
  };
@@ -18472,8 +18478,27 @@ var WebCall = (() => {
18472
18478
  });
18473
18479
  }
18474
18480
  };
18475
- const observeOptionsHeartbeat = (userAgent, extra) => {
18481
+ const observeSocketStatus = (userAgent, extra) => {
18476
18482
  const { that = this } = extra;
18483
+ that.userAgent.transport.onDisconnect = (error) => {
18484
+ if (error) {
18485
+ that.callKit.logger.debug("connect onDisconnect");
18486
+ if (that.isRegistered() && !(that.sipConnected || that.isRinging() || that.isCalling() || that.isHolding())) {
18487
+ that.reconnect();
18488
+ } else {
18489
+ const data = {
18490
+ kitEvent: ConnectEvent.SIP_CONNECT_ERROR,
18491
+ err: error
18492
+ };
18493
+ that.callKit.logger.debug("SIP WebSocket closed with error", data);
18494
+ that.callKit.trigger(KitEvent.CONNECT_EVENT, data);
18495
+ that.callKit.user.sendHangUpReason(data);
18496
+ that.callKit.callCenter.callEnd();
18497
+ }
18498
+ } else {
18499
+ that.callKit.logger.debug("SIP WebSocket closed normally");
18500
+ }
18501
+ };
18477
18502
  that.clearObserveOptionsHeartbeatInterval();
18478
18503
  setInterval(() => {
18479
18504
  if (that.lastOptionsUpdateTime !== 0) {
@@ -18481,7 +18506,7 @@ var WebCall = (() => {
18481
18506
  const diff = now - that.lastOptionsUpdateTime;
18482
18507
  if (diff > 6e4) {
18483
18508
  const data = {
18484
- event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
18509
+ kitEvent: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
18485
18510
  lastOptionsUpdateTime: that.lastOptionsUpdateTime,
18486
18511
  now
18487
18512
  };
@@ -18584,12 +18609,14 @@ var WebCall = (() => {
18584
18609
  if (this.isRegistered() && !(this.sipConnected || this.isRinging() || this.isCalling() || this.isHolding())) {
18585
18610
  this.reconnect();
18586
18611
  } else {
18587
- const data = {
18612
+ this.callKit.trigger(KitEvent.CONNECT_EVENT, {
18588
18613
  event: ConnectEvent.SIP_CONNECT_ERROR,
18589
18614
  err: error
18590
- };
18591
- this.callKit.trigger(KitEvent.CONNECT_EVENT, data);
18592
- this.callKit.user.sendHangUpReason(data);
18615
+ });
18616
+ this.callKit.user.sendHangUpReason({
18617
+ eventType: ConnectEvent.SIP_RECONNECT_ERROR,
18618
+ err: error
18619
+ });
18593
18620
  this.callKit.callCenter.callEnd();
18594
18621
  }
18595
18622
  },
@@ -18611,16 +18638,15 @@ var WebCall = (() => {
18611
18638
  // });
18612
18639
  // }
18613
18640
  };
18614
- observeOptionsHeartbeat(this.userAgent, {
18641
+ observeSocketStatus(this.userAgent, {
18615
18642
  that: this
18616
18643
  });
18617
18644
  await this.userAgent.start().catch((err) => {
18618
18645
  this.callKit.callCenter.callEnd(false, true);
18619
- const data = {
18620
- event: ConnectEvent.USER_AGENT_START_ERROR,
18646
+ this.callKit.user.sendHangUpReason({
18647
+ eventType: ConnectEvent.USER_AGENT_START_ERROR,
18621
18648
  err
18622
- };
18623
- this.callKit.user.sendHangUpReason(data);
18649
+ });
18624
18650
  this.callKit.logger.error(err, {
18625
18651
  errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
18626
18652
  });
@@ -18639,25 +18665,31 @@ var WebCall = (() => {
18639
18665
  reconnectTimer = setTimeout(async () => {
18640
18666
  try {
18641
18667
  currentRetry += 1;
18642
- console.log(
18668
+ this.callKit.logger.debug(
18643
18669
  `Attempting to reconnect SIP... (Attempt ${currentRetry}/${this.reconnectConfig.maxAttempts})`
18644
18670
  );
18645
18671
  await this.unregister();
18646
18672
  await this.stop();
18647
18673
  await this.register();
18648
- console.log("Reconnection successful");
18674
+ this.callKit.logger.debug("Reconnection successful");
18675
+ this.callKit.trigger(KitEvent.CONNECT_EVENT, {
18676
+ event: ConnectEvent.SIP_RECONNECT_SUCCESS
18677
+ });
18649
18678
  reconnectTimer = null;
18650
18679
  } catch (err) {
18651
- console.error("Reconnection failed:", err);
18680
+ this.callKit.logger.debug("Reconnection failed:", err);
18652
18681
  reconnectTimer = null;
18653
18682
  if (currentRetry < this.reconnectConfig.maxAttempts) {
18654
18683
  await scheduleReconnect();
18655
18684
  } else {
18656
- const data = {
18657
- event: ConnectEvent.SIP_RECONNECT_ERROR
18658
- };
18659
- this.callKit.trigger(KitEvent.CONNECT_EVENT, data);
18660
- this.callKit.user.sendHangUpReason(data);
18685
+ this.callKit.trigger(KitEvent.CONNECT_EVENT, {
18686
+ event: ConnectEvent.SIP_RECONNECT_ERROR,
18687
+ error: err
18688
+ });
18689
+ this.callKit.user.sendHangUpReason({
18690
+ eventType: ConnectEvent.SIP_RECONNECT_ERROR,
18691
+ error: err
18692
+ });
18661
18693
  this.callKit.logger.error("No registerer to unregister.");
18662
18694
  }
18663
18695
  }
@@ -19177,10 +19209,17 @@ var WebCall = (() => {
19177
19209
  `Preparing reconnection attempt ${this.reconnectAttempts + 1}, delay: ${delay}ms`
19178
19210
  );
19179
19211
  this.reconnectTimer = setTimeout(() => {
19180
- const { socket } = this.callKit.config.getConfig();
19181
- this.connect(socket);
19182
- this.reconnectAttempts += 1;
19183
- this.isReconnecting = false;
19212
+ try {
19213
+ const { socket } = this.callKit.config.getConfig();
19214
+ this.connect(socket);
19215
+ this.callKit.trigger(KitEvent.CONNECT_EVENT, {
19216
+ event: ConnectEvent.INCALL_RECONNECT_SUCCESS
19217
+ });
19218
+ this.reconnectAttempts += 1;
19219
+ this.isReconnecting = false;
19220
+ } catch (err) {
19221
+ this.callKit.logger.error(err);
19222
+ }
19184
19223
  }, delay);
19185
19224
  }
19186
19225
  };
@@ -19229,7 +19268,7 @@ var WebCall = (() => {
19229
19268
  async sendHangUpReason(data) {
19230
19269
  try {
19231
19270
  const sendData = data || {};
19232
- this.callKit.socket.send(SocketSendEvent.CALL, sendData);
19271
+ this.callKit.socket.send(SocketSendEvent.HANG_UP_REASON, sendData);
19233
19272
  } catch (error) {
19234
19273
  this.callKit.logger.debug(error);
19235
19274
  }
@@ -19245,7 +19284,6 @@ var WebCall = (() => {
19245
19284
  connect;
19246
19285
  socket;
19247
19286
  user;
19248
- reconnect;
19249
19287
  listener = [];
19250
19288
  constructor(options) {
19251
19289
  this.config = new Config(this);