@koi-design/callkit 1.0.24-beta.11 → 1.0.24-beta.12
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 +6 -0
- package/dist/index.global.js +64 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +64 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +64 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -362,6 +362,11 @@ declare class Connect {
|
|
|
362
362
|
*/
|
|
363
363
|
isInit(): boolean;
|
|
364
364
|
register(): Promise<void>;
|
|
365
|
+
reconnect(params?: {
|
|
366
|
+
retryInterval: number;
|
|
367
|
+
maxRetryCount: number;
|
|
368
|
+
}): Promise<void>;
|
|
369
|
+
stop(): Promise<void>;
|
|
365
370
|
unregister(): Promise<void>;
|
|
366
371
|
call(callback: Function): Promise<void>;
|
|
367
372
|
/**
|
|
@@ -455,6 +460,7 @@ declare class CallKit {
|
|
|
455
460
|
refer(uri: string, options?: any): Promise<void>;
|
|
456
461
|
register(): Promise<void>;
|
|
457
462
|
unregister(): Promise<void>;
|
|
463
|
+
stop(): Promise<void>;
|
|
458
464
|
hangup(): Promise<void>;
|
|
459
465
|
hold(): void;
|
|
460
466
|
unhold(): void;
|
package/dist/index.global.js
CHANGED
|
@@ -3588,6 +3588,12 @@ var WebCall = (() => {
|
|
|
3588
3588
|
phoneNum: 1,
|
|
3589
3589
|
workOrderId: 2
|
|
3590
3590
|
};
|
|
3591
|
+
var ConnectEvent = {
|
|
3592
|
+
SIP_CONNECT_ERROR: "SIP_CONNECT_ERROR",
|
|
3593
|
+
SIP_RECONNECT_ERROR: "SIP_RECONNECT_ERROR",
|
|
3594
|
+
INCALL_CONNECT_ERROR: "INCALL_CONNECT_ERROR",
|
|
3595
|
+
INCALL_RECONNECT_ERROR: "INCALL_RECONNECT_ERROR"
|
|
3596
|
+
};
|
|
3591
3597
|
|
|
3592
3598
|
// package/call.ts
|
|
3593
3599
|
var Call = class {
|
|
@@ -18521,9 +18527,16 @@ var WebCall = (() => {
|
|
|
18521
18527
|
});
|
|
18522
18528
|
});
|
|
18523
18529
|
},
|
|
18524
|
-
onDisconnect: () => {
|
|
18530
|
+
onDisconnect: (error) => {
|
|
18525
18531
|
this.callKit.logger.debug("connect onDisconnect");
|
|
18526
|
-
this.
|
|
18532
|
+
if (this.isRegistered() && !(this.sipConnected || this.isRinging() || this.isCalling() || this.isHolding())) {
|
|
18533
|
+
this.reconnect();
|
|
18534
|
+
} else {
|
|
18535
|
+
this.callKit.trigger(ConnectEvent.SIP_CONNECT_ERROR, {
|
|
18536
|
+
err: error
|
|
18537
|
+
});
|
|
18538
|
+
this.callKit.callCenter.callEnd();
|
|
18539
|
+
}
|
|
18527
18540
|
},
|
|
18528
18541
|
onRegister: () => {
|
|
18529
18542
|
this.callKit.logger.debug("connect onRegister");
|
|
@@ -18553,6 +18566,46 @@ var WebCall = (() => {
|
|
|
18553
18566
|
});
|
|
18554
18567
|
});
|
|
18555
18568
|
}
|
|
18569
|
+
async reconnect(params = {
|
|
18570
|
+
retryInterval: 500,
|
|
18571
|
+
maxRetryCount: 3
|
|
18572
|
+
}) {
|
|
18573
|
+
const { retryInterval, maxRetryCount } = params;
|
|
18574
|
+
let currentRetry = 0;
|
|
18575
|
+
let reconnectTimer = null;
|
|
18576
|
+
const scheduleReconnect = async () => {
|
|
18577
|
+
if (currentRetry >= maxRetryCount) {
|
|
18578
|
+
console.error("Maximum retry attempts reached, stopping reconnection");
|
|
18579
|
+
return;
|
|
18580
|
+
}
|
|
18581
|
+
if (reconnectTimer)
|
|
18582
|
+
return;
|
|
18583
|
+
reconnectTimer = setTimeout(async () => {
|
|
18584
|
+
try {
|
|
18585
|
+
currentRetry += 1;
|
|
18586
|
+
console.log(
|
|
18587
|
+
`Attempting to reconnect SIP... (Attempt ${currentRetry}/${maxRetryCount})`
|
|
18588
|
+
);
|
|
18589
|
+
await this.userAgent.start();
|
|
18590
|
+
console.log("Reconnection successful");
|
|
18591
|
+
reconnectTimer = null;
|
|
18592
|
+
} catch (err) {
|
|
18593
|
+
console.error("Reconnection failed:", err);
|
|
18594
|
+
reconnectTimer = null;
|
|
18595
|
+
if (currentRetry < maxRetryCount) {
|
|
18596
|
+
await scheduleReconnect();
|
|
18597
|
+
} else {
|
|
18598
|
+
this.callKit.trigger(ConnectEvent.SIP_RECONNECT_ERROR, {});
|
|
18599
|
+
this.callKit.logger.error("No registerer to unregister.");
|
|
18600
|
+
}
|
|
18601
|
+
}
|
|
18602
|
+
}, retryInterval);
|
|
18603
|
+
};
|
|
18604
|
+
await scheduleReconnect();
|
|
18605
|
+
}
|
|
18606
|
+
async stop() {
|
|
18607
|
+
await this.userAgent.stop();
|
|
18608
|
+
}
|
|
18556
18609
|
async unregister() {
|
|
18557
18610
|
this.callKit.logger.debug("connect unregister");
|
|
18558
18611
|
if (!this.isRegistered() || !this.registerer) {
|
|
@@ -18808,6 +18861,9 @@ var WebCall = (() => {
|
|
|
18808
18861
|
);
|
|
18809
18862
|
this.attemptReconnect();
|
|
18810
18863
|
} else if (this.reconnectAttempts >= this.socketConfig.maxAttempts) {
|
|
18864
|
+
this.callKit.trigger(ConnectEvent.INCALL_RECONNECT_ERROR, {
|
|
18865
|
+
err: ev
|
|
18866
|
+
});
|
|
18811
18867
|
this.reset();
|
|
18812
18868
|
this.callKit.logger.error(
|
|
18813
18869
|
"Reconnection failed, maximum retry attempts reached",
|
|
@@ -18837,6 +18893,9 @@ var WebCall = (() => {
|
|
|
18837
18893
|
onClose(ev) {
|
|
18838
18894
|
this.callKit.logger.debug("socket onClose", ev);
|
|
18839
18895
|
if ((ev.code !== 1e3 || !ev.wasClean) && this.callKit.connect.isRegistered()) {
|
|
18896
|
+
this.callKit.trigger(ConnectEvent.INCALL_CONNECT_ERROR, {
|
|
18897
|
+
err: ev
|
|
18898
|
+
});
|
|
18840
18899
|
this.reconnect(ev);
|
|
18841
18900
|
} else {
|
|
18842
18901
|
this.isConnected = false;
|
|
@@ -19271,6 +19330,9 @@ var WebCall = (() => {
|
|
|
19271
19330
|
this.connect.unregister();
|
|
19272
19331
|
await this.user.setUserStatus(UserStatus.offline);
|
|
19273
19332
|
}
|
|
19333
|
+
async stop() {
|
|
19334
|
+
await this.connect.stop();
|
|
19335
|
+
}
|
|
19274
19336
|
async hangup() {
|
|
19275
19337
|
if (!this.config.check())
|
|
19276
19338
|
return;
|