Browse Source

Post event when a participant is connected and disconnected

RTCPeerConnections have several states but, for simplicity, for now the
events posted reflect only if the connection is fully established or
not (which includes both a broken connection or an established
connection that is unstable or being updated), which is enough for a
basic information about the connection state in the UI.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Daniel Calviño Sánchez 2 years ago
parent
commit
9f445efc1c

+ 1 - 1
app/src/main/java/com/nextcloud/talk/events/PeerConnectionEvent.java

@@ -120,6 +120,6 @@ public class PeerConnectionEvent {
     }
 
     public enum PeerConnectionEventType {
-        PEER_CONNECTED, PEER_CLOSED, SENSOR_FAR, SENSOR_NEAR, NICK_CHANGE, AUDIO_CHANGE, VIDEO_CHANGE, PUBLISHER_FAILED
+        PEER_CONNECTED, PEER_DISCONNECTED, PEER_CLOSED, SENSOR_FAR, SENSOR_NEAR, NICK_CHANGE, AUDIO_CHANGE, VIDEO_CHANGE, PUBLISHER_FAILED
     }
 }

+ 12 - 1
app/src/main/java/com/nextcloud/talk/webrtc/PeerConnectionWrapper.java

@@ -344,6 +344,8 @@ public class PeerConnectionWrapper {
 
             Log.d("iceConnectionChangeTo: ", iceConnectionState.name() + " over " + peerConnection.hashCode() + " " + sessionId);
             if (iceConnectionState.equals(PeerConnection.IceConnectionState.CONNECTED)) {
+                EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType.PEER_CONNECTED,
+                                                                   sessionId, null, null, null));
 
                 if (!isMCUPublisher) {
                     EventBus.getDefault().post(new MediaStreamEvent(remoteStream, sessionId, videoStreamType));
@@ -352,11 +354,20 @@ public class PeerConnectionWrapper {
                 if (hasInitiated) {
                     sendInitialMediaStatus();
                 }
-
+            } else if (iceConnectionState.equals(PeerConnection.IceConnectionState.COMPLETED)) {
+                EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType.PEER_CONNECTED,
+                                                                   sessionId, null, null, null));
             } else if (iceConnectionState.equals(PeerConnection.IceConnectionState.CLOSED)) {
                 EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
                         .PEER_CLOSED, sessionId, null, null, videoStreamType));
+            } else if (iceConnectionState.equals(PeerConnection.IceConnectionState.DISCONNECTED) ||
+                    iceConnectionState.equals(PeerConnection.IceConnectionState.NEW) ||
+                    iceConnectionState.equals(PeerConnection.IceConnectionState.CHECKING)) {
+                EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType.PEER_DISCONNECTED,
+                                                                   sessionId, null, null, null));
             } else if (iceConnectionState.equals(PeerConnection.IceConnectionState.FAILED)) {
+                EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType.PEER_DISCONNECTED,
+                                                                   sessionId, null, null, null));
                 if (isMCUPublisher) {
                     EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType.PUBLISHER_FAILED, sessionId, null, null, null));
                 }