Skip to content

Commit

Permalink
demo: bind transceiver direction to the configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
devopvoid committed Dec 18, 2020
1 parent 86bd776 commit 61cce45
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public BooleanProperty receiveAudioProperty() {
return receiveAudio;
}

public boolean getAudioVideo() {
public boolean getReceiveAudio() {
return receiveAudio.get();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import dev.onvoid.webrtc.RTCSdpType;
import dev.onvoid.webrtc.RTCSessionDescription;
import dev.onvoid.webrtc.RTCStatsReport;
import dev.onvoid.webrtc.demo.config.AudioConfiguration;
import dev.onvoid.webrtc.demo.config.Configuration;
import dev.onvoid.webrtc.demo.config.VideoConfiguration;
import dev.onvoid.webrtc.demo.model.Contact;
import dev.onvoid.webrtc.demo.model.ContactEventType;
import dev.onvoid.webrtc.demo.model.Contacts;
Expand Down Expand Up @@ -75,14 +77,39 @@ public class PeerConnectionService implements SignalingListener {

connections = new HashMap<>();

final AudioConfiguration audioConfig = config.getAudioConfiguration();
final VideoConfiguration videoConfig = config.getVideoConfiguration();

peerConnectionContext = new PeerConnectionContext();
peerConnectionContext.audioDirection = RTCRtpTransceiverDirection.SEND_RECV;
peerConnectionContext.videoDirection = RTCRtpTransceiverDirection.SEND_RECV;
peerConnectionContext.audioDirection = getDirection(
audioConfig.getReceiveAudio(), audioConfig.getSendAudio());
peerConnectionContext.videoDirection = getDirection(
videoConfig.getReceiveVideo(), videoConfig.getSendVideo());

audioConfig.receiveAudioProperty()
.addListener((observable, oldValue, newValue) -> {
peerConnectionContext.audioDirection = getDirection(
newValue, audioConfig.getSendAudio());
});
audioConfig.sendAudioProperty()
.addListener((observable, oldValue, newValue) -> {
peerConnectionContext.audioDirection = getDirection(
audioConfig.getReceiveAudio(), newValue);
});
videoConfig.receiveVideoProperty()
.addListener((observable, oldValue, newValue) -> {
peerConnectionContext.videoDirection = getDirection(
newValue, videoConfig.getSendVideo());
});
videoConfig.sendVideoProperty()
.addListener((observable, oldValue, newValue) -> {
peerConnectionContext.videoDirection = getDirection(
videoConfig.getReceiveVideo(), newValue);
});
}

@Override
public void onRoomJoined(RoomParameters parameters) {
peerConnectionContext.videoDirection = RTCRtpTransceiverDirection.SEND_RECV;
activeContact = new Contact();

config.getRTCConfig().iceServers.clear();
Expand Down Expand Up @@ -338,4 +365,17 @@ private PeerConnectionClient createPeerConnection(Contact contact) {
return peerConnectionClient;
}

private RTCRtpTransceiverDirection getDirection(boolean receive, boolean send) {
if (receive && send) {
return RTCRtpTransceiverDirection.SEND_RECV;
}
else if (receive) {
return RTCRtpTransceiverDirection.RECV_ONLY;
}
else if (send) {
return RTCRtpTransceiverDirection.SEND_ONLY;
}

throw new IllegalArgumentException();
}
}

0 comments on commit 61cce45

Please sign in to comment.