@koi-design/callkit 2.0.4 → 2.0.5-beta.10
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/CHANGELOG.md +156 -0
- package/README.md +281 -57
- package/dist/index.d.ts +78 -19
- package/dist/index.global.js +305 -235
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +305 -235
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +305 -235
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# v2.0.0
|
|
2
|
+
|
|
3
|
+
## Breaking Changes
|
|
4
|
+
|
|
5
|
+
- Removed user status, you can now maintain user status through events yourself
|
|
6
|
+
- Separated registered status
|
|
7
|
+
|
|
8
|
+
## What's Changed
|
|
9
|
+
|
|
10
|
+
- Refactored SIP reconnection and socket reconnection mechanism
|
|
11
|
+
- Separated call status from registered status, registered is now not associated with call status
|
|
12
|
+
- Optimized log output
|
|
13
|
+
- Optimized various details
|
|
14
|
+
|
|
15
|
+
# v1.0.24
|
|
16
|
+
|
|
17
|
+
## What's Changed
|
|
18
|
+
|
|
19
|
+
- Added socket disconnection event. Added socket reconnection mechanism and reconnection failure event.
|
|
20
|
+
|
|
21
|
+
# v1.0.23
|
|
22
|
+
|
|
23
|
+
## What's Changed
|
|
24
|
+
|
|
25
|
+
- login support encryptionMethod, The user can control whether to use internal encryption by setting a parameter.
|
|
26
|
+
|
|
27
|
+
# v1.0.22
|
|
28
|
+
|
|
29
|
+
## What's Changed
|
|
30
|
+
|
|
31
|
+
- Code optimization
|
|
32
|
+
|
|
33
|
+
# v1.0.21
|
|
34
|
+
|
|
35
|
+
## What's Changed
|
|
36
|
+
|
|
37
|
+
- Demo page, initialize CallKit address using production environment domain
|
|
38
|
+
|
|
39
|
+
# v1.0.20
|
|
40
|
+
|
|
41
|
+
## What's Changed
|
|
42
|
+
|
|
43
|
+
- Added isAutoUpdateUserStatus optimization to config, defaults to true if not configured
|
|
44
|
+
- User status changed: 1, "Offline"; 2, "Online"; 3, "Break"; 4, "In Call"; 5, "Training"; 6, "Processing"
|
|
45
|
+
- Added html3 incoming call popup html + css reference example
|
|
46
|
+
|
|
47
|
+
# v1.0.19
|
|
48
|
+
|
|
49
|
+
## What's Changed
|
|
50
|
+
|
|
51
|
+
- Added getInviteData to invite call invitation for data retrieval
|
|
52
|
+
|
|
53
|
+
# v1.0.18
|
|
54
|
+
|
|
55
|
+
## What's Changed
|
|
56
|
+
|
|
57
|
+
- Added iceGatheringTimeout parameter
|
|
58
|
+
|
|
59
|
+
# v1.0.17
|
|
60
|
+
|
|
61
|
+
## What's Changed
|
|
62
|
+
|
|
63
|
+
- Removed default handling for CALL_FAILED, currently requires user to handle actively
|
|
64
|
+
|
|
65
|
+
# v1.0.14
|
|
66
|
+
|
|
67
|
+
## What's Changed
|
|
68
|
+
|
|
69
|
+
- Added user object, updated user status overall calls user internal functions
|
|
70
|
+
- Added isAutoUpdateUserStatus to config to control whether user controls user status updates
|
|
71
|
+
|
|
72
|
+
# v1.0.12
|
|
73
|
+
|
|
74
|
+
## What's Changed
|
|
75
|
+
|
|
76
|
+
- Active hang up, user status adjusted to break
|
|
77
|
+
- Added AGENT_NO_ANSWER event
|
|
78
|
+
|
|
79
|
+
# v1.0.11
|
|
80
|
+
|
|
81
|
+
## What's Changed
|
|
82
|
+
|
|
83
|
+
- Optimized user status
|
|
84
|
+
|
|
85
|
+
Login - Status: Unregistered
|
|
86
|
+
|
|
87
|
+
Sign in - Status: Idle
|
|
88
|
+
|
|
89
|
+
Dial success (received event: CALL_SUCCESS) - Status: Busy
|
|
90
|
+
|
|
91
|
+
Dial failed (received event: CALL_FAILED) - Status: Idle
|
|
92
|
+
|
|
93
|
+
Customer no answer (received event: CUSTOMER_NO_ANSWER) - Status: Break
|
|
94
|
+
|
|
95
|
+
Customer hang up (received event: CUSTOMER_HANG_UP) - Status: Break
|
|
96
|
+
|
|
97
|
+
Agent hang up (sent event: AGENT_HANG_UP) - Status: Break
|
|
98
|
+
|
|
99
|
+
Agent error (received event: ERROR) - Status: Break
|
|
100
|
+
|
|
101
|
+
- Added isRegistered method
|
|
102
|
+
|
|
103
|
+
# v1.0.10
|
|
104
|
+
|
|
105
|
+
## What's Changed
|
|
106
|
+
|
|
107
|
+
- Agent pick up event: AGENT_PICK_UP
|
|
108
|
+
- Adjusted user status logic, login idle moved to sign in, sign out set to online
|
|
109
|
+
|
|
110
|
+
# v1.0.9
|
|
111
|
+
|
|
112
|
+
## What's Changed
|
|
113
|
+
|
|
114
|
+
- Fixed active hang up callEnd duplicate trigger issue
|
|
115
|
+
|
|
116
|
+
# v1.0.8
|
|
117
|
+
|
|
118
|
+
## What's Changed
|
|
119
|
+
|
|
120
|
+
- Fixed login detection triggered by sip signaling disConnect after logout
|
|
121
|
+
|
|
122
|
+
# v1.0.7
|
|
123
|
+
|
|
124
|
+
## What's Changed
|
|
125
|
+
|
|
126
|
+
- Added forwarding of all socket events
|
|
127
|
+
|
|
128
|
+
# v1.0.6
|
|
129
|
+
|
|
130
|
+
## What's Changed
|
|
131
|
+
|
|
132
|
+
- Support listening to multiple events with the same name
|
|
133
|
+
|
|
134
|
+
# v1.0.5
|
|
135
|
+
|
|
136
|
+
## What's Changed
|
|
137
|
+
|
|
138
|
+
- Fixed socket exception reconnection
|
|
139
|
+
|
|
140
|
+
# v1.0.4
|
|
141
|
+
|
|
142
|
+
## What's Changed
|
|
143
|
+
|
|
144
|
+
- Optimized socket connection
|
|
145
|
+
|
|
146
|
+
# v1.0.3
|
|
147
|
+
|
|
148
|
+
## What's Changed
|
|
149
|
+
|
|
150
|
+
- Incoming call answer support
|
|
151
|
+
|
|
152
|
+
# v1.0.2
|
|
153
|
+
|
|
154
|
+
## What's Changed
|
|
155
|
+
|
|
156
|
+
- Released initial version
|
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
|
-
|