@koi-design/callkit 2.0.5 → 2.1.0-beta.1
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/README.md +281 -57
- package/dist/index.d.ts +65 -23
- package/dist/index.global.js +520 -396
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +520 -396
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +520 -396
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @koi-design/callkit
|
|
2
2
|
|
|
3
3
|
SIP-based Web Phone Call Toolkit
|
|
4
4
|
|
|
5
|
+
Current Version: **2.0.5-beta.2**
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
|
-
###
|
|
9
|
+
### NPM Installation
|
|
8
10
|
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @koi-design/callkit
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
###
|
|
15
|
+
### Dependencies
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
This package requires the following peer dependencies:
|
|
16
18
|
|
|
17
19
|
```json
|
|
18
20
|
{
|
|
@@ -26,30 +28,43 @@ Install the following dependencies:
|
|
|
26
28
|
|
|
27
29
|
## Quick Start
|
|
28
30
|
|
|
29
|
-
###
|
|
31
|
+
### Method 1: IIFE (Browser Global)
|
|
30
32
|
|
|
31
33
|
```html
|
|
32
|
-
<script src="callkit/index.global.js"></script>
|
|
34
|
+
<script src="koi-design/callkit/dist/index.global.js"></script>
|
|
33
35
|
<script>
|
|
34
36
|
const callKit = new WebCall.CallKit({
|
|
35
37
|
host: 'https://example.com',
|
|
36
38
|
log: 'debug',
|
|
37
39
|
audioRef: () => document.querySelector('#audioRef'),
|
|
38
|
-
socket: 'wss://example.com/ws/in-call'
|
|
40
|
+
socket: 'wss://example.com/ws/in-call'
|
|
39
41
|
});
|
|
40
42
|
</script>
|
|
41
43
|
```
|
|
42
44
|
|
|
43
|
-
### ESM Import
|
|
45
|
+
### Method 2: ESM Import
|
|
44
46
|
|
|
45
47
|
```js
|
|
46
|
-
import { CallKit } from '
|
|
48
|
+
import { CallKit } from '@koi-design/callkit';
|
|
47
49
|
|
|
48
50
|
const callKit = new CallKit({
|
|
49
51
|
host: 'https://example.com',
|
|
50
52
|
log: 'debug',
|
|
51
53
|
audioRef: () => document.querySelector('#audioRef'),
|
|
52
|
-
socket: 'wss://example.com/ws/in-call'
|
|
54
|
+
socket: 'wss://example.com/ws/in-call'
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Method 3: CommonJS Import
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const { CallKit } = require('@koi-design/callkit');
|
|
62
|
+
|
|
63
|
+
const callKit = new CallKit({
|
|
64
|
+
host: 'https://example.com',
|
|
65
|
+
log: 'debug',
|
|
66
|
+
audioRef: () => document.querySelector('#audioRef'),
|
|
67
|
+
socket: 'wss://example.com/ws/in-call'
|
|
53
68
|
});
|
|
54
69
|
```
|
|
55
70
|
|
|
@@ -72,10 +87,40 @@ interface CallKitConfig {
|
|
|
72
87
|
constrains?: WebrtcConstranis;
|
|
73
88
|
|
|
74
89
|
// Log level
|
|
75
|
-
log?: '
|
|
90
|
+
log?: 'info' | 'success' | 'warn' | 'error' | 'silent';
|
|
91
|
+
|
|
92
|
+
// Reconnection configuration
|
|
93
|
+
reconnect?: {
|
|
94
|
+
// SIP reconnection configuration
|
|
95
|
+
sip: {
|
|
96
|
+
enabled: boolean; // Enable SIP reconnection (default: true)
|
|
97
|
+
maxAttempts: number; // Maximum reconnection attempts (default: 5)
|
|
98
|
+
delay: number; // Reconnection delay in ms (default: 3000)
|
|
99
|
+
// In-call socket reconnection configuration
|
|
100
|
+
incall: {
|
|
101
|
+
enabled: boolean; // Enable in-call reconnection (default: true)
|
|
102
|
+
maxAttempts: number; // Maximum reconnection attempts (default: 5)
|
|
103
|
+
delay: number; // Reconnection delay in ms (default: 3000)
|
|
104
|
+
pingInterval: number; // Heartbeat interval in ms (default: 30000)
|
|
105
|
+
pingTimeout: number; // Heartbeat timeout in ms (default: 10000)
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Track logs configuration
|
|
110
|
+
trackLogs?: {
|
|
111
|
+
enabled: boolean; // Enable log tracking (default: false)
|
|
112
|
+
interval: number; // Log upload interval in ms (default: 10000)
|
|
113
|
+
maxSize: number; // Maximum log buffer size (default: 100)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
76
116
|
|
|
77
|
-
|
|
78
|
-
|
|
117
|
+
interface WebrtcConstranis {
|
|
118
|
+
audio: {
|
|
119
|
+
autoGainControl?: boolean;
|
|
120
|
+
noiseSuppression?: boolean;
|
|
121
|
+
echoCancellation?: boolean;
|
|
122
|
+
};
|
|
123
|
+
video: false;
|
|
79
124
|
}
|
|
80
125
|
```
|
|
81
126
|
|
|
@@ -84,13 +129,29 @@ interface CallKitConfig {
|
|
|
84
129
|
```ts
|
|
85
130
|
interface CallKit {
|
|
86
131
|
// User login
|
|
87
|
-
login(
|
|
132
|
+
login(
|
|
133
|
+
username: string,
|
|
134
|
+
password: string,
|
|
135
|
+
extra?: {
|
|
136
|
+
encryptionMethod?: 'INTERNAL' | 'NONE';
|
|
137
|
+
[key: string]: any;
|
|
138
|
+
}
|
|
139
|
+
): Promise<void>;
|
|
88
140
|
|
|
89
141
|
// User logout
|
|
90
|
-
logout(): Promise<void>;
|
|
142
|
+
logout(options?: { isReset?: boolean }): Promise<void>;
|
|
91
143
|
|
|
92
144
|
// Initiate call
|
|
93
|
-
call(
|
|
145
|
+
call(
|
|
146
|
+
extno: string | number,
|
|
147
|
+
options?: {
|
|
148
|
+
sourceType?: number;
|
|
149
|
+
workOrderId?: string;
|
|
150
|
+
}
|
|
151
|
+
): Promise<void>;
|
|
152
|
+
|
|
153
|
+
// Transfer call
|
|
154
|
+
refer(uri: string, options?: any): Promise<void>;
|
|
94
155
|
|
|
95
156
|
// SIP registration
|
|
96
157
|
register(): Promise<void>;
|
|
@@ -107,52 +168,66 @@ interface CallKit {
|
|
|
107
168
|
// Release hold
|
|
108
169
|
unhold(): void;
|
|
109
170
|
|
|
110
|
-
//
|
|
111
|
-
|
|
171
|
+
// Mute microphone
|
|
172
|
+
mute(): void;
|
|
112
173
|
|
|
113
|
-
//
|
|
114
|
-
|
|
174
|
+
// Unmute microphone
|
|
175
|
+
unmute(): void;
|
|
115
176
|
|
|
116
|
-
// Set
|
|
117
|
-
|
|
177
|
+
// Set user status (manually)
|
|
178
|
+
setUserStatus(status: number): Promise<void>;
|
|
118
179
|
|
|
119
180
|
// Reset all states
|
|
120
|
-
reset(): Promise<void>;
|
|
181
|
+
reset(config?: { force?: boolean }): Promise<void>;
|
|
121
182
|
|
|
122
183
|
// Event listener
|
|
123
184
|
on(event: string, callback: Function): void;
|
|
185
|
+
|
|
186
|
+
// Remove event listener
|
|
187
|
+
off(event: string, callback?: Function): void;
|
|
188
|
+
|
|
189
|
+
// Remove all event listeners
|
|
190
|
+
removeAllListeners(): void;
|
|
124
191
|
}
|
|
125
192
|
```
|
|
126
193
|
|
|
127
194
|
### Event List
|
|
128
195
|
|
|
129
|
-
#### Status Events
|
|
196
|
+
#### Status Change Events
|
|
130
197
|
|
|
131
|
-
- `
|
|
132
|
-
- `
|
|
133
|
-
- `
|
|
134
|
-
- `
|
|
135
|
-
- `holdChange` - Hold status change
|
|
136
|
-
- `muteChange` - Mute status change
|
|
198
|
+
- `loginChange` - Login status change (param: boolean)
|
|
199
|
+
- `registerChange` - Registration status change (param: boolean)
|
|
200
|
+
- `callStatusChange` - Call status change (param: CallStatus)
|
|
201
|
+
- `callIdChange` - Call ID change (param: string)
|
|
202
|
+
- `holdChange` - Hold status change (param: boolean)
|
|
203
|
+
- `muteChange` - Mute status change (param: boolean)
|
|
137
204
|
|
|
138
205
|
#### Call Events
|
|
139
206
|
|
|
140
|
-
- `invite` - Received call invitation
|
|
141
|
-
- `
|
|
142
|
-
- `
|
|
143
|
-
- `
|
|
144
|
-
- `
|
|
145
|
-
- `
|
|
146
|
-
- `
|
|
147
|
-
- `
|
|
207
|
+
- `invite` - Received incoming call invitation
|
|
208
|
+
- Callback params: `{ accept: Function, reject: Function, getInviteData: Function }`
|
|
209
|
+
- `outgoingInvite` - Received outgoing call invitation
|
|
210
|
+
- `connecting` - Call connecting (param: timestamp)
|
|
211
|
+
- `ringing` - Remote party ringing (param: timestamp)
|
|
212
|
+
- `pickUp` - Remote party answered (param: timestamp)
|
|
213
|
+
- `agentPickUp` - Agent connected (param: timestamp)
|
|
214
|
+
- `hangUp` - Remote party hung up (param: timestamp)
|
|
215
|
+
- `noAnswer` - No answer (param: timestamp)
|
|
216
|
+
- `callEnd` - Call ended (param: timestamp)
|
|
217
|
+
- `callCdr` - Call detail record push (param: CDR data)
|
|
148
218
|
|
|
149
|
-
####
|
|
219
|
+
#### Connection Events
|
|
150
220
|
|
|
151
|
-
- `
|
|
221
|
+
- `IncallConnectEvent` - In-call socket connection event
|
|
222
|
+
- `sipConnectEvent` - SIP connection event
|
|
223
|
+
- `sipRegistererEvent` - SIP registerer event
|
|
224
|
+
- `sipSessionEvent` - SIP session event
|
|
152
225
|
|
|
153
|
-
####
|
|
226
|
+
#### System Events
|
|
154
227
|
|
|
155
|
-
- `
|
|
228
|
+
- `log` - System log event
|
|
229
|
+
- `error` - Error occurred (param: { code: number, message: string })
|
|
230
|
+
- `socketEvent` - Forward all socket events (param: socket message)
|
|
156
231
|
|
|
157
232
|
## Status Codes
|
|
158
233
|
|
|
@@ -161,31 +236,40 @@ interface CallKit {
|
|
|
161
236
|
```js
|
|
162
237
|
const CallStatus = {
|
|
163
238
|
init: 0, // Initial state/hung up
|
|
164
|
-
registered: 1, // Registered
|
|
165
239
|
connecting: 2, // Connecting
|
|
166
|
-
holding: 3, // Call hold
|
|
167
240
|
ringing: 4, // Ringing
|
|
168
|
-
calling: 5
|
|
241
|
+
calling: 5 // In call
|
|
169
242
|
};
|
|
170
243
|
```
|
|
171
244
|
|
|
245
|
+
> Note: In version 2.0.0+, `registered` and `holding` statuses have been removed. Registration status is now tracked separately via the `registerChange` event.
|
|
246
|
+
|
|
172
247
|
### User Status
|
|
173
248
|
|
|
249
|
+
> Note: In version 2.0.0+, user status management has been removed from CallKit. You should maintain user status through your own application using the `setUserStatus` method.
|
|
250
|
+
|
|
174
251
|
```js
|
|
252
|
+
// Example user status codes (define as needed in your application)
|
|
175
253
|
const UserStatus = {
|
|
176
254
|
offline: 1, // Offline
|
|
177
255
|
online: 2, // Online & Free
|
|
178
256
|
catNap: 3, // Cat Nap
|
|
179
257
|
busy: 4, // Busy
|
|
180
258
|
training: 5, // Training
|
|
181
|
-
processing: 6
|
|
259
|
+
processing: 6 // Processing
|
|
182
260
|
};
|
|
261
|
+
|
|
262
|
+
// Set user status manually
|
|
263
|
+
await callKit.setUserStatus(UserStatus.online);
|
|
183
264
|
```
|
|
184
265
|
|
|
185
266
|
### Error Codes
|
|
186
267
|
|
|
187
268
|
```js
|
|
188
269
|
const ErrorCode = {
|
|
270
|
+
// Unknown error
|
|
271
|
+
UNKNOWN_ERROR: -1,
|
|
272
|
+
|
|
189
273
|
// API errors (1000xxx)
|
|
190
274
|
API_USER_LOGIN_ERROR: 1000001, // User login failed
|
|
191
275
|
API_USER_STATUS_UPDATE_ERROR: 1000002, // Update user status failed
|
|
@@ -198,14 +282,19 @@ const ErrorCode = {
|
|
|
198
282
|
WEBRTC_HOLE_STATUS_ERROR: 2000004, // Call hold failed
|
|
199
283
|
WEBRTC_AUDIO_PLAYER_ERROR: 2000005, // Audio player does not exist
|
|
200
284
|
WEBRTC_AUDIO_PLAY_ERROR: 2000006, // Audio playback failed
|
|
285
|
+
WEBRTC_USER_AGENT_ERROR: 2000007, // User agent startup failed
|
|
286
|
+
WEBRTC_CALL_INVITE_ERROR: 2000008, // Call request failed
|
|
287
|
+
WEBRTC_REGISTER_ERROR: 2000009, // Register request failed
|
|
288
|
+
WEBRTC_MUTE_STATUS_ERROR: 2000010, // Mute failed
|
|
289
|
+
WEBRTC_CANCEL_REGISTER_ERROR: 2000011, // Unregister failed
|
|
290
|
+
WEBRTC_MUTE_ERROR: 2000012, // Mute operation failed
|
|
201
291
|
|
|
202
292
|
// WebSocket errors (3000xxx)
|
|
203
293
|
SOCKET_CONNECT_ERROR: 3000001, // Connection exception
|
|
204
294
|
SOCKET_PING_TIMEOUT: 3000002, // Ping timeout
|
|
205
295
|
SOKET_SERVER_ERROR: 3000003, // Server exception
|
|
206
296
|
SOCKET_CALL_ERROR: 3000004, // Call failed
|
|
207
|
-
|
|
208
|
-
UNKNOWN_ERROR: -1, // Unknown error
|
|
297
|
+
SOCKET_RECONNECT_FAILED: 3000005 // Reconnection limit exceeded
|
|
209
298
|
};
|
|
210
299
|
```
|
|
211
300
|
|
|
@@ -217,17 +306,26 @@ const ErrorCode = {
|
|
|
217
306
|
callKit.on('callStatusChange', (status) => {
|
|
218
307
|
const statusMap = {
|
|
219
308
|
0: 'Initial state',
|
|
220
|
-
1: 'Registered',
|
|
221
309
|
2: 'Connecting',
|
|
222
|
-
3: 'Call on hold',
|
|
223
310
|
4: 'Ringing',
|
|
224
|
-
5: 'In call'
|
|
311
|
+
5: 'In call'
|
|
225
312
|
};
|
|
226
313
|
console.log('Current status:', statusMap[status]);
|
|
227
314
|
});
|
|
228
315
|
```
|
|
229
316
|
|
|
230
|
-
### Q2: How to
|
|
317
|
+
### Q2: How to listen for registration status changes?
|
|
318
|
+
|
|
319
|
+
```js
|
|
320
|
+
callKit.on('registerChange', (isRegistered) => {
|
|
321
|
+
console.log(
|
|
322
|
+
'Registration status:',
|
|
323
|
+
isRegistered ? 'Registered' : 'Unregistered'
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Q3: How to get call duration?
|
|
231
329
|
|
|
232
330
|
```js
|
|
233
331
|
let startTime;
|
|
@@ -242,7 +340,23 @@ callKit.on('callEnd', (date) => {
|
|
|
242
340
|
});
|
|
243
341
|
```
|
|
244
342
|
|
|
245
|
-
###
|
|
343
|
+
### Q4: How to handle incoming calls?
|
|
344
|
+
|
|
345
|
+
```js
|
|
346
|
+
callKit.on('invite', ({ accept, reject, getInviteData }) => {
|
|
347
|
+
// Get call data
|
|
348
|
+
const inviteData = getInviteData();
|
|
349
|
+
console.log('Incoming call:', inviteData);
|
|
350
|
+
|
|
351
|
+
// Accept the call
|
|
352
|
+
accept();
|
|
353
|
+
|
|
354
|
+
// Or reject the call
|
|
355
|
+
// reject();
|
|
356
|
+
});
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Q5: How to handle errors?
|
|
246
360
|
|
|
247
361
|
```js
|
|
248
362
|
callKit.on('error', (error) => {
|
|
@@ -256,17 +370,127 @@ callKit.on('error', (error) => {
|
|
|
256
370
|
case 2000002:
|
|
257
371
|
// Handle not logged in error
|
|
258
372
|
break;
|
|
259
|
-
|
|
373
|
+
case 3000005:
|
|
374
|
+
// Handle reconnection failure
|
|
375
|
+
break;
|
|
260
376
|
// ...other error handling
|
|
261
377
|
}
|
|
262
378
|
});
|
|
263
379
|
```
|
|
264
380
|
|
|
381
|
+
### Q6: How to handle reconnection?
|
|
382
|
+
|
|
383
|
+
```js
|
|
384
|
+
// Listen to reconnection events
|
|
385
|
+
callKit.on('IncallConnectEvent', (event) => {
|
|
386
|
+
console.log('In-call connection event:', event);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
callKit.on('sipConnectEvent', (event) => {
|
|
390
|
+
console.log('SIP connection event:', event);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Configure reconnection options
|
|
394
|
+
const callKit = new CallKit({
|
|
395
|
+
host: 'https://example.com',
|
|
396
|
+
socket: 'wss://example.com/ws/in-call',
|
|
397
|
+
audioRef: () => document.querySelector('#audioRef'),
|
|
398
|
+
reconnect: {
|
|
399
|
+
sip: {
|
|
400
|
+
enabled: true,
|
|
401
|
+
maxAttempts: 5,
|
|
402
|
+
delay: 3000
|
|
403
|
+
},
|
|
404
|
+
incall: {
|
|
405
|
+
enabled: true,
|
|
406
|
+
maxAttempts: 5,
|
|
407
|
+
delay: 3000
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Q7: How to use mute/unmute?
|
|
414
|
+
|
|
415
|
+
```js
|
|
416
|
+
// Mute microphone
|
|
417
|
+
callKit.mute();
|
|
418
|
+
|
|
419
|
+
// Unmute microphone
|
|
420
|
+
callKit.unmute();
|
|
421
|
+
|
|
422
|
+
// Listen to mute status changes
|
|
423
|
+
callKit.on('muteChange', (isMuted) => {
|
|
424
|
+
console.log('Mute status:', isMuted ? 'Muted' : 'Unmuted');
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Q8: How to use hold/unhold?
|
|
429
|
+
|
|
430
|
+
```js
|
|
431
|
+
// Hold call
|
|
432
|
+
callKit.hold();
|
|
433
|
+
|
|
434
|
+
// Unhold call
|
|
435
|
+
callKit.unhold();
|
|
436
|
+
|
|
437
|
+
// Listen to hold status changes
|
|
438
|
+
callKit.on('holdChange', (isHeld) => {
|
|
439
|
+
console.log('Hold status:', isHeld ? 'On hold' : 'Active');
|
|
440
|
+
});
|
|
441
|
+
```
|
|
442
|
+
|
|
265
443
|
## More Information
|
|
266
444
|
|
|
267
445
|
For complete TypeScript type definitions, please refer to [index.d.ts](./dist/index.d.ts)
|
|
268
446
|
|
|
447
|
+
## Breaking Changes in v2.0.0
|
|
448
|
+
|
|
449
|
+
### Major Changes
|
|
450
|
+
|
|
451
|
+
1. **User Status Management Removed**
|
|
452
|
+
|
|
453
|
+
- CallKit no longer automatically manages user status
|
|
454
|
+
- Use `setUserStatus()` method to manually maintain user status
|
|
455
|
+
|
|
456
|
+
2. **Registration Status Separated**
|
|
457
|
+
|
|
458
|
+
- Registration status is no longer part of call status
|
|
459
|
+
- Use `registerChange` event to track registration status independently
|
|
460
|
+
|
|
461
|
+
3. **Call Status Simplified**
|
|
462
|
+
|
|
463
|
+
- Removed `registered` (1) status - use `registerChange` event instead
|
|
464
|
+
- Removed `holding` (3) status - use `holdChange` event instead
|
|
465
|
+
- Current statuses: `init` (0), `connecting` (2), `ringing` (4), `calling` (5)
|
|
466
|
+
|
|
467
|
+
4. **Enhanced Reconnection Mechanism**
|
|
468
|
+
|
|
469
|
+
- Completely refactored SIP and socket reconnection logic
|
|
470
|
+
- Added configurable reconnection options for both SIP and in-call connections
|
|
471
|
+
- New error code: `SOCKET_RECONNECT_FAILED` (3000005)
|
|
472
|
+
|
|
473
|
+
5. **New Methods**
|
|
474
|
+
|
|
475
|
+
- `mute()` / `unmute()` - Control microphone muting
|
|
476
|
+
- `refer(uri, options)` - Transfer calls
|
|
477
|
+
- `off(event, callback)` - Remove specific event listeners
|
|
478
|
+
- `removeAllListeners()` - Remove all event listeners
|
|
479
|
+
- `setUserStatus(status)` - Manually set user status
|
|
480
|
+
|
|
481
|
+
6. **New Events**
|
|
482
|
+
- `callIdChange` - Call ID change event
|
|
483
|
+
- `outgoingInvite` - Outgoing call invitation event
|
|
484
|
+
- `hangUp` - Remote party hang up event
|
|
485
|
+
- `IncallConnectEvent` - In-call socket connection event
|
|
486
|
+
- `sipConnectEvent` - SIP connection event
|
|
487
|
+
- `sipRegistererEvent` - SIP registerer event
|
|
488
|
+
- `sipSessionEvent` - SIP session event
|
|
489
|
+
|
|
490
|
+
### Migration Guide
|
|
491
|
+
|
|
492
|
+
Please refer to [MIGRATION.md](./MIGRATION.md) for detailed migration instructions from v1.x to v2.0.
|
|
493
|
+
|
|
269
494
|
## License
|
|
270
495
|
|
|
271
496
|
MIT
|
|
272
|
-
|
package/dist/index.d.ts
CHANGED
|
@@ -8,11 +8,13 @@ declare class Api {
|
|
|
8
8
|
login(params: {
|
|
9
9
|
userName: string;
|
|
10
10
|
password: string;
|
|
11
|
+
timestamp: number;
|
|
11
12
|
}): Promise<any>;
|
|
12
13
|
loginOut(params: {
|
|
13
14
|
sessionId: string;
|
|
15
|
+
timestamp: number;
|
|
14
16
|
}): Promise<any>;
|
|
15
|
-
trackLogs(log: string): Promise<
|
|
17
|
+
trackLogs(log: string): Promise<void>;
|
|
16
18
|
/**
|
|
17
19
|
*
|
|
18
20
|
* @param params agentId status
|
|
@@ -74,7 +76,7 @@ declare class Socket {
|
|
|
74
76
|
/**
|
|
75
77
|
* @description connect auth state
|
|
76
78
|
* @default {
|
|
77
|
-
*
|
|
79
|
+
* startConfirm: false,
|
|
78
80
|
* isConnected: false,
|
|
79
81
|
* isReconnecting: false,
|
|
80
82
|
* isAuthenticated: false,
|
|
@@ -82,16 +84,23 @@ declare class Socket {
|
|
|
82
84
|
* }
|
|
83
85
|
*/
|
|
84
86
|
private connectAuthState;
|
|
85
|
-
get
|
|
87
|
+
get startConfirm(): boolean;
|
|
86
88
|
get isError(): boolean;
|
|
87
89
|
constructor(callKit: CallKit);
|
|
90
|
+
get reconnectConfig(): {
|
|
91
|
+
enabled?: boolean;
|
|
92
|
+
maxAttempts?: number;
|
|
93
|
+
delay?: number;
|
|
94
|
+
pingInterval?: number;
|
|
95
|
+
pingTimeout?: number;
|
|
96
|
+
};
|
|
88
97
|
init(): void;
|
|
89
|
-
private getSocketConfig;
|
|
90
98
|
private setConnectAuthState;
|
|
91
99
|
private handleDisconnect;
|
|
92
100
|
private clearWebSocket;
|
|
93
101
|
private connect;
|
|
94
102
|
private onOpen;
|
|
103
|
+
private cleanReconnectState;
|
|
95
104
|
private resetConnectState;
|
|
96
105
|
private onClose;
|
|
97
106
|
private onError;
|
|
@@ -104,7 +113,7 @@ declare class Socket {
|
|
|
104
113
|
* reset socket connection and all states
|
|
105
114
|
*/
|
|
106
115
|
reset(config?: {
|
|
107
|
-
|
|
116
|
+
force?: boolean;
|
|
108
117
|
}): Promise<void>;
|
|
109
118
|
private attemptReconnect;
|
|
110
119
|
}
|
|
@@ -121,11 +130,14 @@ interface IConfig {
|
|
|
121
130
|
version: string;
|
|
122
131
|
host: string;
|
|
123
132
|
log: LoggerLevel;
|
|
124
|
-
trackLogs: TrackLogsConfig
|
|
133
|
+
trackLogs: Partial<TrackLogsConfig>;
|
|
125
134
|
audioRef?: HTMLAudioElement | (() => HTMLAudioElement);
|
|
126
135
|
constrains: WebrtcConstranis;
|
|
127
136
|
socket: string;
|
|
128
|
-
reconnect?:
|
|
137
|
+
reconnect?: {
|
|
138
|
+
sip?: Partial<SocketConfig>;
|
|
139
|
+
incall?: Partial<SocketConfig>;
|
|
140
|
+
};
|
|
129
141
|
userInfo: {
|
|
130
142
|
wsUrl: string;
|
|
131
143
|
sessionId: string;
|
|
@@ -154,11 +166,22 @@ declare class Config {
|
|
|
154
166
|
getConfig: () => IConfig;
|
|
155
167
|
setConfig: (key: string, value: any) => Promise<void>;
|
|
156
168
|
setUserInfo: (key: string, value: any) => Promise<void>;
|
|
157
|
-
reset: () => Promise<void>;
|
|
169
|
+
reset: (form: string) => Promise<void>;
|
|
158
170
|
validate: () => boolean;
|
|
159
171
|
isLogin: () => boolean;
|
|
160
172
|
check(): boolean;
|
|
161
|
-
getTrackLogsConfig():
|
|
173
|
+
getTrackLogsConfig(): {
|
|
174
|
+
enabled: boolean;
|
|
175
|
+
interval: number;
|
|
176
|
+
maxSize: number;
|
|
177
|
+
};
|
|
178
|
+
getReconnectConfig(type: 'sip' | 'incall'): {
|
|
179
|
+
enabled?: boolean;
|
|
180
|
+
maxAttempts?: number;
|
|
181
|
+
delay?: number;
|
|
182
|
+
pingInterval?: number;
|
|
183
|
+
pingTimeout?: number;
|
|
184
|
+
};
|
|
162
185
|
enableTrackLogs(enabled: boolean): void;
|
|
163
186
|
}
|
|
164
187
|
|
|
@@ -369,10 +392,6 @@ declare class Call {
|
|
|
369
392
|
type CallStatusType = (typeof CallStatus)[keyof typeof CallStatus];
|
|
370
393
|
declare class Connect {
|
|
371
394
|
callKit: CallKit;
|
|
372
|
-
/**
|
|
373
|
-
*@description Reconnect config
|
|
374
|
-
*/
|
|
375
|
-
private reconnectConfig;
|
|
376
395
|
/**
|
|
377
396
|
*@description Whether muted
|
|
378
397
|
*/
|
|
@@ -397,6 +416,10 @@ declare class Connect {
|
|
|
397
416
|
*@description Whether it's a re-connected
|
|
398
417
|
*/
|
|
399
418
|
isReConnected: boolean;
|
|
419
|
+
/**
|
|
420
|
+
*@description Whether it's a referring
|
|
421
|
+
*/
|
|
422
|
+
isRefering: boolean;
|
|
400
423
|
/**
|
|
401
424
|
*@description Whether it's an outgoing call
|
|
402
425
|
*/
|
|
@@ -410,7 +433,18 @@ declare class Connect {
|
|
|
410
433
|
*/
|
|
411
434
|
hasInvite: boolean;
|
|
412
435
|
constructor(callKit: CallKit);
|
|
413
|
-
|
|
436
|
+
get reconnectConfig(): {
|
|
437
|
+
enabled?: boolean;
|
|
438
|
+
maxAttempts?: number;
|
|
439
|
+
delay?: number;
|
|
440
|
+
pingInterval?: number;
|
|
441
|
+
pingTimeout?: number;
|
|
442
|
+
};
|
|
443
|
+
private currentCallId;
|
|
444
|
+
getCurrentCallId(): string | null;
|
|
445
|
+
setRefering(refering: boolean): void;
|
|
446
|
+
private setIsReConnected;
|
|
447
|
+
setOutgoing(outgoing: boolean): void;
|
|
414
448
|
setCallId(callId: string | null): void;
|
|
415
449
|
reset(): Promise<void>;
|
|
416
450
|
private getAduioReference;
|
|
@@ -446,11 +480,12 @@ declare class Connect {
|
|
|
446
480
|
* @returns
|
|
447
481
|
*/
|
|
448
482
|
isInit(): boolean;
|
|
449
|
-
private heartbeatInterval?;
|
|
450
|
-
private heartbeatFlag;
|
|
451
|
-
clearHeartbeat(): void;
|
|
452
|
-
startHeartbeat(): void;
|
|
453
483
|
socketTriggerHangup(callId: string): void;
|
|
484
|
+
/**
|
|
485
|
+
* Setup registerer and bind stateChange listener
|
|
486
|
+
* @private
|
|
487
|
+
*/
|
|
488
|
+
private setupRegisterer;
|
|
454
489
|
register(): Promise<void>;
|
|
455
490
|
private reconnectTimer?;
|
|
456
491
|
private reconnectAttempts;
|
|
@@ -492,8 +527,12 @@ interface CallKitConfig {
|
|
|
492
527
|
socket: string;
|
|
493
528
|
constrains?: WebrtcConstranis;
|
|
494
529
|
log?: LoggerLevel;
|
|
530
|
+
reconnect?: {
|
|
531
|
+
sip?: Partial<SocketConfig>;
|
|
532
|
+
incall?: Partial<SocketConfig>;
|
|
533
|
+
};
|
|
495
534
|
}
|
|
496
|
-
type ConfigEntity =
|
|
535
|
+
type ConfigEntity = Partial<IConfig> & CallKitConfig;
|
|
497
536
|
type kitEventType = (typeof KitEvent)[keyof typeof KitEvent];
|
|
498
537
|
interface Listener {
|
|
499
538
|
event: kitEventType;
|
|
@@ -527,15 +566,18 @@ declare class CallKit {
|
|
|
527
566
|
* set userstatus
|
|
528
567
|
* @param status
|
|
529
568
|
*/
|
|
530
|
-
setUserStatus(status: number
|
|
531
|
-
|
|
532
|
-
focus?: boolean;
|
|
569
|
+
setUserStatus(status: number, extra?: {
|
|
570
|
+
[key: string]: any;
|
|
533
571
|
}): Promise<void>;
|
|
534
572
|
/**
|
|
535
573
|
* reset callkit
|
|
536
574
|
* @description recover the callkit to the initial state
|
|
575
|
+
* @default force is false
|
|
576
|
+
* @param config.force is true, the callkit reset socket connection and all states
|
|
537
577
|
*/
|
|
538
|
-
reset(
|
|
578
|
+
reset(config?: {
|
|
579
|
+
force?: boolean;
|
|
580
|
+
}): Promise<void>;
|
|
539
581
|
on(event: kitEventType, callback: (...args: any[]) => void): void;
|
|
540
582
|
off(event: kitEventType, callback?: (...args: any[]) => void): void;
|
|
541
583
|
removeAllListeners(): void;
|