|
1 | 1 | import React, { useState, useEffect, useCallback, useRef } from 'react'; |
2 | | -import LayercodeClient, { |
3 | | - type AgentConfig, |
4 | | - type AuthorizeSessionRequest, |
5 | | - type LayercodeAudioInputDevice, |
6 | | - listAudioInputDevices, |
7 | | - watchAudioInputDevices, |
8 | | -} from 'layercode-js-sdk'; |
| 2 | +import LayercodeClient, { type AgentConfig, type AuthorizeSessionRequest, type LayercodeAudioInputDevice, listAudioInputDevices, watchAudioInputDevices } from '@layercode/js-sdk'; |
9 | 3 |
|
10 | 4 | /** |
11 | 5 | * Configuration options for the useLayercodeAgent hook. |
@@ -333,27 +327,24 @@ const useLayercodeAgent = ( |
333 | 327 | [_setAudioOutput, clientRef, audioOutput] |
334 | 328 | ); |
335 | 329 |
|
336 | | - const selectInputDevice = useCallback( |
337 | | - async (deviceId: string | null) => { |
338 | | - const normalized = normalizeDeviceId(deviceId); |
339 | | - setPreferredInputDeviceId(normalized); |
340 | | - preferredInputDeviceRef.current = normalized; |
341 | | - setInputDeviceListError(null); |
| 330 | + const selectInputDevice = useCallback(async (deviceId: string | null) => { |
| 331 | + const normalized = normalizeDeviceId(deviceId); |
| 332 | + setPreferredInputDeviceId(normalized); |
| 333 | + preferredInputDeviceRef.current = normalized; |
| 334 | + setInputDeviceListError(null); |
342 | 335 |
|
343 | | - if (!clientRef.current) { |
344 | | - return; |
345 | | - } |
| 336 | + if (!clientRef.current) { |
| 337 | + return; |
| 338 | + } |
346 | 339 |
|
347 | | - try { |
348 | | - await clientRef.current.setPreferredInputDevice(normalized); |
349 | | - } catch (error) { |
350 | | - const message = error instanceof Error ? error.message : 'Unable to switch microphone'; |
351 | | - setInputDeviceListError(message); |
352 | | - throw error; |
353 | | - } |
354 | | - }, |
355 | | - [] |
356 | | - ); |
| 340 | + try { |
| 341 | + await clientRef.current.setPreferredInputDevice(normalized); |
| 342 | + } catch (error) { |
| 343 | + const message = error instanceof Error ? error.message : 'Unable to switch microphone'; |
| 344 | + setInputDeviceListError(message); |
| 345 | + throw error; |
| 346 | + } |
| 347 | + }, []); |
357 | 348 |
|
358 | 349 | const triggerUserTurnStarted = useCallback(() => { |
359 | 350 | clientRef.current?.triggerUserTurnStarted(); |
@@ -521,9 +512,7 @@ const MicrophoneSelect = ({ |
521 | 512 |
|
522 | 513 | {inputDeviceListError ? <div className="layercode-mic-select__error">{inputDeviceListError}</div> : null} |
523 | 514 |
|
524 | | - {!isInputDeviceListLoading && !inputDeviceListError && !hasDevices ? ( |
525 | | - <div className="layercode-mic-select__helper">{emptyLabel}</div> |
526 | | - ) : null} |
| 515 | + {!isInputDeviceListLoading && !inputDeviceListError && !hasDevices ? <div className="layercode-mic-select__helper">{emptyLabel}</div> : null} |
527 | 516 |
|
528 | 517 | {helperText ? <div className="layercode-mic-select__helper">{helperText}</div> : null} |
529 | 518 | </div> |
|
0 commit comments