@koi-design/callkit 2.2.0-beta.4 → 2.3.0-beta.1

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
@@ -72,7 +72,7 @@ var Api = class {
72
72
  const res = await this.post({
73
73
  url: "/auth/agentUser/login",
74
74
  method: "post",
75
- data: { ...params, browserVersion: navigator.userAgent }
75
+ data: params
76
76
  });
77
77
  return res;
78
78
  } finally {
@@ -555,6 +555,12 @@ var CallSourceType = {
555
555
  phoneNum: 1,
556
556
  workOrderId: 2
557
557
  };
558
+ var PhoneTypeEnum = {
559
+ SIP: 0,
560
+ TEL: 1,
561
+ OUT: 2,
562
+ SP: 5
563
+ };
558
564
  var trackLogsDefaultConfig = {
559
565
  enabled: false,
560
566
  interval: 5e3,
@@ -718,7 +724,7 @@ var Call = class {
718
724
  // package.json
719
725
  var package_default = {
720
726
  name: "@koi-design/callkit",
721
- version: "2.2.0-beta.4",
727
+ version: "2.3.0-beta.1",
722
728
  description: "callkit",
723
729
  author: "koi",
724
730
  license: "ISC",
@@ -795,6 +801,7 @@ var Config = class {
795
801
  password: "",
796
802
  encryptionPassword: EncryptionMethod.INTERNAL,
797
803
  sourceType: CallSourceType.phoneNum,
804
+ phoneType: PhoneTypeEnum.SIP,
798
805
  // Extension number
799
806
  extno: "",
800
807
  workOrderId: "",
@@ -838,6 +845,7 @@ var Config = class {
838
845
  encryptionPassword: "",
839
846
  userPart: "",
840
847
  sourceType: CallSourceType.phoneNum,
848
+ phoneType: PhoneTypeEnum.SIP,
841
849
  extno: "",
842
850
  workOrderId: "",
843
851
  agentId: "",
@@ -16702,152 +16710,12 @@ var Connect = class {
16702
16710
  }
16703
16711
  };
16704
16712
 
16705
- // core/heartbeat-worker.ts
16706
- var workerCode = `
16707
- let timer = null;
16708
- let interval = 30000;
16709
-
16710
- self.onmessage = function(e) {
16711
- const { type, interval: newInterval } = e.data;
16712
-
16713
- if (type === 'start') {
16714
- if (timer) {
16715
- clearInterval(timer);
16716
- }
16717
- interval = newInterval || interval;
16718
- timer = setInterval(() => {
16719
- self.postMessage({ type: 'tick' });
16720
- }, interval);
16721
- }
16722
-
16723
- if (type === 'stop') {
16724
- if (timer) {
16725
- clearInterval(timer);
16726
- timer = null;
16727
- }
16728
- }
16729
-
16730
- if (type === 'updateInterval') {
16731
- interval = newInterval;
16732
- if (timer) {
16733
- clearInterval(timer);
16734
- timer = setInterval(() => {
16735
- self.postMessage({ type: 'tick' });
16736
- }, interval);
16737
- }
16738
- }
16739
- };
16740
- `;
16741
- function createHeartbeatWorker() {
16742
- try {
16743
- const blob = new Blob([workerCode], { type: "application/javascript" });
16744
- const workerUrl = URL.createObjectURL(blob);
16745
- const worker = new Worker(workerUrl);
16746
- URL.revokeObjectURL(workerUrl);
16747
- return worker;
16748
- } catch {
16749
- return null;
16750
- }
16751
- }
16752
- var HeartbeatManager = class {
16753
- worker = null;
16754
- fallbackTimer = null;
16755
- interval = 3e4;
16756
- onTick = null;
16757
- isRunning = false;
16758
- constructor() {
16759
- this.worker = createHeartbeatWorker();
16760
- if (this.worker) {
16761
- this.worker.onmessage = (e) => {
16762
- if (e.data.type === "tick" && this.onTick) {
16763
- this.onTick();
16764
- }
16765
- };
16766
- }
16767
- }
16768
- /**
16769
- * Start the heartbeat
16770
- * @param interval - Interval in milliseconds
16771
- * @param onTick - Callback function to execute on each tick
16772
- */
16773
- start(interval, onTick) {
16774
- this.stop();
16775
- this.interval = interval;
16776
- this.onTick = onTick;
16777
- this.isRunning = true;
16778
- if (this.worker) {
16779
- this.worker.postMessage({
16780
- type: "start",
16781
- interval
16782
- });
16783
- } else {
16784
- this.fallbackTimer = setInterval(() => {
16785
- if (this.onTick) {
16786
- this.onTick();
16787
- }
16788
- }, interval);
16789
- }
16790
- }
16791
- /**
16792
- * Stop the heartbeat
16793
- */
16794
- stop() {
16795
- this.isRunning = false;
16796
- this.onTick = null;
16797
- if (this.worker) {
16798
- this.worker.postMessage({ type: "stop" });
16799
- }
16800
- if (this.fallbackTimer) {
16801
- clearInterval(this.fallbackTimer);
16802
- this.fallbackTimer = null;
16803
- }
16804
- }
16805
- /**
16806
- * Update the heartbeat interval
16807
- * @param interval - New interval in milliseconds
16808
- */
16809
- updateInterval(interval) {
16810
- this.interval = interval;
16811
- if (!this.isRunning)
16812
- return;
16813
- if (this.worker) {
16814
- this.worker.postMessage({
16815
- type: "updateInterval",
16816
- interval
16817
- });
16818
- } else if (this.fallbackTimer && this.onTick) {
16819
- clearInterval(this.fallbackTimer);
16820
- this.fallbackTimer = setInterval(() => {
16821
- if (this.onTick) {
16822
- this.onTick();
16823
- }
16824
- }, interval);
16825
- }
16826
- }
16827
- /**
16828
- * Destroy the heartbeat manager and release resources
16829
- */
16830
- destroy() {
16831
- this.stop();
16832
- if (this.worker) {
16833
- this.worker.terminate();
16834
- this.worker = null;
16835
- }
16836
- }
16837
- /**
16838
- * Check if using Web Worker
16839
- */
16840
- isUsingWorker() {
16841
- return this.worker !== null;
16842
- }
16843
- };
16844
-
16845
16713
  // core/socket.ts
16846
16714
  var Socket = class {
16847
16715
  callKit;
16848
16716
  ws;
16849
16717
  lastPingTime = void 0;
16850
- heartbeatManager;
16718
+ pingTimer;
16851
16719
  /**
16852
16720
  * @description reconnect timer
16853
16721
  */
@@ -16880,18 +16748,10 @@ var Socket = class {
16880
16748
  }
16881
16749
  constructor(callKit) {
16882
16750
  this.callKit = callKit;
16883
- this.heartbeatManager = new HeartbeatManager();
16884
16751
  }
16885
16752
  get reconnectConfig() {
16886
16753
  return this.callKit.config.getReconnectConfig("incall");
16887
16754
  }
16888
- get pingInterval() {
16889
- const { keepaliveInterval } = this.callKit.config.getConfig().userInfo;
16890
- if (Number.isInteger(keepaliveInterval) && keepaliveInterval > 0) {
16891
- return keepaliveInterval * 1e3;
16892
- }
16893
- return this.reconnectConfig.pingInterval;
16894
- }
16895
16755
  isConnected() {
16896
16756
  return this.connectAuthState.isConnected;
16897
16757
  }
@@ -17185,7 +17045,7 @@ var Socket = class {
17185
17045
  return;
17186
17046
  }
17187
17047
  const { userInfo, version } = this.callKit.config.getConfig();
17188
- const { sessionId, extno, agentId } = userInfo;
17048
+ const { sessionId, extno, agentId, phoneType } = userInfo;
17189
17049
  if (!sessionId) {
17190
17050
  this.callKit.logger.error("sessionId is empty", {
17191
17051
  caller: "Socket.send",
@@ -17205,6 +17065,7 @@ var Socket = class {
17205
17065
  if (SocketSendEvent.CALL === event) {
17206
17066
  msg.phoneNum = extno;
17207
17067
  msg.agentId = agentId;
17068
+ msg.phoneType = phoneType;
17208
17069
  if (message?.sourceType === CallSourceType.phoneNum) {
17209
17070
  delete msg.workOrderId;
17210
17071
  } else if (message?.sourceType === CallSourceType.workOrderId) {
@@ -17226,8 +17087,8 @@ var Socket = class {
17226
17087
  return;
17227
17088
  this.send(SocketSendEvent.PING);
17228
17089
  const now = Date.now();
17229
- const { pingTimeout } = this.reconnectConfig;
17230
- if (now - this.lastPingTime > this.pingInterval + pingTimeout) {
17090
+ const { pingInterval, pingTimeout } = this.reconnectConfig;
17091
+ if (now - this.lastPingTime > pingInterval + pingTimeout) {
17231
17092
  this.callKit.logger.warn("Ping timeout not connected", {
17232
17093
  caller: "Socket.ping",
17233
17094
  type: "INCALL",
@@ -17242,27 +17103,23 @@ var Socket = class {
17242
17103
  }
17243
17104
  }
17244
17105
  checkPing() {
17245
- this.heartbeatManager.start(this.pingInterval, () => {
17106
+ if (this.pingTimer) {
17107
+ clearInterval(this.pingTimer);
17108
+ }
17109
+ const { pingInterval } = this.reconnectConfig;
17110
+ this.pingTimer = setInterval(() => {
17246
17111
  this.ping();
17247
- });
17248
- this.callKit.logger.info(
17249
- `Heartbeat started with Worker: ${this.heartbeatManager.isUsingWorker()}`,
17250
- {
17251
- caller: "Socket.checkPing",
17252
- type: "INCALL",
17253
- content: {
17254
- pingInterval: this.pingInterval,
17255
- usingWorker: this.heartbeatManager.isUsingWorker()
17256
- }
17257
- }
17258
- );
17112
+ }, pingInterval);
17259
17113
  }
17260
17114
  /**
17261
17115
  * reset socket connection and all states
17262
17116
  */
17263
17117
  async reset(config) {
17264
17118
  const { force = false } = config || {};
17265
- this.heartbeatManager.stop();
17119
+ if (this.pingTimer) {
17120
+ clearInterval(this.pingTimer);
17121
+ this.pingTimer = void 0;
17122
+ }
17266
17123
  if (force) {
17267
17124
  this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
17268
17125
  event: "INCALL_RESET"
@@ -17273,12 +17130,6 @@ var Socket = class {
17273
17130
  this.setConnectAuthState("startConfirm", false);
17274
17131
  this.clearWebSocket();
17275
17132
  }
17276
- /**
17277
- * Destroy the heartbeat manager
17278
- */
17279
- destroyHeartbeat() {
17280
- this.heartbeatManager.destroy();
17281
- }
17282
17133
  attemptReconnect() {
17283
17134
  if (this.reconnectTimer) {
17284
17135
  clearTimeout(this.reconnectTimer);
@@ -17404,7 +17255,6 @@ var CallKit = class {
17404
17255
  content: {
17405
17256
  username,
17406
17257
  password,
17407
- ua: navigator.userAgent,
17408
17258
  encryptionMethod,
17409
17259
  encryptionPassword
17410
17260
  }
@@ -17422,7 +17272,6 @@ var CallKit = class {
17422
17272
  password: encryptionPassword,
17423
17273
  timestamp: Date.now()
17424
17274
  });
17425
- console.log("user", user);
17426
17275
  if (user) {
17427
17276
  this.config.setConfig("userInfo", {
17428
17277
  wsUrl: `wss://${user.wsUrl}`,
@@ -17439,7 +17288,7 @@ var CallKit = class {
17439
17288
  iceInfo: user.iceInfo,
17440
17289
  iceGatheringTimeout: user.iceGatheringTimeout,
17441
17290
  logGather: user.logGather,
17442
- keepaliveInterval: user.keepaliveInterval,
17291
+ phoneType: user.phoneType,
17443
17292
  // encryptionType is in extra
17444
17293
  ...extra
17445
17294
  });