@vonage/client-sdk 1.2.0 → 1.2.1-beta.0
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/index.cjs +9 -9
- package/dist/client/index.mjs +9 -9
- package/dist/vonageClientSDK.js +9 -9
- package/dist/vonageClientSDK.min.js +1 -1
- package/dist/vonageClientSDK.min.mjs +1 -1
- package/dist/vonageClientSDK.mjs +9 -9
- package/package.json +1 -1
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
|
package/dist/client/index.cjs
CHANGED
|
@@ -20080,6 +20080,13 @@ function requireClientsdkClientcore () {
|
|
|
20080
20080
|
setMetadataFor(AuthorizationError, 'AuthorizationError', classMeta, SessionConnectError);
|
|
20081
20081
|
setMetadataFor(SessionExpiredTokenError, 'SessionExpiredTokenError', classMeta, SessionConnectError);
|
|
20082
20082
|
setMetadataFor(SessionMaxOpenSessions, 'SessionMaxOpenSessions', classMeta, SessionConnectError);
|
|
20083
|
+
function onRTCHangup(conversationId, legId, hangup) {
|
|
20084
|
+
}
|
|
20085
|
+
function onRTCTransfer(conversationId, legId) {
|
|
20086
|
+
}
|
|
20087
|
+
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
20088
|
+
}
|
|
20089
|
+
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
20083
20090
|
function onAudioSay() {
|
|
20084
20091
|
}
|
|
20085
20092
|
function onAudioMuteUpdate(conversationId, legId, isMuted) {
|
|
@@ -20089,17 +20096,10 @@ function requireClientsdkClientcore () {
|
|
|
20089
20096
|
function onAudioDTMFUpdate(conversationId, legId, digits) {
|
|
20090
20097
|
}
|
|
20091
20098
|
setMetadataFor(AudioEventListener, 'AudioEventListener', interfaceMeta);
|
|
20092
|
-
function onRTCHangup(conversationId, legId, hangup) {
|
|
20093
|
-
}
|
|
20094
|
-
function onRTCTransfer(conversationId, legId) {
|
|
20095
|
-
}
|
|
20096
|
-
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
20097
|
-
}
|
|
20098
|
-
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
20099
20099
|
function onConversationEvent(event) {
|
|
20100
20100
|
}
|
|
20101
20101
|
setMetadataFor(ConversationEventListener, 'ConversationEventListener', interfaceMeta);
|
|
20102
|
-
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [
|
|
20102
|
+
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
20103
20103
|
setMetadataFor(ChatAPIImpl, 'ChatAPIImpl', classMeta, VOID, [ChatAPI]);
|
|
20104
20104
|
setMetadataFor(ClientConfigRegion, 'ClientConfigRegion', classMeta, Enum);
|
|
20105
20105
|
setMetadataFor(Companion_117, 'Companion', objectMeta);
|
|
@@ -20213,7 +20213,7 @@ function requireClientsdkClientcore () {
|
|
|
20213
20213
|
setMetadataFor(HangupReason, 'HangupReason', classMeta, Enum);
|
|
20214
20214
|
setMetadataFor(LegStatus, 'LegStatus', classMeta, Enum);
|
|
20215
20215
|
setMetadataFor(CallDisconnectReason, 'CallDisconnectReason', classMeta, Enum);
|
|
20216
|
-
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [
|
|
20216
|
+
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
20217
20217
|
setMetadataFor(VoiceAPIImpl, 'VoiceAPIImpl', classMeta);
|
|
20218
20218
|
setMetadataFor(CallEvent, 'CallEvent', interfaceMeta);
|
|
20219
20219
|
setMetadataFor(SetupOutboundCall, 'SetupOutboundCall', classMeta, VOID, [CallEvent]);
|
package/dist/client/index.mjs
CHANGED
|
@@ -20056,6 +20056,13 @@ function requireClientsdkClientcore () {
|
|
|
20056
20056
|
setMetadataFor(AuthorizationError, 'AuthorizationError', classMeta, SessionConnectError);
|
|
20057
20057
|
setMetadataFor(SessionExpiredTokenError, 'SessionExpiredTokenError', classMeta, SessionConnectError);
|
|
20058
20058
|
setMetadataFor(SessionMaxOpenSessions, 'SessionMaxOpenSessions', classMeta, SessionConnectError);
|
|
20059
|
+
function onRTCHangup(conversationId, legId, hangup) {
|
|
20060
|
+
}
|
|
20061
|
+
function onRTCTransfer(conversationId, legId) {
|
|
20062
|
+
}
|
|
20063
|
+
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
20064
|
+
}
|
|
20065
|
+
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
20059
20066
|
function onAudioSay() {
|
|
20060
20067
|
}
|
|
20061
20068
|
function onAudioMuteUpdate(conversationId, legId, isMuted) {
|
|
@@ -20065,17 +20072,10 @@ function requireClientsdkClientcore () {
|
|
|
20065
20072
|
function onAudioDTMFUpdate(conversationId, legId, digits) {
|
|
20066
20073
|
}
|
|
20067
20074
|
setMetadataFor(AudioEventListener, 'AudioEventListener', interfaceMeta);
|
|
20068
|
-
function onRTCHangup(conversationId, legId, hangup) {
|
|
20069
|
-
}
|
|
20070
|
-
function onRTCTransfer(conversationId, legId) {
|
|
20071
|
-
}
|
|
20072
|
-
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
20073
|
-
}
|
|
20074
|
-
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
20075
20075
|
function onConversationEvent(event) {
|
|
20076
20076
|
}
|
|
20077
20077
|
setMetadataFor(ConversationEventListener, 'ConversationEventListener', interfaceMeta);
|
|
20078
|
-
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [
|
|
20078
|
+
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
20079
20079
|
setMetadataFor(ChatAPIImpl, 'ChatAPIImpl', classMeta, VOID, [ChatAPI]);
|
|
20080
20080
|
setMetadataFor(ClientConfigRegion, 'ClientConfigRegion', classMeta, Enum);
|
|
20081
20081
|
setMetadataFor(Companion_117, 'Companion', objectMeta);
|
|
@@ -20189,7 +20189,7 @@ function requireClientsdkClientcore () {
|
|
|
20189
20189
|
setMetadataFor(HangupReason, 'HangupReason', classMeta, Enum);
|
|
20190
20190
|
setMetadataFor(LegStatus, 'LegStatus', classMeta, Enum);
|
|
20191
20191
|
setMetadataFor(CallDisconnectReason, 'CallDisconnectReason', classMeta, Enum);
|
|
20192
|
-
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [
|
|
20192
|
+
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
20193
20193
|
setMetadataFor(VoiceAPIImpl, 'VoiceAPIImpl', classMeta);
|
|
20194
20194
|
setMetadataFor(CallEvent, 'CallEvent', interfaceMeta);
|
|
20195
20195
|
setMetadataFor(SetupOutboundCall, 'SetupOutboundCall', classMeta, VOID, [CallEvent]);
|
package/dist/vonageClientSDK.js
CHANGED
|
@@ -19625,6 +19625,13 @@
|
|
|
19625
19625
|
setMetadataFor(AuthorizationError, 'AuthorizationError', classMeta, SessionConnectError);
|
|
19626
19626
|
setMetadataFor(SessionExpiredTokenError, 'SessionExpiredTokenError', classMeta, SessionConnectError);
|
|
19627
19627
|
setMetadataFor(SessionMaxOpenSessions, 'SessionMaxOpenSessions', classMeta, SessionConnectError);
|
|
19628
|
+
function onRTCHangup(conversationId, legId, hangup) {
|
|
19629
|
+
}
|
|
19630
|
+
function onRTCTransfer(conversationId, legId) {
|
|
19631
|
+
}
|
|
19632
|
+
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
19633
|
+
}
|
|
19634
|
+
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
19628
19635
|
function onAudioSay() {
|
|
19629
19636
|
}
|
|
19630
19637
|
function onAudioMuteUpdate(conversationId, legId, isMuted) {
|
|
@@ -19634,17 +19641,10 @@
|
|
|
19634
19641
|
function onAudioDTMFUpdate(conversationId, legId, digits) {
|
|
19635
19642
|
}
|
|
19636
19643
|
setMetadataFor(AudioEventListener, 'AudioEventListener', interfaceMeta);
|
|
19637
|
-
function onRTCHangup(conversationId, legId, hangup) {
|
|
19638
|
-
}
|
|
19639
|
-
function onRTCTransfer(conversationId, legId) {
|
|
19640
|
-
}
|
|
19641
|
-
function onLegStatusUpdate(conversationId, legId, fromUserId, status) {
|
|
19642
|
-
}
|
|
19643
|
-
setMetadataFor(RTCEventListener, 'RTCEventListener', interfaceMeta);
|
|
19644
19644
|
function onConversationEvent(event) {
|
|
19645
19645
|
}
|
|
19646
19646
|
setMetadataFor(ConversationEventListener, 'ConversationEventListener', interfaceMeta);
|
|
19647
|
-
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [
|
|
19647
|
+
setMetadataFor(ChatAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
19648
19648
|
setMetadataFor(ChatAPIImpl, 'ChatAPIImpl', classMeta, VOID, [ChatAPI]);
|
|
19649
19649
|
setMetadataFor(ClientConfigRegion, 'ClientConfigRegion', classMeta, Enum);
|
|
19650
19650
|
setMetadataFor(Companion_117, 'Companion', objectMeta);
|
|
@@ -19740,7 +19740,7 @@
|
|
|
19740
19740
|
setMetadataFor(HangupReason, 'HangupReason', classMeta, Enum);
|
|
19741
19741
|
setMetadataFor(LegStatus, 'LegStatus', classMeta, Enum);
|
|
19742
19742
|
setMetadataFor(CallDisconnectReason, 'CallDisconnectReason', classMeta, Enum);
|
|
19743
|
-
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [
|
|
19743
|
+
setMetadataFor(VoiceAPIImpl$1, VOID, classMeta, VOID, [RTCEventListener, AudioEventListener, ConversationEventListener]);
|
|
19744
19744
|
setMetadataFor(VoiceAPIImpl, 'VoiceAPIImpl', classMeta);
|
|
19745
19745
|
setMetadataFor(CallEvent, 'CallEvent', interfaceMeta);
|
|
19746
19746
|
setMetadataFor(SetupOutboundCall, 'SetupOutboundCall', classMeta, VOID, [CallEvent]);
|