@d-id/client-sdk 2.0.6 → 2.0.7-staging.404

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
@@ -126,12 +126,10 @@ The `agentManager` object created during initialization has several built-in met
126
126
  ```
127
127
 
128
128
  ```javascript Audio File - JavaScript
129
- let speak = agentManager.speak(
130
- {
131
- type: "audio",
132
- audio_url: "http://www.yourwebsite.com/audio.mp3"
133
- }
134
- );
129
+ let speak = agentManager.speak({
130
+ type: 'audio',
131
+ audio_url: 'http://www.yourwebsite.com/audio.mp3',
132
+ });
135
133
  ```
136
134
 
137
135
  - **`agentManager.chat(string)`**
@@ -158,18 +156,28 @@ The `agentManager` object created during initialization has several built-in met
158
156
  **Supported only with Expressive (V4) agents.**
159
157
  Method to publish a microphone audio track to the session. Call after `connect()` to enable voice input.
160
158
 
161
- ```javascript
162
- const micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
163
- await agentManager.publishMicrophoneStream(micStream);
164
- ```
159
+ ```javascript
160
+ const micStream = await navigator.mediaDevices.getUserMedia({ audio: true });
161
+ await agentManager.publishMicrophoneStream(micStream);
162
+ ```
165
163
 
166
164
  - **`agentManager.unpublishMicrophoneStream()`**
167
165
  **Supported only with Expressive (V4) agents.**
168
166
  Method to stop and remove the currently published microphone track from the session.
169
167
 
170
- ```javascript
171
- await agentManager.unpublishMicrophoneStream();
172
- ```
168
+ ```javascript
169
+ await agentManager.unpublishMicrophoneStream();
170
+ ```
171
+
172
+ - **`agentManager.sendDataChannelMessage(topic, payload)`**
173
+ **Supported only with Expressive (V4) agents.**
174
+ Method to send a JSON payload to the agent over a data-channel topic. `PublicDataChannelTopic` is exported from the package root and lists every topic this method accepts.
175
+
176
+ ```javascript
177
+ import { PublicDataChannelTopic } from '@d-id/client-sdk';
178
+
179
+ await agentManager.sendDataChannelMessage(PublicDataChannelTopic.Presentation, { type: 'navigate', slide: 3 });
180
+ ```
173
181
 
174
182
  ### ➤ ✴️ Callback Functions
175
183
 
@@ -207,21 +215,24 @@ Callback functions enable you to manage various events throughout the SDK lifecy
207
215
  }
208
216
  ```
209
217
 
210
- - **`onConnectionStateChange(state):`**
218
+ - **`onConnectionStateChange(state, reason):`**
211
219
  Displaying the different connection states with the Agent's WebRTC stream connection
212
220
  Triggered when `agentManager.connect(), agentManager.reconnect(), agentManager.disconnect()` are called.
213
221
 
214
222
  ```javascript
215
- onConnectionStateChange(state) {
216
- console.log("onConnectionStateChange(): ", state)
223
+ onConnectionStateChange(state, reason) {
224
+ console.log("onConnectionStateChange(): ", state, reason)
217
225
  if (state == "connected") {
218
226
  console.log("I'm ready to go!")
219
227
  }
220
228
  }
221
229
  ```
222
230
 
231
+ The second `reason` argument says why the connection reached that state. On `disconnected` it is a `StreamEndReason` when the server ended the stream on purpose, which lets you tell a deliberate end from a dropped connection. Any other value is an opaque transport diagnostic. `agentManager.reconnect()` still works after a deliberate end; it starts a new stream rather than resuming the old one.
232
+
223
233
  ```javascript Example Values
224
234
  state: ['new', 'fail', 'connecting', 'connected', 'disconnected', 'closed'];
235
+ reason: ['ok', 'unknown_error', 'network_issue', 'message_limit', 'time_limit', 'inactivity', 'ended_by_agent'];
225
236
  ```
226
237
 
227
238
  - **`onNewMessage(messages, type)`:**