improve user disconnection detection
This commit is contained in:
parent
f762128922
commit
75ec382fb7
2 changed files with 13 additions and 16 deletions
|
@ -1,6 +1,7 @@
|
|||
package fr.insa.clavardator.ui.users;
|
||||
|
||||
import fr.insa.clavardator.users.PeerUser;
|
||||
import fr.insa.clavardator.util.Log;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.shape.Circle;
|
||||
|
@ -20,20 +21,20 @@ public class UserActiveIndicatorController implements Initializable {
|
|||
|
||||
}
|
||||
|
||||
private void updateState() {
|
||||
if (user != null) {
|
||||
private void updateState(boolean isActive) {
|
||||
circle.getStyleClass().clear();
|
||||
if (user.isActive()) {
|
||||
if (isActive) {
|
||||
circle.getStyleClass().add("active-user-dot");
|
||||
} else {
|
||||
circle.getStyleClass().add("inactive-user-dot");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onStateChange(PropertyChangeEvent propertyChangeEvent) {
|
||||
if (propertyChangeEvent.getPropertyName().equals("state")) {
|
||||
updateState();
|
||||
final PeerUser.State newState = (PeerUser.State) propertyChangeEvent.getNewValue();
|
||||
Log.v(this.getClass().getSimpleName(), "User state updated to " + newState.toString());
|
||||
updateState(newState == PeerUser.State.CONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ public class UserActiveIndicatorController implements Initializable {
|
|||
}
|
||||
this.user = user;
|
||||
user.addObserver(this::onStateChange);
|
||||
updateState();
|
||||
updateState(user.isActive());
|
||||
}
|
||||
|
||||
public void setSize(double value) {
|
||||
|
|
|
@ -129,10 +129,10 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
}
|
||||
},
|
||||
e -> {
|
||||
Log.e(this.getClass().getSimpleName(), "Error receiving message from " + id, e);
|
||||
if (e instanceof EOFException) {
|
||||
disconnect();
|
||||
} else {
|
||||
Log.e(this.getClass().getSimpleName(), "Error receiving message from " + id, e);
|
||||
errorCallback.onError(e);
|
||||
}
|
||||
});
|
||||
|
@ -158,10 +158,6 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
return history;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
private void setState(State state) {
|
||||
pcs.firePropertyChange("state", this.state, state);
|
||||
this.state = state;
|
||||
|
@ -181,7 +177,7 @@ public class PeerUser extends User implements Comparable<PeerUser> {
|
|||
return getUsername().compareTo(peerUser.getUsername());
|
||||
}
|
||||
|
||||
enum State {
|
||||
public enum State {
|
||||
CONNECTING,
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
|
|
Loading…
Reference in a new issue