@koi-design/callkit 1.0.23 → 1.0.24-beta.10

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
@@ -24,6 +24,12 @@ declare class Call {
24
24
  private callKit;
25
25
  constructor(callKit: CallKit);
26
26
  callStart(): Promise<void>;
27
+ /**
28
+ * Refer
29
+ * @param referTo - The referral target. If a `Session`, a REFER w/Replaces is sent.
30
+ * @returns
31
+ */
32
+ callRefer(referTo: string, options?: any): Promise<void>;
27
33
  /**
28
34
  * Hang up
29
35
  * @param isUnprompted Whether to actively hang up
@@ -168,12 +174,20 @@ declare const SocketSendEvent: {
168
174
  * End
169
175
  */
170
176
  END: string;
177
+ /**
178
+ * AGENT_TRANSFER
179
+ */
180
+ AGENT_TRANSFER: string;
171
181
  };
172
182
  declare const EncryptionMethod: {
173
183
  NONE: string;
174
184
  INTERNAL: string;
175
185
  };
176
- type EncryptionMethodType = (typeof EncryptionMethod)[keyof typeof EncryptionMethod];
186
+ type EncryptionMethodType = (typeof EncryptionMethod)[keyof typeof EncryptionMethod];
187
+ declare const CallSourceType: {
188
+ phoneNum: number;
189
+ workOrderId: number;
190
+ };
177
191
 
178
192
  type LoggerLevel = 'debug' | 'log' | 'warn' | 'error' | 'silent';
