@layercode/js-sdk 2.7.0 → 2.8.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 +46 -4
- package/dist/layercode-js-sdk.esm.js +5344 -5085
- package/dist/layercode-js-sdk.esm.js.map +1 -1
- package/dist/layercode-js-sdk.min.js +4620 -4357
- package/dist/layercode-js-sdk.min.js.map +1 -1
- package/dist/types/index.d.ts +27 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,54 @@ A JavaScript SDK for integrating Layercode voice agents into web applications.
|
|
|
8
8
|
npm install @layercode/js-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Or
|
|
11
|
+
Or load it directly:
|
|
12
12
|
|
|
13
13
|
```html
|
|
14
|
-
<script src="https://cdn.jsdelivr.net/npm/@layercode/js-sdk@VERSION/
|
|
14
|
+
<script src="https://cdn.jsdelivr.net/npm/@layercode/js-sdk@VERSION/dist/layercode-js-sdk.min.js"></script>
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
> Device helpers require a secure context (https/localhost) and browser `navigator.mediaDevices` support.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
## Device helpers
|
|
20
|
+
|
|
21
|
+
The SDK now exposes microphone helpers so you can build device pickers or react to hot-swaps without reimplementing the tricky parts:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import {
|
|
25
|
+
LayercodeClient,
|
|
26
|
+
listAudioInputDevices,
|
|
27
|
+
watchAudioInputDevices,
|
|
28
|
+
type LayercodeAudioInputDevice,
|
|
29
|
+
} from '@layercode/js-sdk';
|
|
30
|
+
|
|
31
|
+
async function main() {
|
|
32
|
+
const devices: LayercodeAudioInputDevice[] = await listAudioInputDevices();
|
|
33
|
+
console.log('Default mic:', devices.find((d) => d.default));
|
|
34
|
+
|
|
35
|
+
const stopWatching = watchAudioInputDevices((nextDevices) => {
|
|
36
|
+
console.log('Devices changed', nextDevices);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const client = new LayercodeClient({ /* ... */ });
|
|
40
|
+
await client.setPreferredInputDevice('abcdef123'); // persists your pick even before connecting
|
|
41
|
+
await client.connect();
|
|
42
|
+
|
|
43
|
+
// Later, when you need to follow the system default again:
|
|
44
|
+
await client.setPreferredInputDevice('default');
|
|
45
|
+
|
|
46
|
+
// Stop watching once the page/component unmounts
|
|
47
|
+
stopWatching();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
main().catch(console.error);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- `listAudioInputDevices()` triggers a permission prompt (once) and returns labeled devices with a `default` flag.
|
|
54
|
+
- `watchAudioInputDevices(cb)` re-emits whenever the browser fires `devicechange`, de-duping noisy events for you.
|
|
55
|
+
- `client.setPreferredInputDevice(deviceId | 'default' | null)` pins recording to a concrete device ID, or passes `'default'`/`null` to follow the operating system’s default input.
|
|
56
|
+
|
|
57
|
+
All helpers guard against stale media streams and ensure tracks are stopped whenever we only need labels, which avoids the “mic busy” bugs that browsers frequently hit.
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
Full API reference lives in the docs: [https://docs.layercode.com/sdk-reference/vanilla-js-sdk](https://docs.layercode.com/sdk-reference/vanilla-js-sdk)
|