@koi-design/callkit 2.0.0-beta.12 → 2.0.0-beta.15

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
@@ -189,6 +189,10 @@ declare const KitEvent: {
189
189
  * Mute status change
190
190
  */
191
191
  KIT_SET_MUTE: string;
192
+ /**
193
+ * Call id change
194
+ */
195
+ KIT_CALL_ID_CHANGE: string;
192
196
  /**
193
197
  * Error
194
198
  */
@@ -346,42 +350,49 @@ type CallStatusType = (typeof CallStatus)[keyof typeof CallStatus];
346
350
  declare class Connect {
347
351
  callKit: CallKit;
348
352
  /**
349
- * connectStatus: init registered connecting calling
353
+ *@description Reconnect config
354
+ */
355
+ private reconnectConfig;
356
+ /**
357
+ *@description Whether muted
358
+ */
359
+ private isMute;
360
+ /**
361
+ *@description Whether registered
362
+ */
363
+ private isRegister;
364
+ /**
365
+ *@description Whether holding
366
+ */
367
+ private isHold;
368
+ /**
369
+ *@description Connect status: init registered connecting calling
350
370
  */
351
371
  connectStatus: number;
352
372
  currentSession?: Invitation;
353
373
  mediaStream?: MediaStream;
354
374
  userAgent?: UserAgent;
355
375
  registerer?: Registerer;
356
- currentCallId?: string;
357
376
  /**
358
- * Whether it's a re-connected
377
+ *@description Whether it's a re-connected
359
378
  */
360
379
  isReConnected: boolean;
361
380
  observeOptionsHeartbeatHandler: ReturnType<typeof setTimeout> | null;
362
381
  /**
363
- * Whether it's an outgoing call
382
+ *@description Whether it's an outgoing call
364
383
  */
365
384
  isOutgoing: boolean;
366
385
  /**
367
- * Whether it's an active hangup
386
+ *@description Whether it's an active hangup
368
387
  */
369
388
  isUnprompted: boolean;
370
- isCurrentSessionInvited: boolean;
371
- private reconnectConfig;
372
389
  /**
373
- * Whether muted
390
+ *@description Whether the current session is invited
374
391
  */
375
- private isMute;
376
- /**
377
- * Whether registered
378
- */
379
- private isRegister;
380
- /**
381
- * Whether holding
382
- */
383
- private isHold;
392
+ hasInvite: boolean;
384
393
  constructor(callKit: CallKit);
394
+ currentCallId: string | null;
395
+ setCallId(callId: string | null): void;
385
396
  reset(): Promise<void>;
386
397
  private getAduioReference;
387
398
  permission(): Promise<void>;
@@ -3352,6 +3352,10 @@ var WebCall = (() => {
3352
3352
  * Mute status change
3353
3353
  */
3354
3354
  KIT_SET_MUTE: "muteChange",
3355
+ /**
3356
+ * Call id change
3357
+ */
3358
+ KIT_CALL_ID_CHANGE: "callIdChange",
3355
3359
  /**
3356
3360
  * Error
3357
3361
  */
@@ -18461,43 +18465,47 @@ var WebCall = (() => {
18461
18465
  var Connect = class {
18462
18466
  callKit;
18463
18467
  /**
18464
- * connectStatus: init registered connecting calling
18468
+ *@description Reconnect config
18469
+ */
18470
+ reconnectConfig;
18471
+ /**
18472
+ *@description Whether muted
18473
+ */
18474
+ isMute = false;
18475
+ /**
18476
+ *@description Whether registered
18477
+ */
18478
+ isRegister = false;
18479
+ /**
18480
+ *@description Whether holding
18481
+ */
18482
+ isHold = false;
18483
+ /**
18484
+ *@description Connect status: init registered connecting calling
18465
18485
  */
18466
18486
  connectStatus = CallStatus.init;
18467
18487
  currentSession;
18468
18488
  mediaStream;
18469
18489
  userAgent;
18470
18490
  registerer;
18471
- // current call id for invite data
18472
- currentCallId;
18473
18491
  /**
18474
- * Whether it's a re-connected
18492
+ *@description Whether it's a re-connected
18475
18493
  */
18476
18494
  isReConnected = false;
18477
18495
  observeOptionsHeartbeatHandler = null;
18478
18496
  // sipConnected = false;
18479
18497
  /**
18480
- * Whether it's an outgoing call
18498
+ *@description Whether it's an outgoing call
18481
18499
  */
18482
18500
  isOutgoing = false;
18483
18501
  /**
18484
- * Whether it's an active hangup
18502
+ *@description Whether it's an active hangup
18485
18503
  */
18486
18504
  isUnprompted = false;
18487
- isCurrentSessionInvited = false;
18488
- reconnectConfig;
18489
- /**
18490
- * Whether muted
18491
- */
18492
- isMute = false;
18493
- /**
18494
- * Whether registered
18495
- */
18496
- isRegister = false;
18497
18505
  /**
18498
- * Whether holding
18506
+ *@description Whether the current session is invited
18499
18507
  */
18500
- isHold = false;
18508
+ hasInvite = false;
18501
18509
  constructor(callKit) {
18502
18510
  this.callKit = callKit;
18503
18511
  const { reconnect = {} } = this.callKit.config.getConfig();
@@ -18506,15 +18514,33 @@ var WebCall = (() => {
18506
18514
  ...reconnect
18507
18515
  };
18508
18516
  }
18517
+ // current call id for invite data
18518
+ currentCallId = null;
18519
+ setCallId(callId) {
18520
+ this.callKit.logger.info("setCallId", {
18521
+ caller: "Connect.setCallId",
18522
+ content: {
18523
+ callId
18524
+ }
18525
+ });
18526
+ this.currentCallId = callId;
18527
+ this.callKit.trigger(KitEvent.KIT_CALL_ID_CHANGE, callId);
18528
+ }
18509
18529
  async reset() {
18510
18530
  if (this.isHolding()) {
18511
- this.setHold(false);
18531
+ await this.setHold(false);
18532
+ }
18533
+ if (this.isMuted()) {
18534
+ await this.setMute(false);
18512
18535
  }
18513
18536
  if (this.connectStatus !== CallStatus.init) {
18514
18537
  this.setConnectStatus(CallStatus.init);
18515
18538
  }
18516
18539
  if (this.isRegistered()) {
18517
- this.unregister();
18540
+ await this.unregister();
18541
+ }
18542
+ if (this.currentCallId) {
18543
+ this.setCallId(null);
18518
18544
  }
18519
18545
  this.currentSession = void 0;
18520
18546
  this.mediaStream = void 0;
@@ -18522,7 +18548,7 @@ var WebCall = (() => {
18522
18548
  this.registerer = void 0;
18523
18549
  this.isOutgoing = false;
18524
18550
  this.isUnprompted = false;
18525
- this.currentCallId = void 0;
18551
+ this.hasInvite = false;
18526
18552
  if (this.mediaStream) {
18527
18553
  try {
18528
18554
  closeStream(this.mediaStream);
@@ -18845,9 +18871,6 @@ var WebCall = (() => {
18845
18871
  }
18846
18872
  });
18847
18873
  this.currentSession = invite;
18848
- if (this.isOutgoing) {
18849
- this.isCurrentSessionInvited = false;
18850
- }
18851
18874
  this.currentSession.stateChange.addListener((state) => {
18852
18875
  switch (state) {
18853
18876
  case SessionState2.Establishing:
@@ -18893,11 +18916,10 @@ var WebCall = (() => {
18893
18916
  sessionState: state
18894
18917
  }
18895
18918
  });
18896
- if (this.isUnprompted) {
18897
- if (this.isCurrentSessionInvited) {
18898
- this.currentSession.reject();
18899
- }
18900
- } else {
18919
+ if (this.hasInvite) {
18920
+ this.currentSession.reject();
18921
+ this.hasInvite = false;
18922
+ } else if (!this.isUnprompted) {
18901
18923
  this.callKit.callCenter.callEnd();
18902
18924
  }
18903
18925
  this.isUnprompted = false;
@@ -18932,14 +18954,9 @@ var WebCall = (() => {
18932
18954
  const info = getInviteData();
18933
18955
  try {
18934
18956
  const inviteData = formatGetInviteData(info);
18935
- this.currentCallId = inviteData?.callUuid;
18936
- this.callKit.logger.info("get invite data", {
18937
- caller: "Connect.register.onInvite",
18938
- content: {
18939
- inviteData,
18940
- currentCallId: this.currentCallId
18941
- }
18942
- });
18957
+ if (inviteData?.callUuid) {
18958
+ this.setCallId(inviteData.callUuid);
18959
+ }
18943
18960
  } catch (error) {
18944
18961
  this.callKit.logger.info(error, {
18945
18962
  caller: "Connect.register.onInvite",
@@ -18952,14 +18969,16 @@ var WebCall = (() => {
18952
18969
  getInviteData
18953
18970
  });
18954
18971
  } else {
18972
+ this.hasInvite = true;
18955
18973
  const reject = () => {
18956
18974
  this.currentSession.reject();
18975
+ this.hasInvite = false;
18957
18976
  this.callKit.callCenter.callEnd(true, false);
18958
18977
  };
18959
18978
  this.callKit.trigger(KitEvent.KIT_INVITE, {
18960
18979
  accept: () => {
18961
- this.isCurrentSessionInvited = true;
18962
18980
  this.callKit.trigger(KitEvent.CALL_CONNECTING, /* @__PURE__ */ new Date());
18981
+ this.hasInvite = false;
18963
18982
  this.currentSession.accept(options);
18964
18983
  },
18965
18984
  reject,
@@ -19178,18 +19197,22 @@ var WebCall = (() => {
19178
19197
  connectStatus: this.connectStatus
19179
19198
  }
19180
19199
  });
19181
- if (this.connectStatus === CallStatus.init)
19182
- return;
19183
19200
  this.isOutgoing = false;
19184
19201
  this.isUnprompted = isUnprompted;
19202
+ this.setHold(false);
19203
+ this.setMute(false);
19204
+ if (this.connectStatus === CallStatus.init)
19205
+ return;
19185
19206
  try {
19186
19207
  if (isUnprompted) {
19187
- const shouldSendBye = (
19188
- // this.sipConnected ||
19189
- this.isRinging() || this.isCalling() || this.isHolding()
19190
- );
19208
+ const shouldSendBye = this.isRinging() || this.isCalling();
19191
19209
  if (shouldSendBye) {
19192
- await this.currentSession?.bye();
19210
+ if (this.hasInvite) {
19211
+ this.currentSession?.reject();
19212
+ this.hasInvite = false;
19213
+ } else {
19214
+ await this.currentSession?.bye();
19215
+ }
19193
19216
  }
19194
19217
  }
19195
19218
  closeStream(this.mediaStream);
@@ -19307,61 +19330,6 @@ var WebCall = (() => {
19307
19330
  });
19308
19331
  this.callKit.trigger(KitEvent.KIT_SET_HOLD, hold);
19309
19332
  }
19310
- // /**
19311
- // * Set mute
19312
- // * @param mute Whether to mute
19313
- // * @deprecated just send socket event to server to mute or unmute
19314
- // */
19315
- // async setMute(mute: boolean) {
19316
- // this.callKit.logger.info('connect setMute', {
19317
- // caller: 'Connect.setMute',
19318
- // type: 'SIP',
19319
- // content: {
19320
- // mute
19321
- // }
19322
- // });
19323
- // if (!this.currentSession) {
19324
- // this.callKit.logger.error('No active session', {
19325
- // caller: 'Connect.setMute',
19326
- // type: 'SIP',
19327
- // content: {
19328
- // errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
19329
- // }
19330
- // });
19331
- // this.callKit.reset();
19332
- // return;
19333
- // }
19334
- // try {
19335
- // // Get SessionDescriptionHandler
19336
- // const sdh = this.currentSession.sessionDescriptionHandler;
19337
- // if (!sdh || !('peerConnection' in sdh)) {
19338
- // throw new Error('Invalid session description handler');
19339
- // }
19340
- // // Get PeerConnection
19341
- // const pc = (sdh as any).peerConnection as RTCPeerConnection;
19342
- // // Get local audio track and set status
19343
- // const audioSender = pc
19344
- // .getSenders()
19345
- // .find((sender) => sender.track?.kind === 'audio');
19346
- // if (audioSender && audioSender.track) {
19347
- // audioSender.track.enabled = !mute;
19348
- // // Update status and trigger event
19349
- // this.isMute = mute;
19350
- // this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
19351
- // } else {
19352
- // throw new Error('No audio track found');
19353
- // }
19354
- // } catch (error) {
19355
- // this.callKit.logger.error('Failed to set mute state', {
19356
- // caller: 'Connect.setMute',
19357
- // type: 'SIP',
19358
- // content: {
19359
- // err: error.message,
19360
- // errCode: ErrorCode.WEBRTC_MUTE_ERROR
19361
- // }
19362
- // });
19363
- // }
19364
- // }
19365
19333
  async setMute(mute) {
19366
19334
  if (this.isMute === mute) {
19367
19335
  this.callKit.logger.warn("Already muted", {