@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.mjs CHANGED
@@ -285,7 +285,15 @@ var KitEvent = {
285
285
  INCALL_CONNECT_EVENT: "IncallConnectEvent",
286
286
  SIP_CONNECT_EVENT: "sipConnectEvent",
287
287
  SIP_REGISTERER_EVENT: "sipRegistererEvent",
288
- SIP_SESSION_EVENT: "sipSessionEvent"
288
+ SIP_SESSION_EVENT: "sipSessionEvent",
289
+ /**
290
+ * Refering change
291
+ */
292
+ KIT_REFERING_CHANGE: "referingChange",
293
+ /**
294
+ * In call refering change
295
+ */
296
+ KIT_IN_CALL_REFERING_CHANGE: "inCallReferingChange"
289
297
  };
290
298
  var ErrorCode = {
291
299
  /**
@@ -672,7 +680,7 @@ var Call = class {
672
680
  // package.json
673
681
  var package_default = {
674
682
  name: "@koi-design/callkit",
675
- version: "2.1.0-beta.2",
683
+ version: "2.1.0-beta.3",
676
684
  description: "callkit",
677
685
  author: "koi",
678
686
  license: "ISC",
@@ -1067,7 +1075,11 @@ var Connect = class {
1067
1075
  /**
1068
1076
  *@description Whether it's a referring
1069
1077
  */
1070
- isRefering = false;
1078
+ _isRefering = false;
1079
+ /**
1080
+ *@description Whether it's in call refering dealwith disconnect recovery
1081
+ */
1082
+ _isInCallRefering = false;
1071
1083
  // sipConnected = false;
1072
1084
  /**
1073
1085
  *@description Whether it's an outgoing call
@@ -1092,8 +1104,30 @@ var Connect = class {
1092
1104
  getCurrentCallId() {
1093
1105
  return this.currentCallId;
1094
1106
  }
1107
+ /**
1108
+ *@description Whether the SIP socket is error
1109
+ */
1110
+ _isError = false;
1111
+ get isError() {
1112
+ return this._isError;
1113
+ }
1114
+ /**
1115
+ *@description Set whether it's in call refering dealwith disconnect recovery
1116
+ */
1117
+ setInCallRefering(refering) {
1118
+ if (this._isInCallRefering === refering)
1119
+ return;
1120
+ this.callKit.logger.info("setIsInCallRefering", {
1121
+ caller: "Connect.setIsInCallRefering",
1122
+ content: {
1123
+ refering
1124
+ }
1125
+ });
1126
+ this._isInCallRefering = refering;
1127
+ this.callKit.trigger(KitEvent.KIT_IN_CALL_REFERING_CHANGE);
1128
+ }
1095
1129
  setRefering(refering) {
1096
- if (this.isRefering === refering)
1130
+ if (this._isRefering === refering)
1097
1131
  return;
1098
1132
  this.callKit.logger.info("setRefering", {
1099
1133
  caller: "Connect.setRefering",
@@ -1101,7 +1135,8 @@ var Connect = class {
1101
1135
  refering
1102
1136
  }
1103
1137
  });
1104
- this.isRefering = refering;
1138
+ this._isRefering = refering;
1139
+ this.callKit.trigger(KitEvent.KIT_REFERING_CHANGE);
1105
1140
  }
1106
1141
  setIsReConnected(isReConnected) {
1107
1142
  if (this.isReConnected === isReConnected)
@@ -1135,13 +1170,19 @@ var Connect = class {
1135
1170
  this.currentCallId = callId;
1136
1171
  this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
1137
1172
  }
1138
- async reset() {
1173
+ async reset({ force = false } = { force: false }) {
1139
1174
  this.setOutgoing(false);
1140
1175
  this.isUnprompted = false;
1141
1176
  this.hasInvite = false;
1142
- if (this.isRefering) {
1177
+ if (force) {
1178
+ this._isError = false;
1179
+ }
1180
+ if (this._isRefering) {
1143
1181
  this.setRefering(false);
1144
1182
  }
1183
+ if (this._isInCallRefering) {
1184
+ this.setInCallRefering(false);
1185
+ }
1145
1186
  if (this.isReConnected) {
1146
1187
  this.setIsReConnected(false);
1147
1188
  }
@@ -1237,6 +1278,18 @@ var Connect = class {
1237
1278
  isMuted() {
1238
1279
  return this.isMute;
1239
1280
  }
1281
+ /**
1282
+ * isRefering
1283
+ */
1284
+ isRefering() {
1285
+ return this._isRefering;
1286
+ }
1287
+ /**
1288
+ * isInCallRefering
1289
+ */
1290
+ isInCallRefering() {
1291
+ return this._isInCallRefering;
1292
+ }
1240
1293
  /**
1241
1294
  * Call ended, call not started
1242
1295
  * @returns
@@ -1286,7 +1339,9 @@ var Connect = class {
1286
1339
  }
1287
1340
  });
1288
1341
  this.setRegister(false);
1289
- this.setConnectStatus(CallStatus.init);
1342
+ if (!this.isInCallRefering()) {
1343
+ this.setConnectStatus(CallStatus.init);
1344
+ }
1290
1345
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1291
1346
  registererState: state,
1292
1347
  isRegistered: this.isRegistered()
@@ -1317,7 +1372,7 @@ var Connect = class {
1317
1372
  }
1318
1373
  }
1319
1374
  );
1320
- this.refer(selfUri).catch((err) => {
1375
+ this.referInCall(selfUri).catch((err) => {
1321
1376
  this.callKit.logger.error(err, {
1322
1377
  caller: "Connect.setupRegisterer.registererStateChange",
1323
1378
  type: "SIP",
@@ -1355,14 +1410,18 @@ var Connect = class {
1355
1410
  type: "SIP",
1356
1411
  content: {
1357
1412
  registererState: state,
1358
- isRegistered: this.isRegistered()
1413
+ isRegistered: this.isRegistered(),
1414
+ isInCallRefering: this.isInCallRefering()
1359
1415
  }
1360
1416
  });
1361
1417
  this.setRegister(false);
1362
- this.setConnectStatus(CallStatus.init);
1418
+ if (!this.isInCallRefering()) {
1419
+ this.setConnectStatus(CallStatus.init);
1420
+ }
1363
1421
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1364
1422
  registererState: state,
1365
- isRegistered: this.isRegistered()
1423
+ isRegistered: this.isRegistered(),
1424
+ isInCallRefering: this.isInCallRefering()
1366
1425
  });
1367
1426
  break;
1368
1427
  case RegistererState.Unregistered:
@@ -1371,14 +1430,18 @@ var Connect = class {
1371
1430
  type: "SIP",
1372
1431
  content: {
1373
1432
  isRegistered: this.isRegistered(),
1374
- registererState: state
1433
+ registererState: state,
1434
+ isInCallRefering: this.isInCallRefering()
1375
1435
  }
1376
1436
  });
1377
1437
  this.setRegister(false);
1378
- this.setConnectStatus(CallStatus.init);
1438
+ if (!this.isInCallRefering()) {
1439
+ this.setConnectStatus(CallStatus.init);
1440
+ }
1379
1441
  this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1380
1442
  registererState: state,
1381
- isRegistered: this.isRegistered()
1443
+ isRegistered: this.isRegistered(),
1444
+ isInCallRefering: this.isInCallRefering()
1382
1445
  });
1383
1446
  break;
1384
1447
  default:
@@ -1545,14 +1608,17 @@ var Connect = class {
1545
1608
  caller: "Connect.register.onInvite",
1546
1609
  type: "SIP",
1547
1610
  content: {
1548
- sessionState: state
1611
+ sessionState: state,
1612
+ isInCallRefering: this.isInCallRefering()
1549
1613
  }
1550
1614
  });
1551
- this.setConnectStatus(CallStatus.ringing);
1552
- this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1553
- sessionState: state,
1554
- isRegistered: this.isRegistered()
1555
- });
1615
+ if (!this.isInCallRefering()) {
1616
+ this.setConnectStatus(CallStatus.ringing);
1617
+ this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1618
+ sessionState: state,
1619
+ isRegistered: this.isRegistered()
1620
+ });
1621
+ }
1556
1622
  break;
1557
1623
  case SessionState.Established:
1558
1624
  this.callKit.logger.info("connect Established", {
@@ -1562,17 +1628,20 @@ var Connect = class {
1562
1628
  sessionState: state
1563
1629
  }
1564
1630
  });
1565
- this.callKit.connect.setConnectStatus(CallStatus.calling);
1566
- this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1567
- sessionState: state,
1568
- isRegistered: this.isRegistered()
1569
- });
1631
+ if (!this.isInCallRefering()) {
1632
+ this.callKit.connect.setConnectStatus(CallStatus.calling);
1633
+ this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1634
+ sessionState: state,
1635
+ isRegistered: this.isRegistered()
1636
+ });
1637
+ }
1570
1638
  setupRemoteMedia(this.currentSession);
1571
1639
  break;
1572
1640
  case SessionState.Terminating:
1573
1641
  this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1574
1642
  sessionState: state,
1575
- isRegistered: this.isRegistered()
1643
+ isRegistered: this.isRegistered(),
1644
+ isInCallRefering: this.isInCallRefering()
1576
1645
  });
1577
1646
  break;
1578
1647
  case SessionState.Terminated:
@@ -1580,7 +1649,8 @@ var Connect = class {
1580
1649
  caller: "Connect.register.onInvite",
1581
1650
  type: "SIP",
1582
1651
  content: {
1583
- sessionState: state
1652
+ sessionState: state,
1653
+ isInCallRefering: this.isInCallRefering()
1584
1654
  }
1585
1655
  });
1586
1656
  this.hasInvite = false;
@@ -1590,7 +1660,8 @@ var Connect = class {
1590
1660
  this.isUnprompted = false;
1591
1661
  this.callKit.trigger(KitEvent.SIP_SESSION_EVENT, {
1592
1662
  sessionState: state,
1593
- isRegistered: this.isRegistered()
1663
+ isRegistered: this.isRegistered(),
1664
+ isInCallRefering: this.isInCallRefering()
1594
1665
  });
1595
1666
  break;
1596
1667
  default:
@@ -1640,9 +1711,9 @@ var Connect = class {
1640
1711
  }
1641
1712
  });
1642
1713
  }
1643
- if (this.isRefering) {
1714
+ if (this.isInCallRefering()) {
1644
1715
  this.currentSession.accept(options);
1645
- this.setRefering(false);
1716
+ this.setInCallRefering(false);
1646
1717
  return;
1647
1718
  }
1648
1719
  if (this.isOutgoing) {
@@ -1729,7 +1800,10 @@ var Connect = class {
1729
1800
  reconnectTimer;
1730
1801
  reconnectAttempts = 0;
1731
1802
  startReconnectTimer() {
1803
+ if (this._isError)
1804
+ return;
1732
1805
  if (this.reconnectAttempts >= this.reconnectConfig.maxAttempts && this.callKit.config.isLogin()) {
1806
+ this._isError = true;
1733
1807
  this.callKit.reset();
1734
1808
  this.callKit.logger.error("Reconnect failed max attempts", {
1735
1809
  caller: "Connect.startReconnectTimer",
@@ -1752,10 +1826,10 @@ var Connect = class {
1752
1826
  }
1753
1827
  });
1754
1828
  this.reconnectAttempts += 1;
1829
+ this.setIsReConnected(true);
1755
1830
  this.reconnectTimer = setTimeout(() => {
1756
1831
  if (this.reconnectTimer && this.callKit.config.isLogin()) {
1757
1832
  this.userAgent?.reconnect();
1758
- this.setIsReConnected(true);
1759
1833
  this.callKit.logger.info("Reconnect attempt", {
1760
1834
  caller: "Connect.startReconnectTimer",
1761
1835
  type: "SIP",
@@ -2068,6 +2142,35 @@ var Connect = class {
2068
2142
  }
2069
2143
  this.currentSession.refer(target, extra?.sessionReferOptions);
2070
2144
  }
2145
+ async referInCall(referTo, extra) {
2146
+ if (!this.currentSession) {
2147
+ const errorMsg = "Cannot refer in call: currentSession is not available";
2148
+ this.callKit.logger.warn(errorMsg, {
2149
+ caller: "Connect.referInCall",
2150
+ type: "SIP",
2151
+ content: {
2152
+ errCode: ErrorCode.WEBRTC_CALL_INVITE_ERROR,
2153
+ referTo
2154
+ }
2155
+ });
2156
+ return;
2157
+ }
2158
+ this.setInCallRefering(true);
2159
+ this.callKit.logger.info("connect referInCall", {
2160
+ caller: "Connect.referInCall",
2161
+ type: "SIP",
2162
+ content: {
2163
+ referTo,
2164
+ extra,
2165
+ sessionState: this.currentSession.state
2166
+ }
2167
+ });
2168
+ let target;
2169
+ if (referTo) {
2170
+ target = UserAgent.makeURI(referTo);
2171
+ }
2172
+ this.currentSession.refer(target, extra?.sessionReferOptions);
2173
+ }
2071
2174
  };
2072
2175
 
2073
2176
  // core/socket.ts
@@ -2375,14 +2478,10 @@ var Socket = class {
2375
2478
  this.callKit.connect.socketTriggerHangup(callUuid);
2376
2479
  }
2377
2480
  }
2378
- this.callKit.trigger(
2379
- KitEvent.SERVER_SOCKET_EVENT,
2380
- {
2381
- ...data,
2382
- callUuid
2383
- },
2384
- true
2385
- );
2481
+ this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, {
2482
+ ...data,
2483
+ callUuid
2484
+ });
2386
2485
  }
2387
2486
  send(event, message) {
2388
2487
  if (!this.connectAuthState.isConnected) {
@@ -2617,7 +2716,7 @@ var CallKit = class {
2617
2716
  encryptionPassword
2618
2717
  }
2619
2718
  });
2620
- if (this.socket.isError) {
2719
+ if (this.socket.isError || this.connect.isError) {
2621
2720
  this.logger.warn("socket is error", {
2622
2721
  caller: "CallKit.login",
2623
2722
  content: { username, password, extra, socketError: this.socket.isError }
@@ -2855,7 +2954,7 @@ var CallKit = class {
2855
2954
  if (this.connect.isCalling()) {
2856
2955
  await this.hangup();
2857
2956
  }
2858
- await this.connect.reset();
2957
+ await this.connect.reset({ force });
2859
2958
  if (this.config.isLogin()) {
2860
2959
  await this.logout({ isReset: false });
2861
2960
  } else {