@koi-design/callkit 2.0.0-beta.4 → 2.0.0-beta.5

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
@@ -243,7 +243,8 @@ var KitEvent = {
243
243
  * User status change
244
244
  */
245
245
  USER_STATUS_CHANGE: "userStatusChange",
246
- CONNECT_EVENT: "CONNECT_EVENT",
246
+ INCALL_CONNECT_EVENT: "IncallConnectEvent",
247
+ SIP_CONNECT_EVENT: "sipConnectEvent",
247
248
  SIP_REGISTERER_EVENT: "sipRegistererEvent",
248
249
  SIP_SESSION_EVENT: "sipSessionEvent"
249
250
  };
@@ -568,7 +569,7 @@ var Call = class {
568
569
  });
569
570
  return;
570
571
  }
571
- this.callKit.connect.setHold(true);
572
+ this.callKit.connect.setHold(false);
572
573
  }
573
574
  async callMute() {
574
575
  if (!this.callKit.config.check())
@@ -925,7 +926,7 @@ var Connect = class {
925
926
  if (this.connectStatus !== CallStatus.init) {
926
927
  this.setConnectStatus(CallStatus.init);
927
928
  }
928
- if (this.isRegistered) {
929
+ if (this.isRegistered()) {
929
930
  this.unregister();
930
931
  }
931
932
  this.currentSession = void 0;
@@ -1029,7 +1030,7 @@ var Connect = class {
1029
1030
  this.heartbeatFlag -= 1;
1030
1031
  if (this.heartbeatFlag <= 0) {
1031
1032
  this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
1032
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
1033
+ this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
1033
1034
  event: "OPTIONS_HEARTBEAT_EXPIRED"
1034
1035
  });
1035
1036
  }
@@ -1193,6 +1194,10 @@ var Connect = class {
1193
1194
  }
1194
1195
  });
1195
1196
  this.setRegister(true);
1197
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1198
+ registererState: state,
1199
+ isRegistered: this.isRegistered()
1200
+ });
1196
1201
  break;
1197
1202
  case import_sip.RegistererState.Terminated:
1198
1203
  this.callKit.logger.info("registerer stateChange Terminated", {
@@ -1205,6 +1210,10 @@ var Connect = class {
1205
1210
  });
1206
1211
  this.setRegister(false);
1207
1212
  this.setConnectStatus(CallStatus.init);
1213
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1214
+ registererState: state,
1215
+ isRegistered: this.isRegistered()
1216
+ });
1208
1217
  break;
1209
1218
  case import_sip.RegistererState.Unregistered:
1210
1219
  this.callKit.logger.info("registerer stateChange Unregistered", {
@@ -1217,6 +1226,10 @@ var Connect = class {
1217
1226
  });
1218
1227
  this.setRegister(false);
1219
1228
  this.setConnectStatus(CallStatus.init);
1229
+ this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
1230
+ registererState: state,
1231
+ isRegistered: this.isRegistered()
1232
+ });
1220
1233
  break;
1221
1234
  default:
1222
1235
  break;
@@ -1306,7 +1319,6 @@ var Connect = class {
1306
1319
  };