179
193
  declare class Logger {
@@ -255,7 +269,9 @@ interface IConfig {
255
269
  username: string;
256
270
  password: string;
257
271
  encryptionPassword: string;
272
+ sourceType: (typeof CallSourceType)[keyof typeof CallSourceType];
258
273
  extno: string;
274
+ workOrderId: string;
259
275
  userPart: string;
260
276
  agentId: string;
261
277
  fsUserId: string;
@@ -381,6 +397,7 @@ declare class Connect {
381
397
  setMute(mute: boolean): Promise<void>;
382
398
  mute(): Promise<void>;
383
399
  unmute(): Promise<void>;
400
+ refer(referTo: string, extra?: any): Promise<void>;
384
401
  }
385
402
 
386
403
  declare class User {
@@ -397,6 +414,7 @@ declare class User {
397
414
  * @param status
398
415
  */
399
416
  updateUserStatus(status: number): Promise<void>;
417
+ sendHangUpReason(data: any): Promise<void>;
400
418
  }
401
419
 
402
420
  interface CallKitConfig {
@@ -412,6 +430,11 @@ interface Listener {
412
430
  event: kitEventType;
413
431
  callback: (...args: any[]) => void;
414
432
  }
433
+ interface CallOptions {
434
+ sourceType: (typeof CallSourceType)[keyof typeof CallSourceType];
435
+ phoneNum?: string;
436
+ workOrderId?: string;
437
+ }
415
438
  declare class CallKit {
416
439
  api: Api;
417
440
  config: Config;
@@ -426,7 +449,8 @@ declare class CallKit {
426
449
  [key: string]: any;
427
450
  }): Promise<void>;
428
451
  logout(): Promise<void>;
429
- call(extno?: string | number): Promise<void>;
452
+ call(extno?: string | number, options?: CallOptions): Promise<void>;
453
+ refer(uri: string, options?: any): Promise<void>;
430
454
  register(): Promise<void>;
431
455
  unregister(): Promise<void>;
432
456
  hangup(): Promise<void>;
@@ -1065,9 +1065,9 @@ var WebCall = (() => {
1065
1065
  }
1066
1066
  });
1067
1067
 
1068
- // node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/common.js
1068
+ // node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/common.js
1069
1069
  var require_common = __commonJS({
1070
- "node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/common.js"(exports, module) {
1070
+ "node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/common.js"(exports, module) {
1071
1071
  function setup(env) {
1072
1072
  createDebug.debug = createDebug;
1073
1073
  createDebug.default = createDebug;
@@ -1168,50 +1168,64 @@ var WebCall = (() => {
1168
1168
  createDebug.namespaces = namespaces;
1169
1169
  createDebug.names = [];
1170
1170
  createDebug.skips = [];
1171
- let i;
1172
- const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
1173
- const len = split.length;
1174
- for (i = 0; i < len; i++) {
1175
- if (!split[i]) {
1176
- continue;
1171
+ const split = (typeof namespaces === "string" ? namespaces : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean);
1172
+ for (const ns of split) {
1173
+ if (ns[0] === "-") {
1174
+ createDebug.skips.push(ns.slice(1));
1175
+ } else {
1176
+ createDebug.names.push(ns);
1177
1177
  }
1178
- namespaces = split[i].replace(/\*/g, ".*?");
1179
- if (namespaces[0] === "-") {
1180
- createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$"));
1178
+ }
1179
+ }
1180
+ function matchesTemplate(search, template) {
1181
+ let searchIndex = 0;
1182
+ let templateIndex = 0;
1183
+ let starIndex = -1;
1184
+ let matchIndex = 0;
1185
+ while (searchIndex < search.length) {
1186
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === "*")) {
1187
+ if (template[templateIndex] === "*") {
1188
+ starIndex = templateIndex;
1189
+ matchIndex = searchIndex;
1190
+ templateIndex++;
1191
+ } else {
1192
+ searchIndex++;
1193
+ templateIndex++;
1194
+ }
1195
+ } else if (starIndex !== -1) {
1196
+ templateIndex = starIndex + 1;
1197
+ matchIndex++;
1198
+ searchIndex = matchIndex;
1181
1199
  } else {
1182
- createDebug.names.push(new RegExp("^" + namespaces + "$"));
1200
+ return false;
1183
1201
  }
1184
1202
  }
1203
+ while (templateIndex < template.length && template[templateIndex] === "*") {
1204
+ templateIndex++;
1205
+ }
1206
+ return templateIndex === template.length;
1185
1207
  }
1186
1208
  function disable() {
1187
1209
  const namespaces = [
1188
- ...createDebug.names.map(toNamespace),
1189
- ...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace)
1210
+ ...createDebug.names,
1211
+ ...createDebug.skips.map((namespace) => "-" + namespace)
1190
1212
  ].join(",");
1191
1213
  createDebug.enable("");
1192
1214
  return namespaces;
1193
1215
  }
1194
1216
  function enabled(name) {
1195
- if (name[name.length - 1] === "*") {
1196
- return true;
1197
- }
1198
- let i;
1199
- let len;
1200
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
1201
- if (createDebug.skips[i].test(name)) {
1217
+ for (const skip of createDebug.skips) {
1218
+ if (matchesTemplate(name, skip)) {
1202
1219
  return false;
1203
1220
  }
1204
1221
  }
1205
- for (i = 0, len = createDebug.names.length; i < len; i++) {
1206
- if (createDebug.names[i].test(name)) {
1222
+ for (const ns of createDebug.names) {
1223
+ if (matchesTemplate(name, ns)) {
1207
1224
  return true;
1208
1225
  }
1209
1226
  }
1210
1227
  return false;
1211
1228
  }
1212
- function toNamespace(regexp) {
1213
- return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*");
1214
- }
1215
1229
  function coerce(val) {
1216
1230
  if (val instanceof Error) {
1217
1231
  return val.stack || val.message;
@@ -1228,9 +1242,9 @@ var WebCall = (() => {
1228
1242
  }
1229
1243
  });
1230
1244
 
1231
- // node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/browser.js
1245
+ // node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/browser.js
1232
1246
  var require_browser = __commonJS({
1233
- "node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/browser.js"(exports, module) {
1247
+ "node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/browser.js"(exports, module) {
1234
1248
  exports.formatArgs = formatArgs;
1235
1249
  exports.save = save;
1236
1250
  exports.load = load;
@@ -1372,7 +1386,7 @@ var WebCall = (() => {
1372
1386
  function load() {
1373
1387
  let r;
1374
1388
  try {
1375
- r = exports.storage.getItem("debug");
1389
+ r = exports.storage.getItem("debug") || exports.storage.getItem("DEBUG");
1376
1390
  } catch (error) {
1377
1391
  }
1378
1392
  if (!r && typeof process !== "undefined" && "env" in process) {
@@ -1513,9 +1527,9 @@ var WebCall = (() => {
1513
1527
  }
1514
1528
  });
1515
1529
 
1516
- // node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/node.js
1530
+ // node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/node.js
1517
1531
  var require_node = __commonJS({
1518
- "node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/node.js"(exports, module) {
1532
+ "node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/node.js"(exports, module) {
1519
1533
  var tty = __require("tty");
1520
1534
  var util = __require("util");
1521
1535
  exports.init = init;
@@ -1687,9 +1701,9 @@ var WebCall = (() => {
1687
1701
  }
1688
1702
  });
1689
1703
 
1690
- // node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/index.js
1704
+ // node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/index.js
1691
1705
  var require_src = __commonJS({
1692
- "node_modules/.pnpm/debug@4.3.7/node_modules/debug/src/index.js"(exports, module) {
1706
+ "node_modules/.pnpm/debug@4.4.1/node_modules/debug/src/index.js"(exports, module) {
1693
1707
  if (typeof process === "undefined" || process.type === "renderer" || process.browser === true || process.__nwjs) {
1694
1708
  module.exports = require_browser();
1695
1709
  } else {
@@ -3321,6 +3335,10 @@ var WebCall = (() => {
3321
3335
  * Server initiated call
3322
3336
  */
3323
3337
  KIT_INVITE: "invite",
3338
+ // /**
3339
+ // * Referral
3340
+ // */
3341
+ // KIT_REFER: 'refer',
3324
3342
  /**
3325
3343
  * Connecting
3326
3344
  */
@@ -3487,7 +3505,11 @@ var WebCall = (() => {
3487
3505
  /**
3488
3506
  * End
3489
3507
  */
3490
- END: "STOP"
3508
+ END: "STOP",
3509
+ /**
3510
+ * AGENT_TRANSFER
3511
+ */
3512
+ AGENT_TRANSFER: "AGENT_TRANSFER"
3491
3513
  };
3492
3514
  var SocketReceiveEvent = {
3493
3515
  /**
@@ -3562,6 +3584,10 @@ var WebCall = (() => {
3562
3584
  video: false
3563
3585
  };
3564
3586
  var isAutoUpdateUserStatusDefault = true;
3587
+ var CallSourceType = {
3588
+ phoneNum: 1,
3589
+ workOrderId: 2
3590
+ };
3565
3591
 
3566
3592
  // package/call.ts
3567
3593
  var Call = class {
@@ -3578,13 +3604,40 @@ var WebCall = (() => {
3578
3604
  return;
3579
3605
  }
3580
3606
  this.callKit.connect.call(async (user) => {
3581
- const queryTrain = {
3582
- agentId: user.agentId,
3583
- phoneNum: user.extno
3584
- };
3607
+ let queryTrain = {};
3608
+ if (user.sourceType === CallSourceType.phoneNum) {
3609
+ queryTrain = {
3610
+ agentId: user.agentId,
3611
+ phoneNum: user.extno,
3612
+ sourceType: user.sourceType
3613
+ };
3614
+ } else if (user.sourceType === CallSourceType.workOrderId) {
3615
+ queryTrain = {
3616
+ agentId: user.agentId,
3617
+ workOrderId: user.workOrderId,
3618
+ sourceType: user.sourceType
3619
+ };
3620
+ }
3585
3621
  this.callKit.socket.send(SocketSendEvent.CALL, queryTrain);
3586
3622
  });
3587
3623
  }
3624
+ /**
3625
+ * Refer
3626
+ * @param referTo - The referral target. If a `Session`, a REFER w/Replaces is sent.
3627
+ * @returns
3628
+ */
3629
+ async callRefer(referTo, options) {
3630
+ if (!this.callKit.config.check())
3631
+ return;
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);
3639
+ this.callKit.connect.refer(referTo, options);
3640
+ }
3588
3641
  /**
3589
3642
  * Hang up
3590
3643
  * @param isUnprompted Whether to actively hang up
@@ -3643,8 +3696,10 @@ var WebCall = (() => {
3643
3696
  // Password
3644
3697
  password: "",
3645
3698
  encryptionPassword: EncryptionMethod.INTERNAL,
3699
+ sourceType: CallSourceType.phoneNum,
3646
3700
  // Extension number
3647
3701
  extno: "",
3702
+ workOrderId: "",
3648
3703
  userPart: "",
3649
3704
  agentId: "",
3650
3705
  fsUserId: "",
@@ -3675,7 +3730,9 @@ var WebCall = (() => {
3675
3730
  password: "",
3676
3731
  encryptionPassword: "",
3677
3732
  userPart: "",
3733
+ sourceType: CallSourceType.phoneNum,
3678
3734
  extno: "",
3735
+ workOrderId: "",
3679
3736
  agentId: "",
3680
3737
  fsUserId: "",
3681
3738
  fsPassword: "",
@@ -3689,12 +3746,7 @@ var WebCall = (() => {
3689
3746
  }
3690
3747
  };
3691
3748
  validate = () => {
3692
- const {
3693
- userPart,
3694
- fsIp,
3695
- fsPassword,
3696
- fsPort
3697
- } = this.config.userInfo;
3749
+ const { userPart, fsIp, fsPassword, fsPort } = this.config.userInfo;
3698
3750
  if (!userPart || !fsIp || !fsPort || !fsPassword) {
3699
3751
  return false;
3700
3752
  }
@@ -18347,13 +18399,7 @@ var WebCall = (() => {
18347
18399
  this.mediaStream = await navigator.mediaDevices.getUserMedia(constrains);
18348
18400
  return this.mediaStream;
18349
18401
  };
18350
- const {
18351
- userPart,
18352
- fsIp,
18353
- fsPort,
18354
- iceInfo,
18355
- wsUrl
18356
- } = userInfo;
18402
+ const { userPart, fsIp, fsPort, iceInfo, wsUrl } = userInfo;
18357
18403
  const connectConfig = {
18358
18404
  uri: UserAgent.makeURI(`sip:${userPart}@${fsIp}:${fsPort}`),
18359
18405
  displayName: userPart,
@@ -18454,7 +18500,9 @@ var WebCall = (() => {
18454
18500
  const { request: request2 } = this.currentSession;
18455
18501
  const headerNames = Object.keys(request2.headers);
18456
18502
  const xHeaders = {};
18457
- headerNames.filter((name) => name.toLocaleLowerCase().startsWith("x-antaios")).forEach((name) => {
18503
+ headerNames.filter(
18504
+ (name) => name.toLocaleLowerCase().startsWith("x-antaios")
18505
+ ).forEach((name) => {
18458
18506
  xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
18459
18507
  });
18460
18508
  this.callKit.logger.debug("get invite data", xHeaders);
@@ -18480,9 +18528,26 @@ var WebCall = (() => {
18480
18528
  onRegister: () => {
18481
18529
  this.callKit.logger.debug("connect onRegister");
18482
18530
  }
18531
+ // onRefer: (referral) => {
18532
+ // this.callKit.trigger(KitEvent.KIT_REFER, {
18533
+ // referAccept: () => {
18534
+ // this.setConnectStatus(CallStatus.connecting);
18535
+ // referral.accept().then(() => {
18536
+ // referral.makeInviter().invite();
18537
+ // });
18538
+ // },
18539
+ // referReject: () => {
18540
+ // referral.reject();
18541
+ // this.callKit.callCenter.callEnd(true, false);
18542
+ // }
18543
+ // });
18544
+ // }
18483
18545
  };
18484
18546
  await this.userAgent.start().catch((err) => {
18485
18547
  this.callKit.callCenter.callEnd(false, true);
18548
+ this.callKit.user.sendHangUpReason({
18549
+ reason: err
18550
+ });
18486
18551
  this.callKit.logger.error(err, {
18487
18552
  errCode: ErrorCode.WEBRTC_USER_AGENT_ERROR
18488
18553
  });
@@ -18687,6 +18752,14 @@ var WebCall = (() => {
18687
18752
  }
18688
18753
  await this.setMute(false);
18689
18754
  }
18755
+ async refer(referTo, extra) {
18756
+ this.callKit.logger.debug("connect refer");
18757
+ let target;
18758
+ if (referTo) {
18759
+ target = UserAgent.makeURI(referTo);
18760
+ }
18761
+ this.currentSession.refer(target, extra?.sessionReferOptions);
18762
+ }
18690
18763
  };
18691
18764
 
18692
18765
  // package/socket.ts
@@ -18874,6 +18947,11 @@ var WebCall = (() => {
18874
18947
  if (SocketSendEvent.CALL === event) {
18875
18948
  msg.phoneNum = extno;
18876
18949
  msg.agentId = agentId;
18950
+ if (message?.sourceType === CallSourceType.phoneNum) {
18951
+ delete msg.workOrderId;
18952
+ } else if (message?.sourceType === CallSourceType.workOrderId) {
18953
+ delete msg.phoneNum;
18954
+ }
18877
18955
  }
18878
18956
  this.callKit.logger.debug("socket send", msg);
18879
18957
  switch (event) {
@@ -19014,6 +19092,22 @@ var WebCall = (() => {
19014
19092
  });
19015
19093
  });
19016
19094
  }
19095
+ async sendHangUpReason(data) {
19096
+ try {
19097
+ const { reason = "" } = data;
19098
+ const { userInfo } = this.callKit.config.getConfig();
19099
+ const { username } = userInfo;
19100
+ const reasonData = {
19101
+ username,
19102
+ userInfo,
19103
+ reason
19104
+ };
19105
+ const reasonStr = JSON.stringify(reasonData);
19106
+ this.callKit.socket.send(SocketSendEvent.CALL, reasonStr);
19107
+ } catch (error) {
19108
+ this.callKit.logger.debug(error);
19109
+ }
19110
+ }
19017
19111
  };
19018
19112
 
19019
19113
  // package/index.ts
@@ -19120,19 +19214,36 @@ var WebCall = (() => {
19120
19214
  this.config.reset();
19121
19215
  this.trigger(KitEvent.KIT_LOGIN_CHANGE, false);
19122
19216
  }
19123
- async call(extno) {
19217
+ async call(extno = "", options = {
19218
+ sourceType: CallSourceType.phoneNum,
19219
+ workOrderId: ""
19220
+ }) {
19124
19221
  if (!this.config.check())
19125
19222
  return;
19126
19223
  if (!this.connect.isRegistered()) {
19127
19224
  this.logger.warn("Currently not registered");
19128
19225
  return;
19129
19226
  }
19130
- if (extno) {
19131
- this.config.setUserInfo("extno", extno);
19227
+ const { sourceType, workOrderId } = options;
19228
+ this.config.setUserInfo("sourceType", sourceType);
19229
+ if (sourceType === CallSourceType.phoneNum) {
19230
+ if (extno) {
19231
+ this.config.setUserInfo("extno", extno);
19232
+ }
19233
+ } else if (sourceType === CallSourceType.workOrderId) {
19234
+ if (workOrderId) {
19235
+ this.config.setUserInfo("workOrderId", workOrderId);
19236
+ }
19132
19237
  }
19133
19238
  this.logger.debug("call");
19134
19239
  this.callCenter.callStart();
19135
19240
  }
19241
+ async refer(uri, options) {
19242
+ if (!this.config.check())
19243
+ return;
19244
+ this.logger.debug("refer");
19245
+ this.callCenter.callRefer(uri, options);
19246
+ }
19136
19247
  async register() {
19137
19248
  if (!this.config.check())
19138
19249
  return;