@vonage/client-sdk 1.2.1-alpha.0 → 1.2.1-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 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,68 +139,55 @@ Below are several typical scenarios where the SDK is commonly utilized.
121
139
  ### Make an Outbound Call
122
140
 
123
141
  ```ts
124
- const call = await client.serverCall({
125
- customData: {
126
- callee: 'bob',
127
- type: 'app'
128
- }
129
- });
130
- console.log(call);
142
+ const context = {
143
+ callee: 'user1'
144
+ };
145
+
146
+ const callId = await client.serverCall(context);
131
147
  ```
132
148
 
133
149
  ### Answer/Reject an Inbound Call
134
150
 
135
151
  ```ts
136
- // Answer Call
137
- client.on(
138
- 'callInvite',
139
- async (callId: string, from: string, channelType: string) => {
140
- client.answer(callId);
141
- console.log(callId, from, channelType);
142
- }
143
- );
152
+ client.on('callInvite', async (callId, from, channleType) => {
153
+ console.log(`Received call invite from ${from} on ${channleType}`);
144
154
 
145
- // ----
155
+ // Accept the call
156
+ await client.answer(callId);
157
+
158
+ // Reject the call
159
+ await client.reject(callId);
160
+ });
146
161
 
147
- // Reject Call
148
- client.on(
149
- 'callInvite',
150
- async (callId: string, from: string, channelType: string) => {
151
- client.reject(callId);
152
- console.log(callId, from, channelType);
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`);
153
171
  }
154
- );
172
+ });
155
173
  ```
156
174
 
157
175
  ### Hang-up and Collect Stats
158
176
 
159
177
  ```ts
