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)
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) {

View File

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

View File

@ -41,6 +41,9 @@ import android.media.AudioManager;
import android.os.Build;
import android.util.Log;
import com.nextcloud.talk.events.PeerConnectionEvent;
import org.greenrobot.eventbus.EventBus;
import org.webrtc.ThreadUtils;
import java.util.Collections;
@ -137,6 +140,15 @@ public class MagicAudioManager {
* e.g. from "NEAR to FAR" or from "FAR to NEAR".
*/
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)) {
return;
}

View File

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