1307
1320
  if (this.isOutgoing) {
1308
1321
  this.currentSession.accept(options);
1309
- this.setConnectStatus(CallStatus.connecting);
1310
1322
  this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
1311
1323
  getInviteData: () => {
1312
1324
  const { request: request2 } = this.currentSession;
@@ -1787,7 +1799,7 @@ var Connect = class {
1787
1799
  // package/socket.ts
1788
1800
  var RECONNECT_CONFIG = {
1789
1801
  enabled: true,
1790
- maxAttempts: 1,
1802
+ maxAttempts: 3,
1791
1803
  delay: 500,
1792
1804
  backoffMultiplier: 1.5,
1793
1805
  pingInterval: 3e4,
@@ -1805,6 +1817,7 @@ var Socket = class {
1805
1817
  reconnectTimer;
1806
1818
  isReconnecting = false;
1807
1819
  reconnectAttempts = 0;
1820
+ socketError = false;
1808
1821
  constructor(callKit) {
1809
1822
  this.callKit = callKit;
1810
1823
  const { reconnect } = this.callKit.config.getConfig();
@@ -1828,7 +1841,7 @@ var Socket = class {
1828
1841
  this.isConnected = false;
1829
1842
  if (!this.callKit.config.isLogin() || !this.socketConfig.enabled) {
1830
1843
  this.reset();
1831
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
1844
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
1832
1845
  event: "INCALL_NOT_CONNECTED"
1833
1846
  });
1834
1847
  return;
@@ -1848,6 +1861,7 @@ var Socket = class {
1848
1861
  type: "INCALL",
1849
1862
  content: { ev }
1850
1863
  });
1864
+ this.socketError = false;
1851
1865
  this.isConnected = true;
1852
1866
  this.lastPingTime = Date.now();
1853
1867
  this.checkPing();
@@ -1860,7 +1874,7 @@ var Socket = class {
1860
1874
  reconnectAttempts: this.reconnectAttempts
1861
1875
  }
1862
1876
  });
1863
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
1877
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
1864
1878
  event: "INCALL_RECONNECT_SUCCESS"
1865
1879
  });
1866
1880
  }
@@ -1880,10 +1894,13 @@ var Socket = class {
1880
1894
  type: "INCALL",
1881
1895
  content: { ev }
1882
1896
  });
1883
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
1897
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
1884
1898
  event: "INCALL_CONNECT_ERROR",
1885
1899
  err: ev
1886
1900
  });
1901
+ if (this.socketError) {
1902
+ return;
1903
+ }
1887
1904
  this.handleDisconnect();
1888
1905
  }
1889
1906
  onError(ev) {
@@ -1895,6 +1912,7 @@ var Socket = class {
1895
1912
  data: ev
1896
1913
  }
1897
1914
  });
1915
+ this.socketError = true;
1898
1916
  }
1899
1917
  confirmAck(data) {
1900
1918
  const { ack, messageId } = data;
@@ -2052,7 +2070,7 @@ var Socket = class {
2052
2070
  }
2053
2071
  send(event, message) {
2054
2072
  if (!this.isConnected) {
2055
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
2073
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2056
2074
  event: "INCALL_NOT_CONNECTED"
2057
2075
  });
2058
2076
  this.callKit.logger.error("socket not connected", {
@@ -2111,7 +2129,7 @@ var Socket = class {
2111
2129
  }
2112
2130
  async sendMessage(event, message) {
2113
2131
  if (!this.isConnected) {
2114
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
2132
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2115
2133
  event: "INCALL_NOT_CONNECTED"
2116
2134
  });
2117
2135
  this.callKit.logger.error("socket not connected", {
@@ -2165,8 +2183,7 @@ var Socket = class {
2165
2183
  }, this.socketConfig.pingInterval);
2166
2184
  }
2167
2185
  /**
2168
- * 重置 socket 连接和所有状态
2169
- * @param isWaitConfirm Whether need to wait for close confirmation
2186
+ * reset socket connection and all states
2170
2187
  */
2171
2188
  async reset() {
2172
2189
  if (this.pingTimer) {
@@ -2176,6 +2193,7 @@ var Socket = class {
2176
2193
  this.resetReconnectState();
2177
2194
  this.lastPingTime = void 0;
2178
2195
  this.satrtConfirm = false;
2196
+ this.socketError = false;
2179
2197
  if (this.ws && this.isConnected) {
2180
2198
  this.callKit.logger.info("Closing socket connection", {
2181
2199
  caller: "Socket.reset",
@@ -2196,14 +2214,14 @@ var Socket = class {
2196
2214
  reconnectAttempts: this.reconnectAttempts
2197
2215
  }
2198
2216
  });
2199
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
2217
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2200
2218
  event: "INCALL_RECONNECT_ERROR"
2201
2219
  });
2202
2220
  this.reset();
2203
2221
  return;
2204
2222
  }
2205
2223
  if (this.reconnectAttempts === 0) {
2206
- this.callKit.trigger(KitEvent.CONNECT_EVENT, {
2224
+ this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
2207
2225
  event: "INCALL_RECONNECT_START"
2208
2226
  });
2209
2227
  }