@koi-design/callkit 2.1.0-beta.2 → 2.1.0-beta.3

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
@@ -318,7 +318,15 @@ var KitEvent = {
318
318
  INCALL_CONNECT_EVENT: "IncallConnectEvent",
319
319
  SIP_CONNECT_EVENT: "sipConnectEvent",
320
320
  SIP_REGISTERER_EVENT: "sipRegistererEvent",
321
- SIP_SESSION_EVENT: "sipSessionEvent"
321
+ SIP_SESSION_EVENT: "sipSessionEvent",
322
+ /**
323
+ * Refering change
324
+ */
325
+ KIT_REFERING_CHANGE: "referingChange",
326
+ /**
327
+ * In call refering change
328
+ */
329
+ KIT_IN_CALL_REFERING_CHANGE: "inCallReferingChange"
322
330
  };
323
331
  var ErrorCode = {
324
332
  /**
@@ -705,7 +713,7 @@ var Call = class {
705
713
  // package.json
706
714
  var package_default = {
707
715
  name: "@koi-design/callkit",
708
- version: "2.1.0-beta.2",
716
+ version: "2.1.0-beta.3",
709
717
  description: "callkit",
710
718
  author: "koi",
711
719
  license: "ISC",
@@ -1094,7 +1102,11 @@ var Connect = class {
1094
1102
  /**
1095
1103
  *@description Whether it's a referring
1096
1104
  */
1097
- isRefering = false;
1105
+ _isRefering = false;
1106
+ /**
1107
+ *@description Whether it's in call refering dealwith disconnect recovery
1108
+ */
1109
+ _isInCallRefering = false;
1098
1110
  // sipConnected = false;
1099
1111
  /**
1100
1112
  *@description Whether it's an outgoing call
@@ -1119,8 +1131,30 @@ var Connect = class {
1119
1131
  getCurrentCallId() {
1120
1132
  return this.currentCallId;
1121
1133
  }
1134
+ /**
1135
+ *@description Whether the SIP socket is error
1136
+ */
1137
+ _isError = false;
1138
+ get isError() {
1139
+ return this._isError;
1140
+ }
1141
+ /**
1142
+ *@description Set whether it's in call refering dealwith disconnect recovery
1143
+ */
1144
+ setInCallRefering(refering) {
1145
+ if (this._isInCallRefering === refering)
1146
+ return;
1147
+ this.callKit.logger.info("setIsInCallRefering", {
1148
+ caller: "Connect.setIsInCallRefering",
1149
+ content: {
1150
+ refering
1151
+ }
1152
+ });
1153
+ this._isInCallRefering = refering;
1154
+ this.callKit.trigger(KitEvent.KIT_IN_CALL_REFERING_CHANGE);
1155
+ }
1122
1156
  setRefering(refering) {
1123
- if (this.isRefering === refering)
1157
+ if (this._isRefering === refering)
1124
1158
  return;
1125
1159
  this.callKit.logger.info("setRefering", {
1126
1160
  caller: "Connect.setRefering",
@@ -1128,7 +1162,8 @@ var Connect = class {
1128
1162
  refering
1129
1163
  }
1130
1164
  });
1131
- this.isRefering = refering;
1165
+ this._isRefering = refering;
1166
+ this.callKit.trigger(KitEvent.KIT_REFERING_CHANGE);
1132
1167
  }
1133
1168
  setIsReConnected(isReConnected) {
1134
1169
  if (this.isReConnected === isReConnected)
@@ -1162,13 +1197,19 @@ var Connect = class {
1162
1197
  this.currentCallId = callId;
1163
1198
  this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
1164
1199
  }
1165
- async reset() {
1200
+ async reset({ force = false } = { force: false }) {
1166
1201
  this.setOutgoing(false);
1167
1202
  this.isUnprompted = false;
1168
1203
  this.hasInvite = false;
1169
- if (this.isRefering) {
1204
+ if (force) {
1205
+ this._isError = false;
1206
+ }
1207
+ if (this._isRefering) {
1170
1208
  this.setRefering(false);
1171
1209
  }
1210
+ if (this._isInCallRefering) {
1211
+ this.setInCallRefering(false);
1212
+ }
1172
1213
  if (this.isReConnected) {
1173
1214
  this.setIsReConnected(false);
1174
1215
  }
@@ -1264,6 +1305,18 @@ var Connect = class {
1264
1305
  isMuted() {
1265
1306
  return this.isMute;
1266
1307
  }
1308
+ /**
1309
+ * isRefering
1310
+ */
1311
+ isRefering() {
1312
+ return this._isRefering;
1313
+ }
1314
+ /**
1315
+ * isInCallRefering
1316
+ */
1317
+ isInCallRefering() {
1318
+ return this._isInCallRefering;
1319
+ }
1267
1320
  /**
1268
1321
  * Call ended, call not started
1269
1322
  * @returns
@@ -1313,7 +1366,9 @@ var Connect = class {
1313
1366
  }
1314
1367
  });
1315
1368
  this.setRegister(false);
1316
- this.setConnectStatus(CallStatus.init);
1369
+ if (!this.isInCallRefering()) {
1370
+ this.setConnectStatus(CallStatus.init);
1371
+ }
1317
1372
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1318
1373
  registererState: state,
1319
1374
  isRegistered: this.isRegistered()
@@ -1344,7 +1399,7 @@ var Connect = class {
1344
1399
  }
1345
1400
  }
1346
1401
  );
1347
- this.refer(selfUri).catch((err) => {
1402
+ this.referInCall(selfUri).catch((err) => {
1348
1403
  this.callKit.logger.error(err, {
1349
1404
  caller: "Connect.setupRegisterer.registererStateChange",
1350
1405
  type: "SIP",
@@ -1382,14 +1437,18 @@ var Connect = class {
1382
1437
  type: "SIP",
1383
1438
  content: {
1384
1439
  registererState: state,
1385
- isRegistered: this.isRegistered()
1440
+ isRegistered: this.isRegistered(),
1441
+ isInCallRefering: this.isInCallRefering()
1386
1442
  }
1387
1443
  });
1388
1444
  this.setRegister(false);
1389
- this.setConnectStatus(CallStatus.init);
1445
+ if (!this.isInCallRefering()) {
1446
+ this.setConnectStatus(CallStatus.init);
1447
+ }
1390
1448
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1391
1449
  registererState: state,
1392
- isRegistered: this.isRegistered()
1450
+ isRegistered: this.isRegistered(),
1451
+ isInCallRefering: this.isInCallRefering()
1393
1452
  });
1394
1453
  break;
1395
1454
  case import_sip.RegistererState.Unregistered:
@@ -1398,14 +1457,18 @@ var Connect = class {
1398
1457
  type: "SIP",
1399
1458
  content: {
1400
1459
  isRegistered: this.isRegistered(),
1401
- registererState: state
1460
+ registererState: state,
1461
+ isInCallRefering: this.isInCallRefering()
1402
1462
  }
1403
1463
  });
1404
1464
  this.setRegister(false);
1405
- this.setConnectStatus(CallStatus.init);
1465
+ if (!this.isInCallRefering()) {
1466
+ this.setConnectStatus(CallStatus.init);
1467
+ }
1406
1468
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1407
1469
  registererState: state,
1408
- isRegistered: this.isRegistered()
1470
+ isRegistered: this.isRegistered(),
1471
+ isInCallRefering: this.isInCallRefering()
1409
1472
  });
1410
1473
  break;
1411
1474
  default:
@@ -1572,14 +1635,17 @@ var Connect = class {
1572
1635
  caller: "Connect.register.onInvite",
1573
1636
  type: "SIP",
1574
1637
  content: {
1575
- sessionState: state
1638
+ sessionState: state,
1639
+ isInCallRefering: this.isInCallRefering()
1576
1640
  }
1577
1641
  });
1578
- this.setConnectStatus(CallStatus.ringing);
1579
- this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1580
- sessionState: state,
1581
- isRegistered: this.isRegistered()
1582
- });
1642
+ if (!this.isInCallRefering()) {
1643
+ this.setConnectStatus(CallStatus.ringing);
1644
+ this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1645
+ sessionState: state,
1646
+ isRegistered: this.isRegistered()
1647
+ });
1648
+ }
1583
1649
  break;
1584
1650
  case import_sip.SessionState.Established:
1585
1651
  this.callKit.logger.info("connect Established", {
@@ -1589,17 +1655,20 @@ var Connect = class {
1589
1655
  sessionState: state
1590
1656
  }
1591
1657
  });
1592
- this.callKit.connect.setConnectStatus(CallStatus.calling);
1593
- this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1594
- sessionState: state,
1595
- isRegistered: this.isRegistered()
1596
- });
1658
+ if (!this.isInCallRefering()) {
1659
+ this.callKit.connect.setConnectStatus(CallStatus.calling);
1660
+ this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1661
+ sessionState: state,
1662
+ isRegistered: this.isRegistered()
1663
+ });
1664
+ }
1597
1665
  setupRemoteMedia(this.currentSession);
1598
1666
  break;
1599
1667
  case import_sip.SessionState.Terminating:
1600
1668
  this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1601
1669
  sessionState: state,
1602
- isRegistered: this.isRegistered()
1670
+ isRegistered: this.isRegistered(),
1671
+ isInCallRefering: this.isInCallRefering()
1603
1672
  });
1604
1673
  break;
1605
1674
  case import_sip.SessionState.Terminated:
@@ -1607,7 +1676,8 @@ var Connect = class {
1607
1676
  caller: "Connect.register.onInvite",
1608
1677
  type: "SIP",
1609
1678
  content: {
1610
- sessionState: state
1679
+ sessionState: state,
1680
+ isInCallRefering: this.isInCallRefering()
1611
1681
  }
1612
1682
  });
1613
1683
  this.hasInvite = false;
@@ -1617,7 +1687,8 @@ var Connect = class {
1617
1687
  this.isUnprompted = false;
1618
1688
  this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1619
1689
  sessionState: state,
1620
- isRegistered: this.isRegistered()
1690
+ isRegistered: this.isRegistered(),
1691
+ isInCallRefering: this.isInCallRefering()
1621
1692
  });
1622
1693
  break;
1623
1694
  default:
@@ -1667,9 +1738,9 @@ var Connect = class {
1667
1738
  }
1668
1739
  });
1669
1740
  }
1670
- if (this.isRefering) {
1741
+ if (this.isInCallRefering()) {
1671
1742
  this.currentSession.accept(options);
1672
- this.setRefering(false);
1743
+ this.setInCallRefering(false);
1673
1744
  return;
1674
1745
  }
1675
1746
  if (this.isOutgoing) {
@@ -1756,7 +1827,10 @@ var Connect = class {
1756
1827
  reconnectTimer;
1757
1828
  reconnectAttempts = 0;
1758
1829
  startReconnectTimer() {
1830
+ if (this._isError)
1831
+ return;
1759
1832
  if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts && this.callKit.config.isLogin()) {
1833
+ this._isError = true;
1760
1834
  this.callKit.reset();
1761
1835
  this.callKit.logger.error("Reconnect failed max attempts", {
1762
1836
  caller: "Connect.startReconnectTimer",
@@ -1779,10 +1853,10 @@ var Connect = class {
1779
1853
  }
1780
1854
  });
1781
1855
  this.reconnectAttempts += 1;
1856
+ this.setIsReConnected(true);
1782
1857
  this.reconnectTimer = setTimeout(() => {
1783
1858
  if (this.reconnectTimer && this.callKit.config.isLogin()) {
1784
1859
  this.userAgent?.reconnect();
1785
- this.setIsReConnected(true);
1786
1860
  this.callKit.logger.info("Reconnect attempt", {
1787
1861
  caller: "Connect.startReconnectTimer",
1788
1862
  type: "SIP",
@@ -2095,6 +2169,35 @@ var Connect = class {
2095
2169
  }
2096
2170
  this.currentSession.refer(target, extra?.sessionReferOptions);
2097
2171
  }
2172
+ async referInCall(referTo, extra) {
2173
+ if (!this.currentSession) {
2174
+ const errorMsg = "Cannot refer in call: currentSession is not available";
2175
+ this.callKit.logger.warn(errorMsg, {
2176
+ caller: "Connect.referInCall",
2177
+ type: "SIP",
2178
+ content: {
2179
+ errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
2180
+ referTo
2181
+ }
2182
+ });
2183
+ return;
2184
+ }
2185
+ this.setInCallRefering(true);
2186
+ this.callKit.logger.info("connect referInCall", {
2187
+ caller: "Connect.referInCall",
2188
+ type: "SIP",
2189
+ content: {
2190
+ referTo,
2191
+ extra,
2192
+ sessionState: this.currentSession.state
2193
+ }
2194
+ });
2195
+ let target;
2196
+ if (referTo) {
2197
+ target = import_sip.UserAgent.makeURI(referTo);
2198
+ }
2199
+ this.currentSession.refer(target, extra?.sessionReferOptions);
2200
+ }
2098
2201
  };
2099
2202
 
2100
2203
  // core/socket.ts
@@ -2402,14 +2505,10 @@ var Socket = class {
2402
2505
  this.callKit.connect.socketTriggerHangup(callUuid);
2403
2506
  }
2404
2507
  }
2405
- this.callKit.trigger(
2406
- KitEvent.SERVER_SOCKET_EVENT,
2407
- {
2408
- ...data,
2409
- callUuid
2410
- },
2411
- true
2412
- );
2508
+ this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, {
2509
+ ...data,
2510
+ callUuid
2511
+ });
2413
2512
  }
2414
2513
  send(event, message) {
2415
2514
  if (!this.connectAuthState.isConnected) {
@@ -2644,7 +2743,7 @@ var CallKit = class {
2644
2743
  encryptionPassword
2645
2744
  }
2646
2745
  });
2647
- if (this.socket.isError) {
2746
+ if (this.socket.isError || this.connect.isError) {
2648
2747
  this.logger.warn("socket is error", {
2649
2748
  caller: "CallKit.login",
2650
2749
  content: { username, password, extra, socketError: this.socket.isError }
@@ -2882,7 +2981,7 @@ var CallKit = class {
2882
2981
  if (this.connect.isCalling()) {
2883
2982
  await this.hangup();
2884
2983
  }
2885
- await this.connect.reset();
2984
+ await this.connect.reset({ force });
2886
2985
  if (this.config.isLogin()) {
2887
2986
  await this.logout({ isReset: false });
2888
2987
  } else {