@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 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 { VonageClient, ClientConfig, ConfigRegion } from '@vonage/client-sdk';
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
- // Config is optional but recomended, default region is US
27
- const [config] = useState(() => new ClientConfig(ConfigRegion.US));
31
+ const [config] = useState(() => new ClientConfig(ConfigRegion.AP));
28
32
  const [client] = useState(() => {
29
- const client = new VonageClient();
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
- const client = new vonageClientSDK.VoiceClient();
74
- const config = new vonageClientSDK.ClientConfig(
75
- vonageClientSDK.ConfigRegion.EU
76
- );
77
- client.setConfig(config);
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
- ClientConfig,
89
- ConfigRegion
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
- const client = new VonageClient();
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
- // Config is optional but recomended, default region is US
95
- const config = new ClientConfig(ConfigRegion.US);
96
- client.setConfig(config);
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, ConversationEvent, PersistentConversationEvent, OrderBy, ClientInitConfigObject } from '../utils';
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
  *