Skip to content

Commit 522bfbd

Browse files
committed
fix: keep device changes during startup and surface failed device queries
Register the device listener before the first snapshot and serialize the reads, so a change during startup is no longer lost. Only the native layer's plain Error counts as "no such devices"; other query failures throw a MediaException, and JVM errors pass through. switchDevice keeps the refusal and restart failures as suppressed instead of letting one hide another.
1 parent 8665683 commit 522bfbd

5 files changed

Lines changed: 552 additions & 39 deletions

File tree

‎docs/guide/client-api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ The new camera keeps the resolution and frame rate of the old one, as far as it
468468

469469
### Devices
470470

471-
`media.devices()` returns the cameras, microphones and speakers. The first call reads them from the system; after that, the lists are snapshots kept current in the background, so reading them is cheap on any thread. `screens()` and `windows()` ask the system on each call.
471+
`media.devices()` returns the cameras, microphones and speakers. The first call reads them from the system; after that, the lists are snapshots kept current in the background, so reading them is cheap on any thread. `screens()` and `windows()` ask the system on each call. A kind of device the system cannot list, such as audio devices on a machine without an audio system, comes back as an empty list; a query that fails otherwise throws a `MediaException`, so an empty list means there are no such devices.
472472

473473
```java
474474
Devices devices = media.devices();

‎webrtc/src/main/java/dev/onvoid/webrtc/client/Devices.java‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,30 @@
2929
* the background, so reading them is cheap on any thread. Where the system
3030
* reports no device changes, as a Linux machine without PulseAudio, they are
3131
* read on each call. A kind of device the system cannot list, such as audio
32-
* devices without an audio system, comes back as an empty list.
32+
* devices without an audio system, comes back as an empty list. A query that
33+
* fails otherwise throws a {@link MediaException}, so that an empty list means
34+
* that there are no such devices.
3335
*/
3436
public interface Devices {
3537

3638
/**
3739
* @return the cameras.
40+
*
41+
* @throws MediaException if the cameras could not be read.
3842
*/
3943
List<VideoDevice> cameras();
4044

4145
/**
4246
* @return the microphones.
47+
*
48+
* @throws MediaException if the microphones could not be read.
4349
*/
4450
List<AudioDevice> microphones();
4551

4652
/**
4753
* @return the speakers.
54+
*
55+
* @throws MediaException if the speakers could not be read.
4856
*/
4957
List<AudioDevice> speakers();
5058

0 commit comments

Comments
 (0)