@koi-design/callkit 1.0.24-beta.7 → 1.0.24-beta.9

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
@@ -174,6 +174,10 @@ declare const SocketSendEvent: {
174
174
  * End
175
175
  */
176
176
  END: string;
177
+ /**
178
+ * AGENT_TRANSFER
179
+ */
180
+ AGENT_TRANSFER: string;
177
181
  };
178
182
  declare const EncryptionMethod: {
179
183
  NONE: string;
@@ -222,6 +226,7 @@ declare class Socket {
222
226
  private reconnectAttempts;
223
227
  constructor(callKit: CallKit);
224
228
  init(): void;
229
+ private reconnect;
225
230
  private connect;
226
231
  private onOpen;
227
232
  private onClose;
@@ -410,6 +415,7 @@ declare class User {
410
415
  * @param status
411
416
  */
412
417
  updateUserStatus(status: number): Promise<void>;
418
+ sendHangUpReason(data: any): Promise<void>;
413
419
  }
414
420
 
415
421
  interface CallKitConfig {
@@ -438,6 +444,7 @@ declare class CallKit {
438
444
  connect: Connect;
439
445
  socket: Socket;
440
446
  user: User;
447
+ reconnect?: SocketConfig;
441
448
  listener: Listener[];
442
449
  constructor(options: ConfigEntity);
443
450
  login(username: string, password: string, extra?: {
@@ -3505,7 +3505,11 @@ var WebCall = (() => {
3505
3505
  /**
3506
3506
  * End
3507
3507
  */
3508
- END: "STOP"
3508
+ END: "STOP",
3509
+ /**
3510
+ * AGENT_TRANSFER
3511
+ */
3512
+ AGENT_TRANSFER: "AGENT_TRANSFER"
3509
3513
  };
3510
3514
  var SocketReceiveEvent = {
3511
3515
  /**
@@ -3626,6 +3630,12 @@ var WebCall = (() => {
3626
3630
  if (!this.callKit.config.check())
3627
3631
  return;
3628
3632
  this.callKit.logger.debug("callRefer");
3633
+ const { toAgentId, workOrderId } = options;
3634
+ const queryTrain = {
3635
+ toAgentId,
3636
+ workOrderId
3637
+ };
3638
+ this.callKit.socket.send(SocketSendEvent.AGENT_TRANSFER, queryTrain);
3629
3639
  this.callKit.connect.refer(referTo, options);
3630
3640
  }
3631
3641
  /**
@@ -18535,6 +18545,9 @@ var WebCall = (() => {
18535
18545
  };
18536
18546
  await this.userAgent.start().catch((err) => {
18537
18547
  this.callKit.callCenter.callEnd(false, true);
18548
+ this.callKit.user.sendHangUpReason({
18549
+ reason: err
18550
+ });
18538
18551
  this.callKit.logger.error(err, {
18539
18552
  errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
18540
18553
  });
@@ -18741,7 +18754,7 @@ var WebCall = (() => {
18741
18754
  }
18742
18755
  async refer(referTo, extra) {
18743
18756
  this.callKit.logger.debug("connect refer");
18744
- let target = void 0;
18757
+ let target;
18745
18758
  if (referTo) {
18746
18759
  target = UserAgent.makeURI(referTo);
18747
18760
  }
@@ -18785,6 +18798,21 @@ var WebCall = (() => {
18785
18798
  this.callKit.logger.debug(`socket init: ${socket}`);
18786
18799
  this.connect(socket);
18787
18800
  }
18801
+ reconnect(ev) {
18802
+ this.callKit.logger.debug("socket reconnect", ev);
18803
+ this.isConnected = false;
18804
+ if (!this.isReconnecting && this.socketConfig.maxAttempts > 0) {
18805
+ this.attemptReconnect();
18806
+ } else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
18807
+ this.reset();
18808
+ this.callKit.logger.error(
18809
+ "Reconnection failed, maximum retry attempts reached",
18810
+ {
18811
+ errCode: ErrorCode.SOCKET_RECONNECT_FAILED
18812
+ }
18813
+ );
18814
+ }
18815
+ }
18788
18816
  connect(socketUrl) {
18789
18817
  this.ws = new WebSocket(socketUrl);
18790
18818
  this.ws.onopen = (ev) => this.onOpen(ev);
@@ -18804,32 +18832,24 @@ var WebCall = (() => {
18804
18832
  }
18805
18833
  onClose(ev) {
18806
18834
  this.callKit.logger.debug("socket onClose", ev);
18807
- this.isConnected = false;
18808
- this.satrtConfirm = false;
18809
- if (this.pingTimer) {
18810
- clearInterval(this.pingTimer);
18811
- this.pingTimer = void 0;
18835
+ if ((ev.code !== 1e3 || !ev.wasClean) && this.callKit.connect.isRegistered()) {
18836
+ this.reconnect(ev);
18837
+ } else {
18838
+ this.isConnected = false;
18839
+ this.satrtConfirm = false;
18840
+ if (this.pingTimer) {
18841
+ clearInterval(this.pingTimer);
18842
+ this.pingTimer = void 0;
18843
+ }
18844
+ this.callKit.connect.hangup();
18845
+ this.reset();
18812
18846
  }
18813
- this.callKit.connect.hangup();
18814
- this.reset();
18815
18847
  }
18816
18848
  onError(ev) {
18817
18849
  this.callKit.logger.error("socket onError", {
18818
18850
  errCode: ErrorCode.SOCKET_CONNECT_ERROR,
18819
18851
  data: ev
18820
18852
  });
18821
- this.isConnected = false;
18822
- if (!this.isReconnecting && this.socketConfig.maxAttempts > 0) {
18823
- this.attemptReconnect();
18824
- } else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
18825
- this.reset();
18826
- this.callKit.logger.error(
18827
- "Reconnection failed, maximum retry attempts reached",
18828
- {
18829
- errCode: ErrorCode.SOCKET_RECONNECT_FAILED
18830
- }
18831
- );
18832
- }
18833
18853
  }
18834
18854
  onMessage(ev) {
18835
18855
  const data = JSON.parse(ev.data);
@@ -19079,6 +19099,22 @@ var WebCall = (() => {
19079
19099
  });
19080
19100
  });
19081
19101
  }
19102
+ async sendHangUpReason(data) {
19103
+ try {
19104
+ const { reason = "" } = data;
19105
+ const { userInfo } = this.callKit.config.getConfig();
19106
+ const { username } = userInfo;
19107
+ const reasonData = {
19108
+ username,
19109
+ userInfo,
19110
+ reason
19111
+ };
19112
+ const reasonStr = JSON.stringify(reasonData);
19113
+ this.callKit.socket.send(SocketSendEvent.CALL, reasonStr);
19114
+ } catch (error) {
19115
+ this.callKit.logger.debug(error);
19116
+ }
19117
+ }
19082
19118
  };
19083
19119
 
19084
19120
  // package/index.ts
@@ -19090,6 +19126,7 @@ var WebCall = (() => {
19090
19126
  connect;
19091
19127
  socket;
19092
19128
  user;
19129
+ reconnect;
19093
19130
  listener = [];
19094
19131
  constructor(options) {
19095
19132
  this.config = new Config(this);
@@ -19105,6 +19142,7 @@ var WebCall = (() => {
19105
19142
  "isAutoUpdateUserStatus",
19106
19143
  options.isAutoUpdateUserStatus === void 0 ? isAutoUpdateUserStatusDefault : options.isAutoUpdateUserStatus
19107
19144
  );
19145
+ this.config.setConfig("reconnect", options.reconnect);
19108
19146
  this.logger = new Logger(this, options.log);
19109
19147
  this.logger.debug("callKit init", options);
19110
19148
  this.api = new Api(this);