Add DisconnectListener
This commit is contained in:
parent
3baa9ce1e2
commit
4b0ec70f54
@ -0,0 +1,7 @@
|
||||
package me.mrletsplay.shareclientcore.connection;
|
||||
|
||||
public interface DisconnectListener {
|
||||
|
||||
public void onDisconnect(String reason, boolean remote);
|
||||
|
||||
}
|
@ -34,4 +34,9 @@ public class DummyConnection implements RemoteConnection {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisconnectListener(DisconnectListener listener) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,4 +21,6 @@ public interface RemoteConnection {
|
||||
|
||||
public void removeListener(MessageListener listener);
|
||||
|
||||
public void setDisconnectListener(DisconnectListener listener);
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public class WebSocketConnection implements RemoteConnection {
|
||||
private WSClient client;
|
||||
private String username;
|
||||
private Set<MessageListener> listeners;
|
||||
private DisconnectListener disconnectListener;
|
||||
private int siteID;
|
||||
|
||||
private Object wait = new Object();
|
||||
@ -90,6 +91,11 @@ public class WebSocketConnection implements RemoteConnection {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisconnectListener(DisconnectListener listener) {
|
||||
this.disconnectListener = listener;
|
||||
}
|
||||
|
||||
private class WSClient extends WebSocketClient {
|
||||
|
||||
public WSClient(URI serverUri) {
|
||||
@ -138,7 +144,7 @@ public class WebSocketConnection implements RemoteConnection {
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
// TODO: handle
|
||||
if(disconnectListener != null) disconnectListener.onDisconnect("WebSocket disconnected (" + code + "): " + reason, remote);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,4 +57,9 @@ public record Char(Identifier[] position, int lamport, char value) implements Se
|
||||
return new Char(pos, lamport, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Char [position=" + Arrays.toString(position) + ", lamport=" + lamport + ", value=" + value + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user