@koi-design/callkit 2.0.0-beta.3 → 2.0.0-beta.4
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 +17 -14
- package/dist/index.global.js +153 -132
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +153 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -132
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ declare class Call {
|
|
|
39
39
|
callEnd(isUnprompted?: boolean, isError?: boolean): Promise<void>;
|
|
40
40
|
callHold(): Promise<void>;
|
|
41
41
|
callUnhold(): Promise<void>;
|
|
42
|
+
callMute(): Promise<void>;
|
|
43
|
+
callUnmute(): Promise<void>;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
declare const CallStatus: {
|
|
@@ -50,10 +52,6 @@ declare const CallStatus: {
|
|
|
50
52
|
* Connecting
|
|
51
53
|
*/
|
|
52
54
|
connecting: number;
|
|
53
|
-
/**
|
|
54
|
-
* Call on hold
|
|
55
|
-
*/
|
|
56
|
-
holding: number;
|
|
57
55
|
/**
|
|
58
56
|
* Ringing
|
|
59
57
|
*/
|
|
@@ -173,6 +171,14 @@ declare const SocketSendEvent: {
|
|
|
173
171
|
* Unhold
|
|
174
172
|
*/
|
|
175
173
|
UNHOLD: string;
|
|
174
|
+
/**
|
|
175
|
+
* Mute
|
|
176
|
+
*/
|
|
177
|
+
MUTE: string;
|
|
178
|
+
/**
|
|
179
|
+
* Unmute
|
|
180
|
+
*/
|
|
181
|
+
UNMUTE: string;
|
|
176
182
|
/**
|
|
177
183
|
* Call
|
|
178
184
|
*/
|
|
@@ -351,11 +357,15 @@ declare class Connect {
|
|
|
351
357
|
/**
|
|
352
358
|
* Whether muted
|
|
353
359
|
*/
|
|
354
|
-
isMute
|
|
360
|
+
private isMute;
|
|
355
361
|
/**
|
|
356
362
|
* Whether registered
|
|
357
363
|
*/
|
|
358
364
|
private isRegister;
|
|
365
|
+
/**
|
|
366
|
+
* Whether holding
|
|
367
|
+
*/
|
|
368
|
+
private isHold;
|
|
359
369
|
constructor(callKit: CallKit);
|
|
360
370
|
reset(): void;
|
|
361
371
|
private getAduioReference;
|
|
@@ -424,17 +434,8 @@ declare class Connect {
|
|
|
424
434
|
*/
|
|
425
435
|
getRemoteMediaStream(session: any): any;
|
|
426
436
|
setupRemoteMedia(session: any): void;
|
|
427
|
-
/**
|
|
428
|
-
* Update hold
|
|
429
|
-
* @param hold
|
|
430
|
-
*/
|
|
431
|
-
setHoldStatus(hold: boolean): void;
|
|
432
437
|
setHold(hold: boolean): Promise<void>;
|
|
433
|
-
hold(): Promise<void>;
|
|
434
|
-
unhold(): Promise<void>;
|
|
435
438
|
setMute(mute: boolean): Promise<void>;
|
|
436
|
-
mute(): Promise<void>;
|
|
437
|
-
unmute(): Promise<void>;
|
|
438
439
|
refer(referTo: string, extra?: any): Promise<void>;
|
|
439
440
|
}
|
|
440
441
|
|
|
@@ -477,6 +478,8 @@ declare class CallKit {
|
|
|
477
478
|
hangup(): Promise<void>;
|
|
478
479
|
hold(): void;
|
|
479
480
|
unhold(): void;
|
|
481
|
+
mute(): void;
|
|
482
|
+
unmute(): void;
|
|
480
483
|
/**
|
|
481
484
|
* set userstatus
|
|
482
485
|
* @param status
|
package/dist/index.global.js
CHANGED
|
@@ -3310,10 +3310,10 @@ var WebCall = (() => {
|
|
|
3310
3310
|
* Connecting
|
|
3311
3311
|
*/
|
|
3312
3312
|
connecting: 2,
|
|
3313
|
-
/**
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
holding: 3,
|
|
3313
|
+
// /**
|
|
3314
|
+
// * Call on hold
|
|
3315
|
+
// */
|
|
3316
|
+
// holding: 3,
|
|
3317
3317
|
/**
|
|
3318
3318
|
* Ringing
|
|
3319
3319
|
*/
|
|
@@ -3530,6 +3530,14 @@ var WebCall = (() => {
|
|
|
3530
3530
|
* Unhold
|
|
3531
3531
|
*/
|
|
3532
3532
|
UNHOLD: "AGENT_UN_HOLD",
|
|
3533
|
+
/**
|
|
3534
|
+
* Mute
|
|
3535
|
+
*/
|
|
3536
|
+
MUTE: "AGENT_MUTE",
|
|
3537
|
+
/**
|
|
3538
|
+
* Unmute
|
|
3539
|
+
*/
|
|
3540
|
+
UNMUTE: "AGENT_UN_MUTE",
|
|
3533
3541
|
/**
|
|
3534
3542
|
* Call
|
|
3535
3543
|
*/
|
|
@@ -3704,28 +3712,58 @@ var WebCall = (() => {
|
|
|
3704
3712
|
this.callKit.logger.warn("Current state cannot be held", {
|
|
3705
3713
|
caller: "Call.callHold",
|
|
3706
3714
|
content: {
|
|
3715
|
+
isHold: this.callKit.connect.isHolding(),
|
|
3707
3716
|
isCalling: this.callKit.connect.isCalling()
|
|
3708
3717
|
}
|
|
3709
3718
|
});
|
|
3710
3719
|
return;
|
|
3711
3720
|
}
|
|
3712
|
-
this.callKit.
|
|
3713
|
-
this.callKit.connect.setConnectStatus(CallStatus.holding);
|
|
3721
|
+
this.callKit.connect.setHold(true);
|
|
3714
3722
|
}
|
|
3715
3723
|
async callUnhold() {
|
|
3716
3724
|
if (!this.callKit.config.check())
|
|
3717
3725
|
return;
|
|
3718
|
-
if (!this.callKit.connect.
|
|
3726
|
+
if (!this.callKit.connect.isCalling()) {
|
|
3719
3727
|
this.callKit.logger.warn("Current state cannot unhold", {
|
|
3720
3728
|
caller: "Call.callUnhold",
|
|
3721
3729
|
content: {
|
|
3722
|
-
|
|
3730
|
+
isHold: this.callKit.connect.isHolding(),
|
|
3731
|
+
isCalling: this.callKit.connect.isCalling()
|
|
3732
|
+
}
|
|
3733
|
+
});
|
|
3734
|
+
return;
|
|
3735
|
+
}
|
|
3736
|
+
this.callKit.connect.setHold(true);
|
|
3737
|
+
}
|
|
3738
|
+
async callMute() {
|
|
3739
|
+
if (!this.callKit.config.check())
|
|
3740
|
+
return;
|
|
3741
|
+
if (!this.callKit.connect.isCalling()) {
|
|
3742
|
+
this.callKit.logger.warn("Current state cannot be muted", {
|
|
3743
|
+
caller: "Call.callMute",
|
|
3744
|
+
content: {
|
|
3745
|
+
isMuted: this.callKit.connect.isMuted(),
|
|
3746
|
+
isCalling: this.callKit.connect.isCalling()
|
|
3747
|
+
}
|
|
3748
|
+
});
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
this.callKit.connect.setMute(true);
|
|
3752
|
+
}
|
|
3753
|
+
async callUnmute() {
|
|
3754
|
+
if (!this.callKit.config.check())
|
|
3755
|
+
return;
|
|
3756
|
+
if (!this.callKit.connect.isCalling()) {
|
|
3757
|
+
this.callKit.logger.warn("Current state cannot be unmuted", {
|
|
3758
|
+
caller: "Call.callUnmute",
|
|
3759
|
+
content: {
|
|
3760
|
+
isMuted: this.callKit.connect.isMuted(),
|
|
3761
|
+
isCalling: this.callKit.connect.isCalling()
|
|
3723
3762
|
}
|
|
3724
3763
|
});
|
|
3725
3764
|
return;
|
|
3726
3765
|
}
|
|
3727
|
-
this.callKit.
|
|
3728
|
-
this.callKit.connect.setConnectStatus(CallStatus.calling);
|
|
3766
|
+
this.callKit.connect.setMute(false);
|
|
3729
3767
|
}
|
|
3730
3768
|
};
|
|
3731
3769
|
|
|
@@ -18433,6 +18471,10 @@ var WebCall = (() => {
|
|
|
18433
18471
|
* Whether registered
|
|
18434
18472
|
*/
|
|
18435
18473
|
isRegister = false;
|
|
18474
|
+
/**
|
|
18475
|
+
* Whether holding
|
|
18476
|
+
*/
|
|
18477
|
+
isHold = false;
|
|
18436
18478
|
constructor(callKit) {
|
|
18437
18479
|
this.callKit = callKit;
|
|
18438
18480
|
const { reconnect = {} } = this.callKit.config.getConfig();
|
|
@@ -18443,7 +18485,7 @@ var WebCall = (() => {
|
|
|
18443
18485
|
}
|
|
18444
18486
|
reset() {
|
|
18445
18487
|
if (this.isHolding()) {
|
|
18446
|
-
this.
|
|
18488
|
+
this.setHold(false);
|
|
18447
18489
|
}
|
|
18448
18490
|
if (this.connectStatus !== CallStatus.init) {
|
|
18449
18491
|
this.setConnectStatus(CallStatus.init);
|
|
@@ -18518,7 +18560,7 @@ var WebCall = (() => {
|
|
|
18518
18560
|
* isHolding
|
|
18519
18561
|
*/
|
|
18520
18562
|
isHolding() {
|
|
18521
|
-
return this.
|
|
18563
|
+
return this.isHold;
|
|
18522
18564
|
}
|
|
18523
18565
|
/**
|
|
18524
18566
|
* isRegistered
|
|
@@ -18716,10 +18758,6 @@ var WebCall = (() => {
|
|
|
18716
18758
|
}
|
|
18717
18759
|
});
|
|
18718
18760
|
this.setRegister(true);
|
|
18719
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18720
|
-
registererState: state,
|
|
18721
|
-
isRegistered: this.isRegistered()
|
|
18722
|
-
});
|
|
18723
18761
|
break;
|
|
18724
18762
|
case RegistererState.Terminated:
|
|
18725
18763
|
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
@@ -18732,10 +18770,6 @@ var WebCall = (() => {
|
|
|
18732
18770
|
});
|
|
18733
18771
|
this.setRegister(false);
|
|
18734
18772
|
this.setConnectStatus(CallStatus.init);
|
|
18735
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18736
|
-
isRegistered: this.isRegistered(),
|
|
18737
|
-
registererState: state
|
|
18738
|
-
});
|
|
18739
18773
|
break;
|
|
18740
18774
|
case RegistererState.Unregistered:
|
|
18741
18775
|
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
@@ -18748,10 +18782,6 @@ var WebCall = (() => {
|
|
|
18748
18782
|
});
|
|
18749
18783
|
this.setRegister(false);
|
|
18750
18784
|
this.setConnectStatus(CallStatus.init);
|
|
18751
|
-
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18752
|
-
isRegistered: this.isRegistered(),
|
|
18753
|
-
registererState: state
|
|
18754
|
-
});
|
|
18755
18785
|
break;
|
|
18756
18786
|
default:
|
|
18757
18787
|
break;
|
|
@@ -19205,133 +19235,102 @@ var WebCall = (() => {
|
|
|
19205
19235
|
});
|
|
19206
19236
|
}
|
|
19207
19237
|
}
|
|
19208
|
-
/**
|
|
19209
|
-
* Update hold
|
|
19210
|
-
* @param hold
|
|
19211
|
-
*/
|
|
19212
|
-
setHoldStatus(hold) {
|
|
19213
|
-
this.callKit.logger.info("connect setHold", {
|
|
19214
|
-
caller: "Connect.setHoldStatus",
|
|
19215
|
-
type: "SIP",
|
|
19216
|
-
content: {
|
|
19217
|
-
hold
|
|
19218
|
-
}
|
|
19219
|
-
});
|
|
19220
|
-
this.callKit.trigger(KitEvent.KIT_SET_HOLD, hold);
|
|
19221
|
-
}
|
|
19222
19238
|
async setHold(hold) {
|
|
19223
|
-
this.
|
|
19224
|
-
|
|
19225
|
-
|
|
19226
|
-
this.callKit.logger.info("connect hold", {
|
|
19227
|
-
caller: "Connect.hold",
|
|
19228
|
-
type: "SIP",
|
|
19229
|
-
content: {
|
|
19230
|
-
hold: true
|
|
19231
|
-
}
|
|
19232
|
-
});
|
|
19233
|
-
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
19234
|
-
this.callKit.logger.error("Current status is not in call", {
|
|
19235
|
-
caller: "Connect.hold",
|
|
19239
|
+
if (this.isHold === hold) {
|
|
19240
|
+
this.callKit.logger.warn("Already holding", {
|
|
19241
|
+
caller: "Connect.setHold",
|
|
19236
19242
|
type: "SIP",
|
|
19237
19243
|
content: {
|
|
19238
|
-
|
|
19244
|
+
isHold: this.isHold
|
|
19239
19245
|
}
|
|
19240
19246
|
});
|
|
19247
|
+
return;
|
|
19241
19248
|
}
|
|
19242
|
-
|
|
19243
|
-
|
|
19244
|
-
|
|
19245
|
-
|
|
19249
|
+
this.callKit.socket.send(
|
|
19250
|
+
hold ? SocketSendEvent.HOLD : SocketSendEvent.UNHOLD
|
|
19251
|
+
);
|
|
19252
|
+
this.isHold = hold;
|
|
19253
|
+
this.callKit.logger.info("connect setHold", {
|
|
19254
|
+
caller: "Connect.setHold",
|
|
19246
19255
|
type: "SIP",
|
|
19247
19256
|
content: {
|
|
19248
|
-
hold
|
|
19257
|
+
hold
|
|
19249
19258
|
}
|
|
19250
19259
|
});
|
|
19260
|
+
this.callKit.trigger(KitEvent.KIT_SET_HOLD, hold);
|
|
19251
19261
|
}
|
|
19262
|
+
// /**
|
|
19263
|
+
// * Set mute
|
|
19264
|
+
// * @param mute Whether to mute
|
|
19265
|
+
// * @deprecated just send socket event to server to mute or unmute
|
|
19266
|
+
// */
|
|
19267
|
+
// async setMute(mute: boolean) {
|
|
19268
|
+
// this.callKit.logger.info('connect setMute', {
|
|
19269
|
+
// caller: 'Connect.setMute',
|
|
19270
|
+
// type: 'SIP',
|
|
19271
|
+
// content: {
|
|
19272
|
+
// mute
|
|
19273
|
+
// }
|
|
19274
|
+
// });
|
|
19275
|
+
// if (!this.currentSession) {
|
|
19276
|
+
// this.callKit.logger.error('No active session', {
|
|
19277
|
+
// caller: 'Connect.setMute',
|
|
19278
|
+
// type: 'SIP',
|
|
19279
|
+
// content: {
|
|
19280
|
+
// errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
19281
|
+
// }
|
|
19282
|
+
// });
|
|
19283
|
+
// this.callKit.reset();
|
|
19284
|
+
// return;
|
|
19285
|
+
// }
|
|
19286
|
+
// try {
|
|
19287
|
+
// // Get SessionDescriptionHandler
|
|
19288
|
+
// const sdh = this.currentSession.sessionDescriptionHandler;
|
|
19289
|
+
// if (!sdh || !('peerConnection' in sdh)) {
|
|
19290
|
+
// throw new Error('Invalid session description handler');
|
|
19291
|
+
// }
|
|
19292
|
+
// // Get PeerConnection
|
|
19293
|
+
// const pc = (sdh as any).peerConnection as RTCPeerConnection;
|
|
19294
|
+
// // Get local audio track and set status
|
|
19295
|
+
// const audioSender = pc
|
|
19296
|
+
// .getSenders()
|
|
19297
|
+
// .find((sender) => sender.track?.kind === 'audio');
|
|
19298
|
+
// if (audioSender && audioSender.track) {
|
|
19299
|
+
// audioSender.track.enabled = !mute;
|
|
19300
|
+
// // Update status and trigger event
|
|
19301
|
+
// this.isMute = mute;
|
|
19302
|
+
// this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19303
|
+
// } else {
|
|
19304
|
+
// throw new Error('No audio track found');
|
|
19305
|
+
// }
|
|
19306
|
+
// } catch (error) {
|
|
19307
|
+
// this.callKit.logger.error('Failed to set mute state', {
|
|
19308
|
+
// caller: 'Connect.setMute',
|
|
19309
|
+
// type: 'SIP',
|
|
19310
|
+
// content: {
|
|
19311
|
+
// err: error.message,
|
|
19312
|
+
// errCode: ErrorCode.WEBRTC_MUTE_ERROR
|
|
19313
|
+
// }
|
|
19314
|
+
// });
|
|
19315
|
+
// }
|
|
19316
|
+
// }
|
|
19252
19317
|
async setMute(mute) {
|
|
19253
|
-
this.
|
|
19254
|
-
|
|
19255
|
-
type: "SIP",
|
|
19256
|
-
content: {
|
|
19257
|
-
mute
|
|
19258
|
-
}
|
|
19259
|
-
});
|
|
19260
|
-
if (!this.currentSession) {
|
|
19261
|
-
this.callKit.logger.error("No active session", {
|
|
19318
|
+
if (this.isMute === mute) {
|
|
19319
|
+
this.callKit.logger.warn("Already muted", {
|
|
19262
19320
|
caller: "Connect.setMute",
|
|
19263
19321
|
type: "SIP",
|
|
19264
19322
|
content: {
|
|
19265
|
-
|
|
19266
|
-
|
|
19267
|
-
});
|
|
19268
|
-
this.callKit.reset();
|
|
19269
|
-
return;
|
|
19270
|
-
}
|
|
19271
|
-
try {
|
|
19272
|
-
const sdh = this.currentSession.sessionDescriptionHandler;
|
|
19273
|
-
if (!sdh || !("peerConnection" in sdh)) {
|
|
19274
|
-
throw new Error("Invalid session description handler");
|
|
19275
|
-
}
|
|
19276
|
-
const pc = sdh.peerConnection;
|
|
19277
|
-
const audioSender = pc.getSenders().find((sender) => sender.track?.kind === "audio");
|
|
19278
|
-
if (audioSender && audioSender.track) {
|
|
19279
|
-
audioSender.track.enabled = !mute;
|
|
19280
|
-
this.isMute = mute;
|
|
19281
|
-
this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19282
|
-
} else {
|
|
19283
|
-
throw new Error("No audio track found");
|
|
19284
|
-
}
|
|
19285
|
-
} catch (error) {
|
|
19286
|
-
this.callKit.logger.error("Failed to set mute state", {
|
|
19287
|
-
caller: "Connect.setMute",
|
|
19288
|
-
type: "SIP",
|
|
19289
|
-
content: {
|
|
19290
|
-
err: error.message,
|
|
19291
|
-
errCode: ErrorCode.WEBRTC_MUTE_ERROR
|
|
19292
|
-
}
|
|
19293
|
-
});
|
|
19294
|
-
}
|
|
19295
|
-
}
|
|
19296
|
-
async mute() {
|
|
19297
|
-
this.callKit.logger.info("connect mute", {
|
|
19298
|
-
caller: "Connect.mute",
|
|
19299
|
-
type: "SIP",
|
|
19300
|
-
content: {
|
|
19301
|
-
mute: true
|
|
19302
|
-
}
|
|
19303
|
-
});
|
|
19304
|
-
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
19305
|
-
this.callKit.logger.warn("Current status is not in call", {
|
|
19306
|
-
caller: "Connect.mute",
|
|
19307
|
-
type: "SIP",
|
|
19308
|
-
content: {
|
|
19309
|
-
errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
19323
|
+
isCalling: this.isCalling(),
|
|
19324
|
+
isMuted: this.isMuted()
|
|
19310
19325
|
}
|
|
19311
19326
|
});
|
|
19312
19327
|
return;
|
|
19313
19328
|
}
|
|
19314
|
-
|
|
19315
|
-
|
|
19316
|
-
|
|
19317
|
-
this.
|
|
19318
|
-
|
|
19319
|
-
type: "SIP",
|
|
19320
|
-
content: {
|
|
19321
|
-
mute: false
|
|
19322
|
-
}
|
|
19323
|
-
});
|
|
19324
|
-
if (this.connectStatus !== CallStatus.calling || !this.currentSession) {
|
|
19325
|
-
this.callKit.logger.warn("Current status is not in call", {
|
|
19326
|
-
caller: "Connect.unmute",
|
|
19327
|
-
type: "SIP",
|
|
19328
|
-
content: {
|
|
19329
|
-
errCode: ErrorCode.WEBRTC_MUTE_STATUS_ERROR
|
|
19330
|
-
}
|
|
19331
|
-
});
|
|
19332
|
-
return;
|
|
19333
|
-
}
|
|
19334
|
-
await this.setMute(false);
|
|
19329
|
+
this.callKit.socket.send(
|
|
19330
|
+
mute ? SocketSendEvent.MUTE : SocketSendEvent.UNMUTE
|
|
19331
|
+
);
|
|
19332
|
+
this.isMute = mute;
|
|
19333
|
+
this.callKit.trigger(KitEvent.KIT_SET_MUTE, mute);
|
|
19335
19334
|
}
|
|
19336
19335
|
async refer(referTo, extra) {
|
|
19337
19336
|
this.callKit.logger.info("connect refer", {
|
|
@@ -20031,6 +20030,28 @@ var WebCall = (() => {
|
|
|
20031
20030
|
});
|
|
20032
20031
|
this.callCenter.callUnhold();
|
|
20033
20032
|
}
|
|
20033
|
+
mute() {
|
|
20034
|
+
if (!this.config.check())
|
|
20035
|
+
return;
|
|
20036
|
+
this.logger.info("mute", {
|
|
20037
|
+
caller: "CallKit.mute",
|
|
20038
|
+
content: {
|
|
20039
|
+
connectStatus: this.connect.connectStatus
|
|
20040
|
+
}
|
|
20041
|
+
});
|
|
20042
|
+
this.callCenter.callMute();
|
|
20043
|
+
}
|
|
20044
|
+
unmute() {
|
|
20045
|
+
if (!this.config.check())
|
|
20046
|
+
return;
|
|
20047
|
+
this.logger.info("unmute", {
|
|
20048
|
+
caller: "CallKit.unmute",
|
|
20049
|
+
content: {
|
|
20050
|
+
connectStatus: this.connect.connectStatus
|
|
20051
|
+
}
|
|
20052
|
+
});
|
|
20053
|
+
this.callCenter.callUnmute();
|
|
20054
|
+
}
|
|
20034
20055
|
/**
|
|
20035
20056
|
* set userstatus
|
|
20036
20057
|
* @param status
|