Skip to content

Commit

Permalink
Fixed demo audio/video config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
devopvoid committed Dec 18, 2020
1 parent af058e8 commit 86bd776
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion webrtc-demo/webrtc-demo-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
<version>5.0.0-BETA-1</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public class Configuration {
/** The locale of the application. */
private final ObjectProperty<Locale> locale;

private AudioConfiguration audioConfig;
private final AudioConfiguration audioConfig;

private VideoConfiguration videoConfig;
private final VideoConfiguration videoConfig;

private DesktopCaptureConfiguration desktopCaptureConfig;
private final DesktopCaptureConfiguration desktopCaptureConfig;

private RTCConfiguration rtcConfig;
private final RTCConfiguration rtcConfig;


public Configuration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import dev.onvoid.webrtc.demo.model.Contact;
import dev.onvoid.webrtc.demo.model.message.ChatMessage;
import dev.onvoid.webrtc.demo.net.codec.JsonBCodec;
import dev.onvoid.webrtc.media.MediaSource.State;
import dev.onvoid.webrtc.media.MediaStreamTrack;
import dev.onvoid.webrtc.media.audio.AudioOptions;
import dev.onvoid.webrtc.media.audio.AudioSource;
Expand Down Expand Up @@ -74,7 +73,7 @@

public class PeerConnectionClient implements PeerConnectionObserver {

private static Logger LOGGER = System.getLogger(PeerConnectionClient.class.getName());
private static final Logger LOGGER = System.getLogger(PeerConnectionClient.class.getName());

private final ExecutorService executor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package dev.onvoid.webrtc.demo.presenter;

import static java.util.Objects.isNull;

import dev.onvoid.webrtc.demo.config.AudioConfiguration;
import dev.onvoid.webrtc.demo.config.Configuration;
import dev.onvoid.webrtc.demo.view.AudioSettingsView;
Expand Down Expand Up @@ -58,9 +60,13 @@ public void initialize() {
}

private AudioDevice getAudioDevice(List<AudioDevice> devices, AudioDevice device) {
return devices.stream()
AudioDevice audioDevice = devices.stream()
.filter(dev -> dev.equals(device))
.findFirst()
.orElse(devices.get(0));
.orElse(null);

return isNull(audioDevice) ?
!devices.isEmpty() ? devices.get(0) : null :
audioDevice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class StartPresenter extends Presenter<StartView> {

private final PeerConnectionService peerConnectionService;

private ResourceBundle resources;
private final ResourceBundle resources;

private Room room;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ public void initialize() {
var devices = MediaDevices.getVideoCaptureDevices();
var device = config.getCaptureDevice();

int devIndex = devices.indexOf(device);
device = (devIndex < 0) ? devices.get(0) : devices.get(devIndex);
if (!devices.isEmpty()) {
int devIndex = devices.indexOf(device);
device = (devIndex < 0) ? devices.get(0) : devices.get(devIndex);

var capabilities = MediaDevices.getVideoCaptureCapabilities(device);
capabilities.sort(new VideoCaptureCapabilityComparator());
var capability = getCaptureCapability(capabilities);
var capabilities = MediaDevices.getVideoCaptureCapabilities(device);
capabilities.sort(new VideoCaptureCapabilityComparator());
var capability = getCaptureCapability(capabilities);

config.setCaptureDevice(device);
config.setCaptureCapability(capability);
config.setCaptureDevice(device);
config.setCaptureCapability(capability);

view.setVideoCaptureCapabilities(capabilities);
view.setVideoCaptureCapability(config.captureCapabilityProperty());
}

config.captureDeviceProperty().addListener((observable, oldDevice, newDevice) -> {
onVideoCaptureDevice(newDevice);
});

view.setVideoDevices(devices);
view.setVideoDevice(config.captureDeviceProperty());
view.setVideoCaptureCapabilities(capabilities);
view.setVideoCaptureCapability(config.captureCapabilityProperty());
view.setReceiveVideo(config.receiveVideoProperty());
view.setSendVideo(config.sendVideoProperty());
}
Expand Down

0 comments on commit 86bd776

Please sign in to comment.