@vonage/client-sdk 1.2.1-snapshot.17.0 → 1.2.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 +120 -19
- package/dist/client/VonageClient.d.ts +12 -1
- package/dist/client/index.cjs +3597 -3462
- package/dist/client/index.mjs +3598 -3461
- package/dist/coreExtend.d.ts +0 -10
- package/dist/kotlin/JsUnions.d.ts +11 -1
- package/dist/kotlin/clientsdk-clientcore_js.d.ts +37 -67
- package/dist/utils/ClientConfig.d.ts +9 -4
- package/dist/utils/ConversationModels.d.ts +14 -8
- package/dist/vonageClientSDK.js +3617 -3462
- package/dist/vonageClientSDK.min.js +1 -1
- package/dist/vonageClientSDK.min.mjs +1 -1
- package/dist/vonageClientSDK.mjs +3618 -3461
- package/package.json +1 -1
- /package/dist/{utils → lib}/ConnectivityManager.d.ts +0 -0
package/README.md
CHANGED
|
@@ -19,14 +19,23 @@ npm i @vonage/client-sdk
|
|
|
19
19
|
### With bundler (Webpack, Vite, etc.) and React
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
VonageClient,
|
|
24
|
+
ClientConfig,
|
|
25
|
+
ConfigRegion,
|
|
26
|
+
LoggingLevel
|
|
27
|
+
} from '@vonage/client-sdk';
|
|
23
28
|
import { useState, useEffect } from 'react';
|
|
24
29
|
|
|
25
30
|
function App() {
|
|
26
|
-
|
|
27
|
-
const [config] = useState(() => new ClientConfig(ConfigRegion.US));
|
|
31
|
+
const [config] = useState(() => new ClientConfig(ConfigRegion.AP));
|
|
28
32
|
const [client] = useState(() => {
|
|
29
|
-
|
|
33
|
+
// Initialize client with optional config (default: ERROR logging, US region).
|
|
34
|
+
const client = new VonageClient({
|
|
35
|
+
loggingLevel: LoggingLevel.DEBUG,
|
|
36
|
+
region: ConfigRegion.EU
|
|
37
|
+
});
|
|
38
|
+
// Or update some options after initialization.
|
|
30
39
|
client.setConfig(config);
|
|
31
40
|
return client;
|
|
32
41
|
});
|
|
@@ -70,11 +79,15 @@ export default App;
|
|
|
70
79
|
<script src="./node_modules/@vonage/client-sdk/dist/vonageClientSDK.min.js"></script>
|
|
71
80
|
<script>
|
|
72
81
|
const token = 'my-token';
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
// Initialize client with optional config (default: ERROR logging, US region).
|
|
83
|
+
const client = new vonageClientSDK.VoiceClient({
|
|
84
|
+
loggingLevel: LoggingLevel.DEBUG,
|
|
85
|
+
region: ConfigRegion.EU
|
|
86
|
+
});
|
|
87
|
+
// Or update some options after initialization.
|
|
88
|
+
client.setConfig({
|
|
89
|
+
region: ConfigRegion.AP
|
|
90
|
+
});
|
|
78
91
|
|
|
79
92
|
client.createSession(token).then((Session) => {});
|
|
80
93
|
</script>
|
|
@@ -85,15 +98,20 @@ export default App;
|
|
|
85
98
|
```js
|
|
86
99
|
import {
|
|
87
100
|
VonageClient,
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
ConfigRegion,
|
|
102
|
+
LoggingLevel
|
|
90
103
|
} from 'https://cdn.jsdelivr.net/npm/@vonage/client-sdk@1.0.0/dist/vonageClientSDK.esm.min.js';
|
|
91
104
|
|
|
92
|
-
|
|
105
|
+
// Initialize client with optional config (default: ERROR logging, US region).
|
|
106
|
+
const client = new VonageClient({
|
|
107
|
+
loggingLevel: LoggingLevel.DEBUG,
|
|
108
|
+
region: ConfigRegion.EU
|
|
109
|
+
});
|
|
93
110
|
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
// Or update some options after initialization.
|
|
112
|
+
client.setConfig({
|
|
113
|
+
region: ConfigRegion.AP
|
|
114
|
+
});
|
|
97
115
|
|
|
98
116
|
(async () => {
|
|
99
117
|
const token = 'my-token';
|
|
@@ -121,37 +139,120 @@ Below are several typical scenarios where the SDK is commonly utilized.
|
|
|
121
139
|
### Make an Outbound Call
|
|
122
140
|
|
|
123
141
|
```ts
|
|
142
|
+
const context = {
|
|
143
|
+
callee: 'user1'
|
|
144
|
+
};
|
|
124
145
|
|
|
146
|
+
const callId = await client.serverCall(context);
|
|
125
147
|
```
|
|
126
148
|
|
|
127
149
|
### Answer/Reject an Inbound Call
|
|
128
150
|
|
|
129
151
|
```ts
|
|
130
|
-
|
|
152
|
+
client.on('callInvite', async (callId, from, channleType) => {
|
|
153
|
+
console.log(`Received call invite from ${from} on ${channleType}`);
|
|
154
|
+
|
|
155
|
+
// Accept the call
|
|
156
|
+
await client.answer(callId);
|
|
157
|
+
|
|
158
|
+
// Reject the call
|
|
159
|
+
await client.reject(callId);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
client.on('callInviteCancel', (callId, reason) => {
|
|
163
|
+
if (reason === CancelReason.AnsweredElsewhere) {
|
|
164
|
+
console.log(`Call ${callId} was answered elsewhere`);
|
|
165
|
+
} else if (reason === CancelReason.RejectedElsewhere) {
|
|
166
|
+
console.log(`Call ${callId} was rejected elsewhere`);
|
|
167
|
+
} else if (reason === CancelReason.RemoteCancel) {
|
|
168
|
+
console.log(`Call ${callId} was cancelled by the caller`);
|
|
169
|
+
} else if (reason === CancelReason.RemoteTimeout) {
|
|
170
|
+
console.log(`Call ${callId} timed out`);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
131
173
|
```
|
|
132
174
|
|
|
133
175
|
### Hang-up and Collect Stats
|
|
134
176
|
|
|
135
177
|
```ts
|
|
136
|
-
|
|
178
|
+
client.on('callHangup', (callId, callQuality, reason) => {
|
|
179
|
+
if (reason.name == 'LOCAL_HANGUP') {
|
|
180
|
+
console.log(`Call ${callId} was hung up locally`);
|
|
181
|
+
} else if (reason.name == 'REMOTE_HANGUP') {
|
|
182
|
+
console.log(`Call ${callId} was hung up remotely`);
|
|
183
|
+
} else if (reason.name == 'REMOTE_REJECT') {
|
|
184
|
+
console.log(`Call ${callId} was rejected remotely`);
|
|
185
|
+
} else if (reason.name == 'REMOTE_NO_ANSWER_TIMEOUT') {
|
|
186
|
+
console.log(`Call ${callId} timed out`);
|
|
187
|
+
} else if (reason.name == 'MEDIA_TIMEOUT') {
|
|
188
|
+
console.log(`Call ${callId} timed out`);
|
|
189
|
+
} else {
|
|
190
|
+
exhaustiveCheck(reason.name);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
137
193
|
```
|
|
138
194
|
|
|
139
195
|
### Get Conversations
|
|
140
196
|
|
|
141
197
|
```ts
|
|
142
|
-
|
|
198
|
+
const { conversations, nextCursor, previousCursor } =
|
|
199
|
+
await client.getConversations(
|
|
200
|
+
PresentingOrder.ASC,
|
|
201
|
+
10, // page size
|
|
202
|
+
undefined, // cursor
|
|
203
|
+
true // include custom data
|
|
204
|
+
);
|
|
143
205
|
```
|
|
144
206
|
|
|
145
207
|
### Send Text Messages
|
|
146
208
|
|
|
147
209
|
```ts
|
|
148
|
-
|
|
210
|
+
const timestamp = await client.sendMessageTextEvent(
|
|
211
|
+
'CONVERSATION_ID',
|
|
212
|
+
'Hello World!'
|
|
213
|
+
);
|
|
149
214
|
```
|
|
150
215
|
|
|
151
216
|
### Listen for Conversation Events
|
|
152
217
|
|
|
153
218
|
```ts
|
|
219
|
+
const eventHandler = (event: ConversationEvent) => {
|
|
220
|
+
if (event.kind == 'member:invited') {
|
|
221
|
+
console.log(`Member invited: ${event.body.memberId}`);
|
|
222
|
+
} else if (event.kind == 'member:joined') {
|
|
223
|
+
console.log(`Member joined: ${event.body.memberId}`);
|
|
224
|
+
} else if (event.kind == 'member:left') {
|
|
225
|
+
console.log(`Member left: ${event.body.memberId}`);
|
|
226
|
+
} else if (event.kind == 'ephemeral') {
|
|
227
|
+
console.log(`Ephemeral event: ${event.body}`);
|
|
228
|
+
} else if (event.kind == 'custom') {
|
|
229
|
+
console.log(`Custom event: ${event.body}`);
|
|
230
|
+
} else if (event.kind == 'message:text') {
|
|
231
|
+
console.log(`Text message: ${event.body.text}`);
|
|
232
|
+
} else if (event.kind == 'message:custom') {
|
|
233
|
+
console.log(`Custom message: ${event.body.customData}`);
|
|
234
|
+
} else if (event.kind == 'message:image') {
|
|
235
|
+
console.log(`Image message: ${event.body.imageUrl}`);
|
|
236
|
+
} else if (event.kind == 'message:video') {
|
|
237
|
+
console.log(`Video message: ${event.body.videoUrl}`);
|
|
238
|
+
} else if (event.kind == 'message:audio') {
|
|
239
|
+
console.log(`Audio message: ${event.body.audioUrl}`);
|
|
240
|
+
} else if (event.kind == 'message:file') {
|
|
241
|
+
console.log(`File message: ${event.body.fileUrl}`);
|
|
242
|
+
} else if (event.kind == 'message:vcard') {
|
|
243
|
+
console.log(`Vcard message: ${event.body.vcardUrl}`);
|
|
244
|
+
} else if (event.kind == 'message:location') {
|
|
245
|
+
console.log(`Location message: ${event.body.location}`);
|
|
246
|
+
} else if (event.kind == 'message:template') {
|
|
247
|
+
console.log(`Template message: ${event.body.template}`);
|
|
248
|
+
} else {
|
|
249
|
+
exhaustiveCheck(event);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const listener = client.on('conversationEvent', eventHandler);
|
|
154
254
|
|
|
255
|
+
client.off('conversationEvent', listener);
|
|
155
256
|
```
|
|
156
257
|
|
|
157
258
|
## Documentation and examples
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import vonage from '../utils/vonage';
|
|
2
|
-
import { Conversation, ConversationsPage, Member, MembersPage, PresentingOrder,
|
|
2
|
+
import { Conversation, ConversationsPage, Member, MembersPage, PresentingOrder, OrderBy, ClientInitConfigObject, ClientConfigObject } from '../utils';
|
|
3
|
+
import { ConversationEvent, PersistentConversationEvent } from '../kotlin/JsUnions';
|
|
3
4
|
/**
|
|
4
5
|
* The Vonage Client SDK for JS/TS provides a simple interface
|
|
5
6
|
* For the Vonage Voice and Messaging APIs.
|
|
@@ -57,6 +58,16 @@ export declare const setVonageClientLoggingLevel: typeof vonage.setDefaultLoggin
|
|
|
57
58
|
*/
|
|
58
59
|
export declare class VonageClient extends vonage.CombinedClientJS {
|
|
59
60
|
constructor(config?: ClientInitConfigObject);
|
|
61
|
+
/**
|
|
62
|
+
* Set a configuration for the client SDK
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* [[include: snippet_SetClientConfig.txt]]
|
|
66
|
+
*
|
|
67
|
+
* @param config - A configuration object
|
|
68
|
+
* @returns void
|
|
69
|
+
*/
|
|
70
|
+
setConfig(config: ClientConfigObject): void;
|
|
60
71
|
/**
|
|
61
72
|
* Register a callback for an event.
|
|
62
73
|
*
|