@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.d.ts CHANGED
@@ -5289,6 +5289,21 @@ declare class Connect {
5289
5289
  setMute(mute: boolean): Promise<void>;
5290
5290
  refer(referTo: string, extra?: any): Promise<void>;
5291
5291
  private referInCall;
5292
+ /**
5293
+ * Get the SIP URI for "refer to self" (same as reconnection refer logic).
5294
+ * Shared by referInCallToSelf and internal reconnection refer.
5295
+ */
5296
+ private getSelfReferUri;
5297
+ /**
5298
+ * Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
5299
+ * Shared by reconnection logic and referInCallToSelf.
5300
+ */
5301
+ private canReferInCallToSelf;
5302
+ /**
5303
+ * Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
5304
+ * Socket and other callers can use this without constructing referTo.
5305
+ */
5306
+ referInCallToSelf(callUuid?: string, extra?: any): Promise<void>;
5292
5307
  }
5293
5308
 
5294
5309
  interface CallKitConfig {
@@ -3700,7 +3700,11 @@ var WebCall = (() => {
3700
3700
  ERROR: "ERROR",
3701
3701
  SESSION_ERROR: "SESSION_ERROR",
3702
3702
  WAITING_QUEUE: "WAITING_QUEUE",
3703
- CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE"
3703
+ CUSTOMER_MATCH_BLACK_PHONE: "CUSTOMER_MATCH_BLACK_PHONE",
3704
+ /**
3705
+ * Agent RTP loss
3706
+ */
3707
+ AGENT_RTP_LOSS: "AGENT_RTP_LOSS"
3704
3708
  };
3705
3709
  var EncryptionMethod = {
3706
3710
  NONE: "NONE",
@@ -3889,7 +3893,7 @@ var WebCall = (() => {
3889
3893
  // package.json
3890
3894
  var package_default = {
3891
3895
  name: "@koi-design/callkit",
3892
- version: "2.3.0-beta.1",
3896
+ version: "2.3.0-beta.10",
3893
3897
  description: "callkit",
3894
3898
  author: "koi",
3895
3899
  license: "ISC",
@@ -18989,8 +18993,6 @@ ${log}` : log;
18989
18993
  });
18990
18994
  return;
18991
18995
  }
18992
- const { userInfo } = this.callKit.config.getConfig();
18993
- const { userPart, fsIp, fsPort } = userInfo;
18994
18996
  const { registererOptions = {} } = this.reconnectConfig;
18995
18997
  this.registerer = new Registerer(this.userAgent, registererOptions);
18996
18998
  this.registerer.stateChange.addListener((state) => {
@@ -19024,27 +19026,26 @@ ${log}` : log;
19024
19026
  });
19025
19027
  this.setRegister(true);
19026
19028
  if (this.isReConnected) {
19027
- if (this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling()) {
19028
- const selfUri = `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
19029
+ if (this.canReferInCallToSelf()) {
19029
19030
  this.callKit.logger.info(
19030
19031
  "Reconnected, referring active session to self",
19031
19032
  {
19032
19033
  caller: "Connect.setupRegisterer.registererStateChange",
19033
19034
  type: "SIP",
19034
19035
  content: {
19035
- selfUri,
19036
+ selfUri: this.getSelfReferUri(),
19036
19037
  sessionState: this.currentSession.state,
19037
19038
  connectStatus: this.connectStatus
19038
19039
  }
19039
19040
  }
19040
19041
  );
19041
- this.referInCall(selfUri).catch((err) => {
19042
+ this.referInCallToSelf().catch((err) => {
19042
19043
  this.callKit.logger.error(err, {
19043
19044
  caller: "Connect.setupRegisterer.registererStateChange",
19044
19045
  type: "SIP",
19045
19046
  content: {
19046
19047
  errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
19047
- selfUri
19048
+ selfUri: this.getSelfReferUri()
19048
19049
  }
19049
19050
  });
19050
19051
  });
@@ -19873,6 +19874,59 @@ ${log}` : log;
19873
19874
  }
19874
19875
  this.currentSession.refer(target, extra?.sessionReferOptions);
19875
19876
  }
19877
+ /**
19878
+ * Get the SIP URI for "refer to self" (same as reconnection refer logic).
19879
+ * Shared by referInCallToSelf and internal reconnection refer.
19880
+ */
19881
+ getSelfReferUri() {
19882
+ const { userInfo } = this.callKit.config.getConfig();
19883
+ const { userPart, fsIp, fsPort } = userInfo;
19884
+ return `sip:manualCallAgent${userPart}@${fsIp}:${fsPort}`;
19885
+ }
19886
+ /**
19887
+ * Whether we can refer the current call to self (has active session in Established/Establishing and is calling).
19888
+ * Shared by reconnection logic and referInCallToSelf.
19889
+ */
19890
+ canReferInCallToSelf() {
19891
+ return !!this.currentSession && (this.currentSession.state === SessionState2.Established || this.currentSession.state === SessionState2.Establishing) && this.isCalling();
19892
+ }
19893
+ /**
19894
+ * Refer the current call to self (e.g. Agent RTP loss recovery, post-reconnect recovery).
19895
+ * Socket and other callers can use this without constructing referTo.
19896
+ */
19897
+ async referInCallToSelf(callUuid, extra) {
19898
+ if (callUuid && this.currentCallId !== callUuid) {
19899
+ this.callKit.logger.warn(
19900
+ "Cannot refer in call to self: callUuid mismatch",
19901
+ {
19902
+ caller: "Connect.referInCallToSelf",
19903
+ type: "SIP",
19904
+ content: {
19905
+ currentCallId: this.currentCallId,
19906
+ callUuid
19907
+ }
19908
+ }
19909
+ );
19910
+ return;
19911
+ }
19912
+ if (!this.canReferInCallToSelf()) {
19913
+ this.callKit.logger.warn(
19914
+ "Cannot refer in call to self: preconditions not met",
19915
+ {
19916
+ caller: "Connect.referInCallToSelf",
19917
+ type: "SIP",
19918
+ content: {
19919
+ hasCurrentSession: !!this.currentSession,
19920
+ sessionState: this.currentSession?.state,
19921
+ isCalling: this.isCalling()
19922
+ }
19923
+ }
19924
+ );
19925
+ return;
19926
+ }
19927
+ const selfUri = this.getSelfReferUri();
19928
+ return this.referInCall(selfUri, extra);
19929
+ }
19876
19930
  };
19877
19931
 
19878
19932
  // core/socket.ts
@@ -20098,6 +20152,28 @@ ${log}` : log;
20098
20152
  this.setConnectAuthState("startConfirm", true);
20099
20153
  this.cleanReconnectState();
20100
20154
  }
20155
+ if (data.event === SocketReceiveEvent.AGENT_RTP_LOSS) {
20156
+ this.callKit.logger.warn("Agent RTP loss", {
20157
+ caller: "Socket.onMessage",
20158
+ type: "INCALL",
20159
+ content: {
20160
+ data: {
20161
+ callUuid,
20162
+ ...content
20163
+ },
20164
+ event: SocketReceiveEvent.AGENT_RTP_LOSS
20165
+ }
20166
+ });
20167
+ if (callUuid) {
20168
+ this.callKit.connect.referInCallToSelf(callUuid).catch((err) => {
20169
+ this.callKit.logger.error(err, {
20170
+ caller: "Socket.onMessage:AGENT_RTP_LOSS",
20171
+ type: "INCALL",
20172
+ content: { callUuid, event: SocketReceiveEvent.AGENT_RTP_LOSS }
20173
+ });
20174
+ });
20175
+ }
20176
+ }
20101
20177
  if (data.event === SocketReceiveEvent.CUSTOMER_RINGING) {
20102
20178
  this.callKit.trigger(KitEvent.CALL_RINGING, {
20103
20179
  time: /* @__PURE__ */ new Date(),
@@ -20210,7 +20286,7 @@ ${log}` : log;
20210
20286
  return;
20211
20287
  }
20212
20288
  const { userInfo, version } = this.callKit.config.getConfig();
20213
- const { sessionId, extno, agentId, phoneType } = userInfo;
20289
+ const { sessionId, extno, agentId } = userInfo;
20214
20290
  if (!sessionId) {
20215
20291
  this.callKit.logger.error("sessionId is empty", {
20216
20292
  caller: "Socket.send",
@@ -20230,7 +20306,6 @@ ${log}` : log;
20230
20306
  if (SocketSendEvent.CALL === event) {
20231
20307
  msg.phoneNum = extno;
20232
20308
  msg.agentId = agentId;
20233
- msg.phoneType = phoneType;
20234
20309
  if (message?.sourceType === CallSourceType.phoneNum) {
20235
20310
  delete msg.workOrderId;
20236
20311
  } else if (message?.sourceType === CallSourceType.workOrderId) {
@@ -20550,7 +20625,10 @@ ${log}` : log;
20550
20625
  caller: "CallKit.register",
20551
20626
  content: {}
20552
20627
  });
20553
- this.connect.register();
20628
+ const { userInfo } = this.config.getConfig();
20629
+ if (userInfo.phoneType === PhoneTypeEnum.SIP) {
20630
+ this.connect.register();
20631
+ }
20554
20632
  }
20555
20633
  async unregister() {
20556
20634
  if (!this.config.check())
@@ -20660,10 +20738,13 @@ ${log}` : log;
20660
20738
  force
20661
20739
  }
20662
20740
  });
20663
- if (this.connect.isCalling()) {
20664
- await this.hangup();
20741
+ const { userInfo } = this.config.getConfig();
20742
+ if (userInfo.phoneType === PhoneTypeEnum.SIP) {
20743
+ if (this.connect.isCalling()) {
20744
+ await this.hangup();
20745
+ }
20746
+ await this.connect.reset({ force });
20665
20747
  }
20666
- await this.connect.reset({ force });
20667
20748
  if (this.config.isLogin()) {
20668
20749
  await this.logout({ isReset: false });
20669
20750
  } else {