@koi-design/callkit 1.0.24-beta.16 → 1.0.24-beta.18

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
@@ -451,7 +451,6 @@ declare class CallKit {
451
451
  connect: Connect;
452
452
  socket: Socket;
453
453
  user: User;
454
- reconnect?: SocketConfig;
455
454
  listener: Listener[];
456
455
  constructor(options: ConfigEntity);
457
456
  login(username: string, password: string, extra?: {
@@ -18472,8 +18472,27 @@ var WebCall = (() => {
18472
18472
  });
18473
18473
  }
18474
18474
  };
18475
- const observeOptionsHeartbeat = (userAgent, extra) => {
18475
+ const observeSocketStatus = (userAgent, extra) => {
18476
18476
  const { that = this } = extra;
18477
+ that.userAgent.transport.onDisconnect = (error) => {
18478
+ if (error) {
18479
+ that.callKit.logger.debug("connect onDisconnect");
18480
+ if (that.isRegistered() && !(that.sipConnected || that.isRinging() || that.isCalling() || that.isHolding())) {
18481
+ that.reconnect();
18482
+ } else {
18483
+ const data = {
18484
+ kitEvent: ConnectEvent.SIP_CONNECT_ERROR,
18485
+ err: error
18486
+ };
18487
+ that.callKit.logger.debug("SIP WebSocket closed with error", data);
18488
+ that.callKit.trigger(KitEvent.CONNECT_EVENT, data);
18489
+ that.callKit.user.sendHangUpReason(data);
18490
+ that.callKit.callCenter.callEnd();
18491
+ }
18492
+ } else {
18493
+ that.callKit.logger.debug("SIP WebSocket closed normally");
18494
+ }
18495
+ };
18477
18496
  that.clearObserveOptionsHeartbeatInterval();
18478
18497
  setInterval(() => {
18479
18498
  if (that.lastOptionsUpdateTime !== 0) {
@@ -18481,7 +18500,7 @@ var WebCall = (() => {
18481
18500
  const diff = now - that.lastOptionsUpdateTime;
18482
18501
  if (diff > 6e4) {
18483
18502
  const data = {
18484
- event: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
18503
+ kitEvent: ConnectEvent.OPTIONS_HEARTBEAT_EXPIRED,
18485
18504
  lastOptionsUpdateTime: that.lastOptionsUpdateTime,
18486
18505
  now
18487
18506
  };
@@ -18585,7 +18604,7 @@ var WebCall = (() => {
18585
18604
  this.reconnect();
18586
18605
  } else {
18587
18606
  const data = {
18588
- event: ConnectEvent.SIP_CONNECT_ERROR,
18607
+ kitEvent: ConnectEvent.SIP_CONNECT_ERROR,
18589
18608
  err: error
18590
18609
  };
18591
18610
  this.callKit.trigger(KitEvent.CONNECT_EVENT, data);
@@ -18611,13 +18630,13 @@ var WebCall = (() => {
18611
18630
  // });
18612
18631
  // }
18613
18632
  };
18614
- observeOptionsHeartbeat(this.userAgent, {
18633
+ observeSocketStatus(this.userAgent, {
18615
18634
  that: this
18616
18635
  });
18617
18636
  await this.userAgent.start().catch((err) => {
18618
18637
  this.callKit.callCenter.callEnd(false, true);
18619
18638
  const data = {
18620
- event: ConnectEvent.USER_AGENT_START_ERROR,
18639
+ kitEvent: ConnectEvent.USER_AGENT_START_ERROR,
18621
18640
  err
18622
18641
  };
18623
18642
  this.callKit.user.sendHangUpReason(data);
@@ -18654,7 +18673,7 @@ var WebCall = (() => {
18654
18673
  await scheduleReconnect();
18655
18674
  } else {
18656
18675
  const data = {
18657
- event: ConnectEvent.SIP_RECONNECT_ERROR
18676
+ kitEvent: ConnectEvent.SIP_RECONNECT_ERROR
18658
18677
  };
18659
18678
  this.callKit.trigger(KitEvent.CONNECT_EVENT, data);
18660
18679
  this.callKit.user.sendHangUpReason(data);
@@ -19228,15 +19247,8 @@ var WebCall = (() => {
19228
19247
  }
19229
19248
  async sendHangUpReason(data) {
19230
19249
  try {
19231
- const { userInfo } = this.callKit.config.getConfig();
19232
- const { username } = userInfo;
19233
- const sendData = {
19234
- username,
19235
- userInfo,
19236
- ...data
19237
- };
19238
- const sendDataStr = JSON.stringify(sendData);
19239
- this.callKit.socket.send(SocketSendEvent.CALL, sendDataStr);
19250
+ const sendData = data || {};
19251
+ this.callKit.socket.send(SocketSendEvent.CALL, sendData);
19240
19252
  } catch (error) {
19241
19253
  this.callKit.logger.debug(error);
19242
19254
  }
@@ -19252,7 +19264,6 @@ var WebCall = (() => {
19252
19264
  connect;
19253
19265
  socket;
19254
19266
  user;
19255
- reconnect;
19256
19267
  listener = [];
19257
19268
  constructor(options) {
19258
19269
  this.config = new Config(this);