160
- // await client.hangup(call);
161
- await client.hangup(call, 'reason-text', 'reason-code');
162
-
163
178
  client.on('callHangup', (callId, callQuality, reason) => {
164
- if (callId == call) {
165
- console.log('The call has finished');
166
- }
167
- console.log(`This was your call MOS score: `, callQuality.mos_score);
168
- const reason_name = reason.name;
169
- if (reason_name === 'LOCAL_HANGUP') {
170
- console.log('You hung up the call');
171
- return;
172
- } else if (reason_name === 'REMOTE_HANGUP') {
173
- console.log('Call was hung up remotely');
174
- return;
175
- } else if (reason_name === 'REMOTE_REJECT') {
176
- console.log('Call was rejected');
177
- return;
178
- } else if (reason_name === 'MEDIA_TIMEOUT') {
179
- console.log('Timeout due to media failure');
180
- return;
181
- } else if (reason_name === 'REMOTE_NO_ANSWER_TIMEOUT') {
182
- console.log('Timeout due to missing remote answer');
183
- return;
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`);
184
189
  } else {
185
- return exhaustiveCheck(reason_name);
190
+ exhaustiveCheck(reason.name);
186
191
  }
187
192
  });
188
193
  ```
@@ -190,72 +195,64 @@ client.on('callHangup', (callId, callQuality, reason) => {
190
195
  ### Get Conversations
191
196
 
192
197
  ```ts
193
- try {
194
- let cursor: string | undefined | null = undefined;
195
- const pageSize = 10;
196
- const conversations: Conversation[] = [];
197
- const includeCustomData = false;
198
- const orderBy = OrderBy.CREATED;
199
- do {
200
- const response: ConversationsPage = await client.getConversations(
201
- PresentingOrder.ASC,
202
- pageSize,
203
- cursor,
204
- includeCustomData,
205
- orderBy
206
- );
207
- conversations.push(...response.conversations);
208
- cursor = response.nextCursor;
209
- } while (cursor !== null);
210
- console.log(`Conversations successfully fetched: ${conversations}`);
211
- } catch (e) {
212
- console.log(`Error in fetching Conversations: ${e}`);
213
- }
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
+ );
214
205
  ```
215
206
 
216
207
  ### Send Text Messages
217
208
 
218
209
  ```ts
219
- try {
220
- const timestamp = await client.sendMessageTextEvent(
221
- 'conversationId',
222
- 'Hello there'
223
- );
224
- console.log(`Message successfully sent with timestamp ${timestamp}`);
225
- } catch (e) {
226
- console.log(`Error in sending Message: ${e}`);
227
- }
210
+ const timestamp = await client.sendMessageTextEvent(
211
+ 'CONVERSATION_ID',
212
+ 'Hello World!'
213
+ );
228
214
  ```
229
215
 
230
216
  ### Listen for Conversation Events
231
217
 
232
218
  ```ts
233
- client.on('conversationEvent', (event) => {
234
- switch (event.kind) {
235
- case 'member:invited':
236
- case 'member:joined':
237
- case 'member:left':
238
- case 'message:text':
239
- case 'message:custom':
240
- case 'message:audio':
241
- case 'message:video':
242
- case 'message:image':
243
- case 'message:file':
244
- case 'message:vcard':
245
- case 'message:location':
246
- case 'message:template':
247
- case 'custom':
248
- case 'ephemeral':
249
- break;
250
- default:
251
- exhaustiveCheck(event);
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);
252
250
  }
253
- const sender =
254
- event.from.kind == 'embeddedInfo' ? event.from.user.name : 'System';
255
- console.log(
256
- `${sender} sent ${event.kind} event to Conversation ${event.conversationId}`
257
- );
258
- });
251
+ };
252
+
253
+ const listener = client.on('conversationEvent', eventHandler);
254
+
255
+ client.off('conversationEvent', listener);
259
256
  ```
260
257
 
261
258
  ## Documentation and examples
@@ -1,5 +1,5 @@
1
1
  import vonage from '../utils/vonage';
2
- import { Conversation, ConversationsPage, Member, MembersPage, PresentingOrder, ConversationEvent, PersistentConversationEvent, OrderBy } from '../utils';
2
+ import { Conversation, ConversationsPage, Member, MembersPage, PresentingOrder, ConversationEvent, PersistentConversationEvent, OrderBy, ClientInitConfigObject } from '../utils';
3
3
  /**
4
4
  * The Vonage Client SDK for JS/TS provides a simple interface
5
5
  * For the Vonage Voice and Messaging APIs.
@@ -39,6 +39,10 @@ export declare const CallDisconnectReason: typeof vonage.CallDisconnectReasonJS;
39
39
  type JSONValue = string | number | boolean | {
40
40
  [x: string]: JSONValue;
41
41
  } | JSONValue[];
42
+ /**
43
+ * @deprecated Use {@link ClientInitConfig.loggingLevel} instead.
44
+ * @param level - The logging level to set.
45
+ */
42
46
  export declare const setVonageClientLoggingLevel: typeof vonage.setDefaultLoggingLevel;
43
47
  /**
44
48
  * VonageClient is the main entry point for the Vonage Client SDK.
@@ -52,12 +56,12 @@ export declare const setVonageClientLoggingLevel: typeof vonage.setDefaultLoggin
52
56
  * DO NOT ADD CODE HERE UNLESS REALLY NEEDEED!!111!
53
57
  */
54
58
  export declare class VonageClient extends vonage.CombinedClientJS {
55
- constructor();
59
+ constructor(config?: ClientInitConfigObject);
56
60
  /**
57
61
  * Register a callback for an event.
58
62
  *
59
63
  * @example
60
- * [[include:register_listener.txt]]
64
+ * [[include: snippet_RegisterListener.txt]]
61
65
  *
62
66
  * @param event - the event to register for (e.g. 'legStatusUpdate')
63
67
  * @param callback - the callback to register for the event
@@ -71,7 +75,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
71
75
  * Unregister a callback for an event.
72
76
  *
73
77
  * @example
74
- * [[include:unregister_listener.txt]]
78
+ * [[include: snippet_UnregisterListener.txt]]
75
79
  *
76
80
  * @param event - the event to register for (e.g. 'legStatusUpdate')
77
81
  * @param callbackSymbol - the callback symbol to unregister
@@ -84,7 +88,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
84
88
  * Clear all callbacks for an event.
85
89
  *
86
90
  * @example
87
- * [[include: clear_callbacks.txt]]
91
+ * [[include: snippet_Clear_Callbacks.txt]]
88
92
  *
89
93
  * @param event - the event to unregister from (e.g. 'legStatusUpdate')
90
94
  * @returns void
@@ -101,7 +105,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
101
105
  * to resume an existing session.
102
106
  *
103
107
  * @example
104
- * [[include:create_session.txt]]
108
+ * [[include: snippet_SessionCreate.txt]]
105
109
  *
106
110
  * @param token
107
111
  * @param sessionId - optional sessionId to use
@@ -128,7 +132,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
128
132
  * This is used to initiate a call using the Voice API and NCCO.
129
133
  *
130
134
  * @example
131
- * [[include:outbound_call.txt]]
135
+ * [[include: snippet_OutboundCall.txt]]
132
136
  *
133
137
  * @group Voice
134
138
  * @param context - the context to send to the server passed as Custom data to the voice answer webhook
@@ -139,7 +143,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
139
143
  * Hangup a call.
140
144
  *
141
145
  * @example
142
- * [[include:call_hangup.txt]]
146
+ * [[include: snippet_CallHangup.txt]]
143
147
  *
144
148
  * @group Voice
145
149
  * @param callId - the `callId` of the call to hangup
@@ -161,7 +165,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
161
165
  * Sends a TTS message to the Call
162
166
  *
163
167
  * @example
164
- * [[include:call_say.txt]]
168
+ * [[include: snippet_CallSay.txt]]
165
169
  *
166
170
  * @group Voice
167
171
  * @param callId - the `callId` of the call to send the message to
@@ -173,7 +177,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
173
177
  * Get a list of Conversations for the user.
174
178
  *
175
179
  * @example
176
- * [[include:get_conversations.txt]]
180
+ * [[include: snippet_GetConversations.txt]]
177
181
  *
178
182
  * @group Chat
179
183
  * @beta
@@ -187,7 +191,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
187
191
  * Get a Conversation's Events
188
192
  *
189
193
  * @example
190
- * [[include:get_conversation_events.txt]]
194
+ * [[include: snippet_GetConversationEvents.txt]]
191
195
  *
192
196
  * @group Chat
193
197
  * @beta
@@ -196,18 +200,19 @@ export declare class VonageClient extends vonage.CombinedClientJS {
196
200
  * @param pageSize - the number of events to return per page (default: 100)
197
201
  * @param cursor - the cursor to use for pagination (default: null)
198
202
  * @param eventFilter - the event types to filter by (default: null)
203
+ * @param includeDeletedEvents - A boolean, which when sent as true, will include `deletedEvents` in the list, default is false
199
204
  * @returns a `EventsPage` containing the events
200
205
  *
201
206
  * @privateRemarks
202
207
  * * This is a workaround for the to ensure exhaustiveness of the `ConversationEvent` type
203
208
  * * the kotlin core does not support union types
204
209
  */
205
- getConversationEvents(id: string, order?: PresentingOrder, pageSize?: number, cursor?: string | null, eventFilter?: string[] | null): Promise<EventPage>;
210
+ getConversationEvents(id: string, order?: PresentingOrder, pageSize?: number, cursor?: string | null, eventFilter?: string[] | null, includeDeletedEvents?: boolean): Promise<EventPage>;
206
211
  /**
207
212
  * Get a Conversation's Members
208
213
  *
209
214
  * @example
210
- * [[include:get_conversation_members.txt]]
215
+ * [[include: snippet_GetConversationMembers.txt]]
211
216
  *
212
217
  * @group Chat
213
218
  * @beta
@@ -222,7 +227,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
222
227
  * Create a conversation
223
228
  *
224
229
  * @example
225
- * [[include:create_conversation.txt]]
230
+ * [[include: snippet_CreateConversation.txt]]
226
231
  *
227
232
  * @group Chat
228
233
  * @beta
@@ -235,7 +240,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
235
240
  * Get a Conversation
236
241
  *
237
242
  * @example
238
- * [[include:get_conversation.txt]]
243
+ * [[include: snippet_GetConversation.txt]]
239
244
  *
240
245
  * @param id - the Conversation's id
241
246
  * @returns the `Conversation`
@@ -245,7 +250,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
245
250
  * Leave a Conversation
246
251
  *
247
252
  * @example
248
- * [[include:leave_conversation.txt]]
253
+ * [[include: snippet_LeaveConversation.txt]]
249
254
  *
250
255
  * @group Chat
251
256
  * @beta
@@ -257,7 +262,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
257
262
  * Join a Conversation
258
263
  *
259
264
  * @example
260
- * [[include:join_conversation.txt]]
265
+ * [[include: snippet_JoinConversation.txt]]
261
266
  *
262
267
  * @group Chat
263
268
  * @beta
@@ -269,7 +274,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
269
274
  * Delete a Conversation
270
275
  *
271
276
  * @example
272
- * [[include:delete_conversation.txt]]
277
+ * [[include: snippet_DeleteConversation.txt]]
273
278
  *
274
279
  * @group Chat
275
280
  * @beta
@@ -281,7 +286,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
281
286
  * Invite a user to a Conversation by user's `name`
282
287
  *
283
288
  * @example
284
- * [[include:invite_to_conversation.txt]]
289
+ * [[include: snippet_InviteToConversation.txt]]
285
290
  *
286
291
  * @group Chat
287
292
  * @beta
@@ -294,7 +299,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
294
299
  * Send a text message to a Conversation
295
300
  *
296
301
  * @example
297
- * [[include:send_text_message.txt]]
302
+ * [[include: snippet_SendTextMessage.txt]]
298
303
  *
299
304
  * @group Chat
300
305
  * @beta
@@ -307,7 +312,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
307
312
  * Send a custom message to a Conversation
308
313
  *
309
314
  * @example
310
- * [[include:send_custom_message.txt]]
315
+ * [[include: snippet_SendCustomMessage.txt]]
311
316
  *
312
317
  * @group Chat
313
318
  * @beta
@@ -320,7 +325,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
320
325
  * Send an ephemeral event to a Conversation
321
326
  *
322
327
  * @example
323
- * [[include:send_ephemeral_event.txt]]
328
+ * [[include: snippet_SendEphemeralEvent.txt]]
324
329
  *
325
330
  * @group Chat
326
331
  * @beta
@@ -346,7 +351,7 @@ export declare class VonageClient extends vonage.CombinedClientJS {
346
351
  * Get a Member of a Conversation
347
352
  *
348
353
  * @example
349
- * [[include:get_conversation_member.txt]]
354
+ * [[include: snippet_GetConversationMember.txt]]
350
355
  *
351
356
  * @group Chat
352
357
  * @beta