@koi-design/callkit 2.0.0-beta.4 → 2.0.0-beta.6
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 +5 -3
- package/dist/index.global.js +102 -45
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +104 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.ts
CHANGED
|
@@ -142,7 +142,8 @@ declare const KitEvent: {
|
|
|
142
142
|
* User status change
|
|
143
143
|
*/
|
|
144
144
|
USER_STATUS_CHANGE: string;
|
|
145
|
-
|
|
145
|
+
INCALL_CONNECT_EVENT: string;
|
|
146
|
+
SIP_CONNECT_EVENT: string;
|
|
146
147
|
SIP_REGISTERER_EVENT: string;
|
|
147
148
|
SIP_SESSION_EVENT: string;
|
|
148
149
|
};
|
|
@@ -255,6 +256,7 @@ declare class Socket {
|
|
|
255
256
|
private reconnectTimer?;
|
|
256
257
|
private isReconnecting;
|
|
257
258
|
private reconnectAttempts;
|
|
259
|
+
private socketError;
|
|
258
260
|
constructor(callKit: CallKit);
|
|
259
261
|
init(): void;
|
|
260
262
|
private handleDisconnect;
|
|
@@ -270,8 +272,7 @@ declare class Socket {
|
|
|
270
272
|
private ping;
|
|
271
273
|
private checkPing;
|
|
272
274
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @param isWaitConfirm Whether need to wait for close confirmation
|
|
275
|
+
* reset socket connection and all states
|
|
275
276
|
*/
|
|
276
277
|
reset(): Promise<void>;
|
|
277
278
|
private attemptReconnect;
|
|
@@ -404,6 +405,7 @@ declare class Connect {
|
|
|
404
405
|
clearObserveOptionsHeartbeatInterval(): void;
|
|
405
406
|
heartbeatFlag: number;
|
|
406
407
|
startHeartbeat(): void;
|
|
408
|
+
socketTriggerHangup(callId: string): void;
|
|
407
409
|
register(): Promise<void>;
|
|
408
410
|
private reconnectTimer?;
|
|
409
411
|
private reconnectAttempts;
|
package/dist/index.global.js
CHANGED
|
@@ -3408,7 +3408,8 @@ var WebCall = (() => {
|
|
|
3408
3408
|
* User status change
|
|
3409
3409
|
*/
|
|
3410
3410
|
USER_STATUS_CHANGE: "userStatusChange",
|
|
3411
|
-
|
|
3411
|
+
INCALL_CONNECT_EVENT: "IncallConnectEvent",
|
|
3412
|
+
SIP_CONNECT_EVENT: "sipConnectEvent",
|
|
3412
3413
|
SIP_REGISTERER_EVENT: "sipRegistererEvent",
|
|
3413
3414
|
SIP_SESSION_EVENT: "sipSessionEvent"
|
|
3414
3415
|
};
|
|
@@ -3733,7 +3734,7 @@ var WebCall = (() => {
|
|
|
3733
3734
|
});
|
|
3734
3735
|
return;
|
|
3735
3736
|
}
|
|
3736
|
-
this.callKit.connect.setHold(
|
|
3737
|
+
this.callKit.connect.setHold(false);
|
|
3737
3738
|
}
|
|
3738
3739
|
async callMute() {
|
|
3739
3740
|
if (!this.callKit.config.check())
|
|
@@ -18401,6 +18402,21 @@ var WebCall = (() => {
|
|
|
18401
18402
|
}
|
|
18402
18403
|
};
|
|
18403
18404
|
|
|
18405
|
+
// package/utils.ts
|
|
18406
|
+
var formatGetInviteData = (inviteData) => {
|
|
18407
|
+
const extendInfoStr = inviteData["x-antaios-manual-extend_info"] || inviteData["x-antaios-manual-extend-info"];
|
|
18408
|
+
let extendInfoObj = null;
|
|
18409
|
+
try {
|
|
18410
|
+
if (extendInfoStr && typeof extendInfoStr === "string") {
|
|
18411
|
+
const cleanedStr = extendInfoStr.replace(/\\/g, "");
|
|
18412
|
+
extendInfoObj = JSON.parse(cleanedStr);
|
|
18413
|
+
return extendInfoObj;
|
|
18414
|
+
}
|
|
18415
|
+
} catch (error) {
|
|
18416
|
+
return {};
|
|
18417
|
+
}
|
|
18418
|
+
};
|
|
18419
|
+
|
|
18404
18420
|
// package/connect.ts
|
|
18405
18421
|
var DEFAULT_RECONNECT_CONFIG = {
|
|
18406
18422
|
maxAttempts: 3,
|
|
@@ -18490,7 +18506,7 @@ var WebCall = (() => {
|
|
|
18490
18506
|
if (this.connectStatus !== CallStatus.init) {
|
|
18491
18507
|
this.setConnectStatus(CallStatus.init);
|
|
18492
18508
|
}
|
|
18493
|
-
if (this.isRegistered) {
|
|
18509
|
+
if (this.isRegistered()) {
|
|
18494
18510
|
this.unregister();
|
|
18495
18511
|
}
|
|
18496
18512
|
this.currentSession = void 0;
|
|
@@ -18499,6 +18515,7 @@ var WebCall = (() => {
|
|
|
18499
18515
|
this.registerer = void 0;
|
|
18500
18516
|
this.isOutgoing = false;
|
|
18501
18517
|
this.isUnprompted = false;
|
|
18518
|
+
this.currentCallId = void 0;
|
|
18502
18519
|
if (this.mediaStream) {
|
|
18503
18520
|
try {
|
|
18504
18521
|
closeStream(this.mediaStream);
|
|
@@ -18594,12 +18611,24 @@ var WebCall = (() => {
|
|
|
18594
18611
|
this.heartbeatFlag -= 1;
|
|
18595
18612
|
if (this.heartbeatFlag <= 0) {
|
|
18596
18613
|
this.heartbeatFlag = MAX_HEARTBEAT_COUNT;
|
|
18597
|
-
this.callKit.trigger(KitEvent.
|
|
18614
|
+
this.callKit.trigger(KitEvent.SIP_CONNECT_EVENT, {
|
|
18598
18615
|
event: "OPTIONS_HEARTBEAT_EXPIRED"
|
|
18599
18616
|
});
|
|
18600
18617
|
}
|
|
18601
18618
|
}, 1e3);
|
|
18602
18619
|
}
|
|
18620
|
+
socketTriggerHangup(callId) {
|
|
18621
|
+
if (!this.isCalling() || callId !== this.currentCallId)
|
|
18622
|
+
return;
|
|
18623
|
+
this.callKit.logger.info("socketHangup trigger hangup", {
|
|
18624
|
+
caller: "Connect.socketHangup",
|
|
18625
|
+
content: {
|
|
18626
|
+
callId,
|
|
18627
|
+
currentCallId: this.currentCallId
|
|
18628
|
+
}
|
|
18629
|
+
});
|
|
18630
|
+
this.callKit.hangup();
|
|
18631
|
+
}
|
|
18603
18632
|
async register() {
|
|
18604
18633
|
if (this.connectStatus !== CallStatus.init) {
|
|
18605
18634
|
if (this.isRegistered()) {
|
|
@@ -18758,6 +18787,10 @@ var WebCall = (() => {
|
|
|
18758
18787
|
}
|
|
18759
18788
|
});
|
|
18760
18789
|
this.setRegister(true);
|
|
18790
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18791
|
+
registererState: state,
|
|
18792
|
+
isRegistered: this.isRegistered()
|
|
18793
|
+
});
|
|
18761
18794
|
break;
|
|
18762
18795
|
case RegistererState.Terminated:
|
|
18763
18796
|
this.callKit.logger.info("registerer stateChange Terminated", {
|
|
@@ -18770,6 +18803,10 @@ var WebCall = (() => {
|
|
|
18770
18803
|
});
|
|
18771
18804
|
this.setRegister(false);
|
|
18772
18805
|
this.setConnectStatus(CallStatus.init);
|
|
18806
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18807
|
+
registererState: state,
|
|
18808
|
+
isRegistered: this.isRegistered()
|
|
18809
|
+
});
|
|
18773
18810
|
break;
|
|
18774
18811
|
case RegistererState.Unregistered:
|
|
18775
18812
|
this.callKit.logger.info("registerer stateChange Unregistered", {
|
|
@@ -18782,6 +18819,10 @@ var WebCall = (() => {
|
|
|
18782
18819
|
});
|
|
18783
18820
|
this.setRegister(false);
|
|
18784
18821
|
this.setConnectStatus(CallStatus.init);
|
|
18822
|
+
this.callKit.trigger(KitEvent.SIP_REGISTERER_EVENT, {
|
|
18823
|
+
registererState: state,
|
|
18824
|
+
isRegistered: this.isRegistered()
|
|
18825
|
+
});
|
|
18785
18826
|
break;
|
|
18786
18827
|
default:
|
|
18787
18828
|
break;
|
|
@@ -18869,25 +18910,40 @@ var WebCall = (() => {
|
|
|
18869
18910
|
alwaysAcquireMediaFirst: true
|
|
18870
18911
|
}
|
|
18871
18912
|
};
|
|
18913
|
+
const getInviteData = () => {
|
|
18914
|
+
const { request: request2 } = this.currentSession;
|
|
18915
|
+
const headerNames = Object.keys(request2.headers);
|
|
18916
|
+
const xHeaders = {};
|
|
18917
|
+
headerNames.filter((name) => name.toLocaleLowerCase().startsWith("x-antaios")).forEach((name) => {
|
|
18918
|
+
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
18919
|
+
});
|
|
18920
|
+
this.callKit.logger.info("get invite data", {
|
|
18921
|
+
caller: "Connect.register.onInvite",
|
|
18922
|
+
content: xHeaders
|
|
18923
|
+
});
|
|
18924
|
+
return xHeaders;
|
|
18925
|
+
};
|
|
18926
|
+
const info = getInviteData();
|
|
18927
|
+
try {
|
|
18928
|
+
const inviteData = formatGetInviteData(info);
|
|
18929
|
+
this.currentCallId = inviteData?.callUuid;
|
|
18930
|
+
this.callKit.logger.info("get invite data", {
|
|
18931
|
+
caller: "Connect.register.onInvite",
|
|
18932
|
+
content: {
|
|
18933
|
+
inviteData,
|
|
18934
|
+
currentCallId: this.currentCallId
|
|
18935
|
+
}
|
|
18936
|
+
});
|
|
18937
|
+
} catch (error) {
|
|
18938
|
+
this.callKit.logger.info(error, {
|
|
18939
|
+
caller: "Connect.register.onInvite",
|
|
18940
|
+
content: info
|
|
18941
|
+
});
|
|
18942
|
+
}
|
|
18872
18943
|
if (this.isOutgoing) {
|
|
18873
18944
|
this.currentSession.accept(options);
|
|
18874
|
-
this.setConnectStatus(CallStatus.connecting);
|
|
18875
18945
|
this.callKit.trigger(KitEvent.KIT_OUTGOING_INVITE, {
|
|
18876
|
-
getInviteData
|
|
18877
|
-
const { request: request2 } = this.currentSession;
|
|
18878
|
-
const headerNames = Object.keys(request2.headers);
|
|
18879
|
-
const xHeaders = {};
|
|
18880
|
-
headerNames.filter(
|
|
18881
|
-
(name) => name.toLocaleLowerCase().startsWith("x-antaios")
|
|
18882
|
-
).forEach((name) => {
|
|
18883
|
-
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
18884
|
-
});
|
|
18885
|
-
this.callKit.logger.info("get invite data", {
|
|
18886
|
-
caller: "Connect.register.onInvite",
|
|
18887
|
-
content: xHeaders
|
|
18888
|
-
});
|
|
18889
|
-
return xHeaders;
|
|
18890
|
-
}
|
|
18946
|
+
getInviteData
|
|
18891
18947
|
});
|
|
18892
18948
|
} else {
|
|
18893
18949
|
const reject = () => {
|
|
@@ -18901,21 +18957,7 @@ var WebCall = (() => {
|
|
|
18901
18957
|
this.currentSession.accept(options);
|
|
18902
18958
|
},
|
|
18903
18959
|
reject,
|
|
18904
|
-
getInviteData
|
|
18905
|
-
const { request: request2 } = this.currentSession;
|
|
18906
|
-
const headerNames = Object.keys(request2.headers);
|
|
18907
|
-
const xHeaders = {};
|
|
18908
|
-
headerNames.filter(
|
|
18909
|
-
(name) => name.toLocaleLowerCase().startsWith("x-antaios")
|
|
18910
|
-
).forEach((name) => {
|
|
18911
|
-
xHeaders[name.toLocaleLowerCase()] = request2.getHeader(name);
|
|
18912
|
-
});
|
|
18913
|
-
this.callKit.logger.info("get invite data", {
|
|
18914
|
-
caller: "Connect.register",
|
|
18915
|
-
content: xHeaders
|
|
18916
|
-
});
|
|
18917
|
-
return xHeaders;
|
|
18918
|
-
}
|
|
18960
|
+
getInviteData
|
|
18919
18961
|
});
|
|
18920
18962
|
}
|
|
18921
18963
|
},
|
|
@@ -19352,7 +19394,7 @@ var WebCall = (() => {
|
|
|
19352
19394
|
// package/socket.ts
|
|
19353
19395
|
var RECONNECT_CONFIG = {
|
|
19354
19396
|
enabled: true,
|
|
19355
|
-
maxAttempts:
|
|
19397
|
+
maxAttempts: 3,
|
|
19356
19398
|
delay: 500,
|
|
19357
19399
|
backoffMultiplier: 1.5,
|
|
19358
19400
|
pingInterval: 3e4,
|
|
@@ -19370,6 +19412,7 @@ var WebCall = (() => {
|
|
|
19370
19412
|
reconnectTimer;
|
|
19371
19413
|
isReconnecting = false;
|
|
19372
19414
|
reconnectAttempts = 0;
|
|
19415
|
+
socketError = false;
|
|
19373
19416
|
constructor(callKit) {
|
|
19374
19417
|
this.callKit = callKit;
|
|
19375
19418
|
const { reconnect } = this.callKit.config.getConfig();
|
|
@@ -19393,7 +19436,7 @@ var WebCall = (() => {
|
|
|
19393
19436
|
this.isConnected = false;
|
|
19394
19437
|
if (!this.callKit.config.isLogin() || !this.socketConfig.enabled) {
|
|
19395
19438
|
this.reset();
|
|
19396
|
-
this.callKit.trigger(KitEvent.
|
|
19439
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19397
19440
|
event: "INCALL_NOT_CONNECTED"
|
|
19398
19441
|
});
|
|
19399
19442
|
return;
|
|
@@ -19413,6 +19456,7 @@ var WebCall = (() => {
|
|
|
19413
19456
|
type: "INCALL",
|
|
19414
19457
|
content: { ev }
|
|
19415
19458
|
});
|
|
19459
|
+
this.socketError = false;
|
|
19416
19460
|
this.isConnected = true;
|
|
19417
19461
|
this.lastPingTime = Date.now();
|
|
19418
19462
|
this.checkPing();
|
|
@@ -19425,7 +19469,7 @@ var WebCall = (() => {
|
|
|
19425
19469
|
reconnectAttempts: this.reconnectAttempts
|
|
19426
19470
|
}
|
|
19427
19471
|
});
|
|
19428
|
-
this.callKit.trigger(KitEvent.
|
|
19472
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19429
19473
|
event: "INCALL_RECONNECT_SUCCESS"
|
|
19430
19474
|
});
|
|
19431
19475
|
}
|
|
@@ -19445,10 +19489,13 @@ var WebCall = (() => {
|
|
|
19445
19489
|
type: "INCALL",
|
|
19446
19490
|
content: { ev }
|
|
19447
19491
|
});
|
|
19448
|
-
this.callKit.trigger(KitEvent.
|
|
19492
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19449
19493
|
event: "INCALL_CONNECT_ERROR",
|
|
19450
19494
|
err: ev
|
|
19451
19495
|
});
|
|
19496
|
+
if (this.socketError) {
|
|
19497
|
+
return;
|
|
19498
|
+
}
|
|
19452
19499
|
this.handleDisconnect();
|
|
19453
19500
|
}
|
|
19454
19501
|
onError(ev) {
|
|
@@ -19460,6 +19507,7 @@ var WebCall = (() => {
|
|
|
19460
19507
|
data: ev
|
|
19461
19508
|
}
|
|
19462
19509
|
});
|
|
19510
|
+
this.socketError = true;
|
|
19463
19511
|
}
|
|
19464
19512
|
confirmAck(data) {
|
|
19465
19513
|
const { ack, messageId } = data;
|
|
@@ -19550,6 +19598,9 @@ var WebCall = (() => {
|
|
|
19550
19598
|
}
|
|
19551
19599
|
});
|
|
19552
19600
|
this.callKit.trigger(KitEvent.CALL_HANG_UP, /* @__PURE__ */ new Date());
|
|
19601
|
+
if (data.data?.callUuid) {
|
|
19602
|
+
this.callKit.connect.socketTriggerHangup(data.data.callUuid);
|
|
19603
|
+
}
|
|
19553
19604
|
}
|
|
19554
19605
|
if (data.event === SocketReceiveEvent.CUSTOMER_NO_ANSWER) {
|
|
19555
19606
|
this.callKit.logger.info(data.msg, {
|
|
@@ -19561,6 +19612,9 @@ var WebCall = (() => {
|
|
|
19561
19612
|
}
|
|
19562
19613
|
});
|
|
19563
19614
|
this.callKit.trigger(KitEvent.CALL_NO_ANSWER);
|
|
19615
|
+
if (data.data?.callUuid) {
|
|
19616
|
+
this.callKit.connect.socketTriggerHangup(data.data.callUuid);
|
|
19617
|
+
}
|
|
19564
19618
|
}
|
|
19565
19619
|
if (data.event === SocketReceiveEvent.CALL_CDR) {
|
|
19566
19620
|
this.callKit.logger.info(data.msg, {
|
|
@@ -19612,12 +19666,15 @@ var WebCall = (() => {
|
|
|
19612
19666
|
event: SocketReceiveEvent.AGENT_NO_ANSWER
|
|
19613
19667
|
}
|
|
19614
19668
|
});
|
|
19669
|
+
if (data.data?.callUuid) {
|
|
19670
|
+
this.callKit.connect.socketTriggerHangup(data.data.callUuid);
|
|
19671
|
+
}
|
|
19615
19672
|
}
|
|
19616
19673
|
this.callKit.trigger(KitEvent.SERVER_SOCKET_EVENT, data);
|
|
19617
19674
|
}
|
|
19618
19675
|
send(event, message) {
|
|
19619
19676
|
if (!this.isConnected) {
|
|
19620
|
-
this.callKit.trigger(KitEvent.
|
|
19677
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19621
19678
|
event: "INCALL_NOT_CONNECTED"
|
|
19622
19679
|
});
|
|
19623
19680
|
this.callKit.logger.error("socket not connected", {
|
|
@@ -19676,7 +19733,7 @@ var WebCall = (() => {
|
|
|
19676
19733
|
}
|
|
19677
19734
|
async sendMessage(event, message) {
|
|
19678
19735
|
if (!this.isConnected) {
|
|
19679
|
-
this.callKit.trigger(KitEvent.
|
|
19736
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19680
19737
|
event: "INCALL_NOT_CONNECTED"
|
|
19681
19738
|
});
|
|
19682
19739
|
this.callKit.logger.error("socket not connected", {
|
|
@@ -19730,8 +19787,7 @@ var WebCall = (() => {
|
|
|
19730
19787
|
}, this.socketConfig.pingInterval);
|
|
19731
19788
|
}
|
|
19732
19789
|
/**
|
|
19733
|
-
*
|
|
19734
|
-
* @param isWaitConfirm Whether need to wait for close confirmation
|
|
19790
|
+
* reset socket connection and all states
|
|
19735
19791
|
*/
|
|
19736
19792
|
async reset() {
|
|
19737
19793
|
if (this.pingTimer) {
|
|
@@ -19741,6 +19797,7 @@ var WebCall = (() => {
|
|
|
19741
19797
|
this.resetReconnectState();
|
|
19742
19798
|
this.lastPingTime = void 0;
|
|
19743
19799
|
this.satrtConfirm = false;
|
|
19800
|
+
this.socketError = false;
|
|
19744
19801
|
if (this.ws && this.isConnected) {
|
|
19745
19802
|
this.callKit.logger.info("Closing socket connection", {
|
|
19746
19803
|
caller: "Socket.reset",
|
|
@@ -19761,14 +19818,14 @@ var WebCall = (() => {
|
|
|
19761
19818
|
reconnectAttempts: this.reconnectAttempts
|
|
19762
19819
|
}
|
|
19763
19820
|
});
|
|
19764
|
-
this.callKit.trigger(KitEvent.
|
|
19821
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19765
19822
|
event: "INCALL_RECONNECT_ERROR"
|
|
19766
19823
|
});
|
|
19767
19824
|
this.reset();
|
|
19768
19825
|
return;
|
|
19769
19826
|
}
|
|
19770
19827
|
if (this.reconnectAttempts === 0) {
|
|
19771
|
-
this.callKit.trigger(KitEvent.
|
|
19828
|
+
this.callKit.trigger(KitEvent.INCALL_CONNECT_EVENT, {
|
|
19772
19829
|
event: "INCALL_RECONNECT_START"
|
|
19773
19830
|
});
|
|
19774
19831
|
}
|