@koi-design/callkit 2.3.0-beta.1 → 2.3.0-beta.10

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
@@ -535,7 +535,11 @@ var SocketReceiveEvent = {
535
535
  ERROR: "ERROR",
536
536
  SESSION_ERROR: "SESSION_ERROR",
537
537
  WAITING_QUEUE: "WAITING_QUEUE",
538
- CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE"
538
+ CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE",
539
+ /**
540
+ * Agent RTP loss
541
+ */
542
+ AGENT_RTP_LOSS: "AGENT_RTP_LOSS"
539
543
  };
540
544
  var EncryptionMethod = {
541
545
  NONE: "NONE",
@@ -724,7 +728,7 @@ var Call = class {
724
728
  // package.json
725
729
  var package_default = {
726
730
  name: "@koi-design/callkit",
727
- version: "2.3.0-beta.1",
731
+ version: "2.3.0-beta.10",
728
732
  description: "callkit",
729
733
  author: "koi",
730
734
  license: "ISC",
@@ -15824,8 +15828,6 @@ var Connect = class {
15824
15828
  });
15825
15829
  return;
15826
15830
  }
15827
- const { userInfo } = this.callKit.config.getConfig();
15828
- const { userPart, fsIp, fsPort } = userInfo;
15829
15831
  const { registererOptions = {} } = this.reconnectConfig;
15830
15832
  this.registerer = new Registerer(this.userAgent, registererOptions);
15831
15833
  this.registerer.stateChange.addListener((state) => {
@@ -15859,27 +15861,26 @@ var Connect = class {
15859
15861
  });
15860
15862
  this.setRegister(true);
15861
15863
  if (this.isReConnected) {
15862
- if (this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling()) {
15863
- const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
15864
+ if (this.canReferInCallToSelf()) {
15864
15865
  this.callKit.logger.info(
15865
15866
  "Reconnected, referring active session to self",
15866
15867
  {
15867
15868
  caller: "Connect.setupRegisterer.registererStateChange",
15868
15869
  type: "SIP",
15869
15870
  content: {
15870
- selfUri,
15871
+ selfUri: this.getSelfReferUri(),
15871
15872
  sessionState: this.currentSession.state,
15872
15873
  connectStatus: this.connectStatus
15873
15874
  }
15874
15875
  }
15875
15876
  );
15876
- this.referInCall(selfUri).catch((err) => {
15877
+ this.referInCallToSelf().catch((err) => {
15877
15878
  this.callKit.logger.error(err, {
15878
15879
  caller: "Connect.setupRegisterer.registererStateChange",
15879
15880
  type: "SIP",
15880
15881
  content: {
15881
15882
  errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
15882
- selfUri
15883
+ selfUri: this.getSelfReferUri()
15883
15884
  }
15884
15885
  });
15885
15886
  });
@@ -16708,6 +16709,59 @@ var Connect = class {
16708
16709
  }
16709
16710
  this.currentSession.refer(target, extra?.sessionReferOptions);
16710
16711
  }
16712
+ /**
16713
+ * Get the SIP URI for "refer to self" (same as reconnection refer logic).
16714
+ * Shared by referInCallToSelf and internal reconnection refer.
16715
+ */
16716
+ getSelfReferUri() {
16717
+ const { userInfo } = this.callKit.config.getConfig();
16718
+ const { userPart, fsIp, fsPort } = userInfo;
16719
+ return `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
16720
+ }
16721
+ /**
16722
+ * Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
16723
+ * Shared by reconnection logic and referInCallToSelf.
16724
+ */
16725
+ canReferInCallToSelf() {
16726
+ return !!this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling();
16727
+ }
16728
+ /**
16729
+ * Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
16730
+ * Socket and other callers can use this without constructing referTo.
16731
+ */
16732
+ async referInCallToSelf(callUuid, extra) {
16733
+ if (callUuid && this.currentCallId !== callUuid) {
16734
+ this.callKit.logger.warn(
16735
+ "Cannot refer in call to self: callUuid mismatch",
16736
+ {
16737
+ caller: "Connect.referInCallToSelf",
16738
+ type: "SIP",
16739
+ content: {
16740
+ currentCallId: this.currentCallId,
16741
+ callUuid
16742
+ }
16743
+ }
16744
+ );
16745
+ return;
16746
+ }
16747
+ if (!this.canReferInCallToSelf()) {
16748
+ this.callKit.logger.warn(
16749
+ "Cannot refer in call to self: preconditions not met",
16750
+ {
16751
+ caller: "Connect.referInCallToSelf",
16752
+ type: "SIP",
16753
+ content: {
16754
+ hasCurrentSession: !!this.currentSession,
16755
+ sessionState: this.currentSession?.state,
16756
+ isCalling: this.isCalling()
16757
+ }
16758
+ }
16759
+ );
16760
+ return;
16761
+ }
16762
+ const selfUri = this.getSelfReferUri();
16763
+ return this.referInCall(selfUri, extra);
16764
+ }
16711
16765
  };
16712
16766
 
16713
16767
  // core/socket.ts
@@ -16933,6 +16987,28 @@ var Socket = class {
16933
16987
  this.setConnectAuthState("startConfirm", true);
16934
16988
  this.cleanReconnectState();
16935
16989
  }
16990
+ if (data.event === SocketReceiveEvent.AGENT_RTP_LOSS) {
16991
+ this.callKit.logger.warn("Agent RTP loss", {
16992
+ caller: "Socket.onMessage",
16993
+ type: "INCALL",
16994
+ content: {
16995
+ data: {
16996
+ callUuid,
16997
+ ...content
16998
+ },
16999
+ event: SocketReceiveEvent.AGENT_RTP_LOSS
17000
+ }
17001
+ });
17002
+ if (callUuid) {
17003
+ this.callKit.connect.referInCallToSelf(callUuid).catch((err) => {
17004
+ this.callKit.logger.error(err, {
17005
+ caller: "Socket.onMessage:AGENT_RTP_LOSS",
17006
+ type: "INCALL",
17007
+ content: { callUuid, event: SocketReceiveEvent.AGENT_RTP_LOSS }
17008
+ });
17009
+ });
17010
+ }
17011
+ }
16936
17012
  if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
16937
17013
  this.callKit.trigger(KitEvent.CALL_RINGING, {
16938
17014
  time: /* @__PURE__ */ new Date(),
@@ -17045,7 +17121,7 @@ var Socket = class {
17045
17121
  return;
17046
17122
  }
17047
17123
  const { userInfo, version } = this.callKit.config.getConfig();
17048
- const { sessionId, extno, agentId, phoneType } = userInfo;
17124
+ const { sessionId, extno, agentId } = userInfo;
17049
17125
  if (!sessionId) {
17050
17126
  this.callKit.logger.error("sessionId is empty", {
17051
17127
  caller: "Socket.send",
@@ -17065,7 +17141,6 @@ var Socket = class {
17065
17141
  if (SocketSendEvent.CALL === event) {
17066
17142
  msg.phoneNum = extno;
17067
17143
  msg.agentId = agentId;
17068
- msg.phoneType = phoneType;
17069
17144
  if (message?.sourceType === CallSourceType.phoneNum) {
17070
17145
  delete msg.workOrderId;
17071
17146
  } else if (message?.sourceType === CallSourceType.workOrderId) {
@@ -17385,7 +17460,10 @@ var CallKit = class {
17385
17460
  caller: "CallKit.register",
17386
17461
  content: {}
17387
17462
  });
17388
- this.connect.register();
17463
+ const { userInfo } = this.config.getConfig();
17464
+ if (userInfo.phoneType === PhoneTypeEnum.SIP) {
17465
+ this.connect.register();
17466
+ }
17389
17467
  }
17390
17468
  async unregister() {
17391
17469
  if (!this.config.check())
@@ -17495,10 +17573,13 @@ var CallKit = class {
17495
17573
  force
17496
17574
  }
17497
17575
  });
17498
- if (this.connect.isCalling()) {
17499
- await this.hangup();
17576
+ const { userInfo } = this.config.getConfig();
17577
+ if (userInfo.phoneType === PhoneTypeEnum.SIP) {
17578
+ if (this.connect.isCalling()) {
17579
+ await this.hangup();
17580
+ }
17581
+ await this.connect.reset({ force });
17500
17582
  }
17501
- await this.connect.reset({ force });
17502
17583
  if (this.config.isLogin()) {
17503
17584
  await this.logout({ isReset: false });
17504
17585
  } else {