Magical sensor stuff

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2017-12-09 20:11:51 +01:00
parent 00cb0869de
commit fdaa69f489
4 changed files with 44 additions and 4 deletions

View File

@ -777,7 +777,26 @@ public class CallActivity extends AppCompatActivity {
@Subscribe(threadMode = ThreadMode.BACKGROUND) @Subscribe(threadMode = ThreadMode.BACKGROUND)
public void onMessageEvent(PeerConnectionEvent peerConnectionEvent) { public void onMessageEvent(PeerConnectionEvent peerConnectionEvent) {
endPeerConnection(peerConnectionEvent.getSessionId()); if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent.PeerConnectionEventType
.CLOSE_PEER)) {
endPeerConnection(peerConnectionEvent.getSessionId());
} else if (peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent
.PeerConnectionEventType.SENSOR_FAR) ||
peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent
.PeerConnectionEventType.SENSOR_NEAR)) {
/*boolean enableVideo = peerConnectionEvent.getPeerConnectionEventType().equals(PeerConnectionEvent
.PeerConnectionEventType.SENSOR_FAR);
String videoMessage = "videoOff";
if (enableVideo) {
videoMessage = "videoOn";
}
localMediaStream.videoTracks.get(0).setEnabled(enableVideo);
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) {
magicPeerConnectionWrapperList.get(i).sendChannelData(new DataChannelMessage(videoMessage));
}*/
}
} }
private void endPeerConnection(String sessionId) { private void endPeerConnection(String sessionId) {

View File

@ -20,13 +20,21 @@
package com.nextcloud.talk.events; package com.nextcloud.talk.events;
import android.support.annotation.Nullable;
import lombok.Data; import lombok.Data;
@Data @Data
public class PeerConnectionEvent { public class PeerConnectionEvent {
public enum PeerConnectionEventType {
CLOSE_PEER, SENSOR_FAR, SENSOR_NEAR
}
private final PeerConnectionEventType peerConnectionEventType;
private final String sessionId; private final String sessionId;
public PeerConnectionEvent(String sessionId) { public PeerConnectionEvent(PeerConnectionEventType peerConnectionEventType, @Nullable String sessionId) {
this.peerConnectionEventType = peerConnectionEventType;
this.sessionId = sessionId; this.sessionId = sessionId;
} }
} }

View File

@ -41,6 +41,9 @@ import android.media.AudioManager;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import com.nextcloud.talk.events.PeerConnectionEvent;
import org.greenrobot.eventbus.EventBus;
import org.webrtc.ThreadUtils; import org.webrtc.ThreadUtils;
import java.util.Collections; import java.util.Collections;
@ -137,6 +140,15 @@ public class MagicAudioManager {
* e.g. from "NEAR to FAR" or from "FAR to NEAR". * e.g. from "NEAR to FAR" or from "FAR to NEAR".
*/ */
private void onProximitySensorChangedState() { private void onProximitySensorChangedState() {
if (proximitySensor.sensorReportsNearState()) {
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
.SENSOR_NEAR, null));
} else {
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
.SENSOR_FAR, null));
}
if (!useSpeakerphone.equals(SPEAKERPHONE_AUTO)) { if (!useSpeakerphone.equals(SPEAKERPHONE_AUTO)) {
return; return;
} }

View File

@ -111,7 +111,7 @@ public class MagicPeerConnectionWrapper {
} }
} }
private void sendChannelData(DataChannelMessage dataChannelMessage) { public void sendChannelData(DataChannelMessage dataChannelMessage) {
ByteBuffer buffer = null; ByteBuffer buffer = null;
try { try {
buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes()); buffer = ByteBuffer.wrap(LoganSquare.serialize(dataChannelMessage).getBytes());
@ -184,7 +184,8 @@ public class MagicPeerConnectionWrapper {
@Override @Override
public void onSignalingChange(PeerConnection.SignalingState signalingState) { public void onSignalingChange(PeerConnection.SignalingState signalingState) {
if (signalingState.equals(PeerConnection.SignalingState.CLOSED)) { if (signalingState.equals(PeerConnection.SignalingState.CLOSED)) {
EventBus.getDefault().post(new PeerConnectionEvent(sessionId)); EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
.CLOSE_PEER, sessionId));
} }
} }