|
25 | 25 | import dev.onvoid.webrtc.RTCSdpType; |
26 | 26 | import dev.onvoid.webrtc.RTCSessionDescription; |
27 | 27 | import dev.onvoid.webrtc.RTCStatsReport; |
| 28 | +import dev.onvoid.webrtc.demo.config.AudioConfiguration; |
28 | 29 | import dev.onvoid.webrtc.demo.config.Configuration; |
| 30 | +import dev.onvoid.webrtc.demo.config.VideoConfiguration; |
29 | 31 | import dev.onvoid.webrtc.demo.model.Contact; |
30 | 32 | import dev.onvoid.webrtc.demo.model.ContactEventType; |
31 | 33 | import dev.onvoid.webrtc.demo.model.Contacts; |
@@ -75,14 +77,39 @@ public class PeerConnectionService implements SignalingListener { |
75 | 77 |
|
76 | 78 | connections = new HashMap<>(); |
77 | 79 |
|
| 80 | + final AudioConfiguration audioConfig = config.getAudioConfiguration(); |
| 81 | + final VideoConfiguration videoConfig = config.getVideoConfiguration(); |
| 82 | + |
78 | 83 | peerConnectionContext = new PeerConnectionContext(); |
79 | | - peerConnectionContext.audioDirection = RTCRtpTransceiverDirection.SEND_RECV; |
80 | | - peerConnectionContext.videoDirection = RTCRtpTransceiverDirection.SEND_RECV; |
| 84 | + peerConnectionContext.audioDirection = getDirection( |
| 85 | + audioConfig.getReceiveAudio(), audioConfig.getSendAudio()); |
| 86 | + peerConnectionContext.videoDirection = getDirection( |
| 87 | + videoConfig.getReceiveVideo(), videoConfig.getSendVideo()); |
| 88 | + |
| 89 | + audioConfig.receiveAudioProperty() |
| 90 | + .addListener((observable, oldValue, newValue) -> { |
| 91 | + peerConnectionContext.audioDirection = getDirection( |
| 92 | + newValue, audioConfig.getSendAudio()); |
| 93 | + }); |
| 94 | + audioConfig.sendAudioProperty() |
| 95 | + .addListener((observable, oldValue, newValue) -> { |
| 96 | + peerConnectionContext.audioDirection = getDirection( |
| 97 | + audioConfig.getReceiveAudio(), newValue); |
| 98 | + }); |
| 99 | + videoConfig.receiveVideoProperty() |
| 100 | + .addListener((observable, oldValue, newValue) -> { |
| 101 | + peerConnectionContext.videoDirection = getDirection( |
| 102 | + newValue, videoConfig.getSendVideo()); |
| 103 | + }); |
| 104 | + videoConfig.sendVideoProperty() |
| 105 | + .addListener((observable, oldValue, newValue) -> { |
| 106 | + peerConnectionContext.videoDirection = getDirection( |
| 107 | + videoConfig.getReceiveVideo(), newValue); |
| 108 | + }); |
81 | 109 | } |
82 | 110 |
|
83 | 111 | @Override |
84 | 112 | public void onRoomJoined(RoomParameters parameters) { |
85 | | - peerConnectionContext.videoDirection = RTCRtpTransceiverDirection.SEND_RECV; |
86 | 113 | activeContact = new Contact(); |
87 | 114 |
|
88 | 115 | config.getRTCConfig().iceServers.clear(); |
@@ -338,4 +365,17 @@ private PeerConnectionClient createPeerConnection(Contact contact) { |
338 | 365 | return peerConnectionClient; |
339 | 366 | } |
340 | 367 |
|
| 368 | + private RTCRtpTransceiverDirection getDirection(boolean receive, boolean send) { |
| 369 | + if (receive && send) { |
| 370 | + return RTCRtpTransceiverDirection.SEND_RECV; |
| 371 | + } |
| 372 | + else if (receive) { |
| 373 | + return RTCRtpTransceiverDirection.RECV_ONLY; |
| 374 | + } |
| 375 | + else if (send) { |
| 376 | + return RTCRtpTransceiverDirection.SEND_ONLY; |
| 377 | + } |
| 378 | + |
| 379 | + throw new IllegalArgumentException(); |
| 380 | + } |
341 | 381 | } |
0 commit comments