[freeboxos] Better fix for WEB socket registration (#17236)

* Checks if the server supports VM.

Replace #17124 which was more a workaround.

* Change default value

The value is always set when calling openSession.

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2024-08-13 10:43:24 +02:00 committed by GitHub
parent 73a3f151c9
commit 858be48183
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 15 deletions

View File

@ -52,6 +52,8 @@ public class FreeboxOsSession {
private @Nullable Session session; private @Nullable Session session;
private String appToken = ""; private String appToken = "";
private int wsReconnectInterval; private int wsReconnectInterval;
@Nullable
private Boolean vmSupported;
public enum BoxModel { public enum BoxModel {
FBXGW_R1_FULL, // Freebox Server (v6) revision 1 FBXGW_R1_FULL, // Freebox Server (v6) revision 1
@ -85,7 +87,9 @@ public class FreeboxOsSession {
ApiVersion.class, null, null); ApiVersion.class, null, null);
this.uriBuilder = config.getUriBuilder(version.baseUrl()); this.uriBuilder = config.getUriBuilder(version.baseUrl());
this.wsReconnectInterval = config.wsReconnectInterval; this.wsReconnectInterval = config.wsReconnectInterval;
this.vmSupported = null;
getManager(LoginManager.class); getManager(LoginManager.class);
getManager(SystemManager.class);
getManager(NetShareManager.class); getManager(NetShareManager.class);
getManager(LanManager.class); getManager(LanManager.class);
getManager(WifiManager.class); getManager(WifiManager.class);
@ -95,9 +99,13 @@ public class FreeboxOsSession {
public void openSession(String appToken) throws FreeboxException { public void openSession(String appToken) throws FreeboxException {
Session newSession = getManager(LoginManager.class).openSession(appToken); Session newSession = getManager(LoginManager.class).openSession(appToken);
getManager(WebSocketManager.class).openSession(newSession.sessionToken(), wsReconnectInterval);
session = newSession; session = newSession;
this.appToken = appToken; this.appToken = appToken;
if (vmSupported == null) {
vmSupported = getManager(SystemManager.class).getConfig().modelInfo().hasVm();
}
getManager(WebSocketManager.class).openSession(newSession.sessionToken(), wsReconnectInterval,
Boolean.TRUE.equals(vmSupported));
} }
public String grant() throws FreeboxException { public String grant() throws FreeboxException {

View File

@ -73,8 +73,7 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
@Nullable @Nullable
private String sessionToken; private String sessionToken;
private int reconnectInterval; private int reconnectInterval;
private boolean vmSupported = true; private boolean vmSupported;
private boolean retryConnectWithoutVm = false;
private record Register(String action, List<String> events) { private record Register(String action, List<String> events) {
Register(String... events) { Register(String... events) {
@ -101,9 +100,10 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
} }
} }
public void openSession(@Nullable String sessionToken, int reconnectInterval) { public void openSession(@Nullable String sessionToken, int reconnectInterval, boolean vmSupported) {
this.sessionToken = sessionToken; this.sessionToken = sessionToken;
this.reconnectInterval = reconnectInterval; this.reconnectInterval = reconnectInterval;
this.vmSupported = vmSupported;
if (reconnectInterval > 0) { if (reconnectInterval > 0) {
try { try {
client.start(); client.start();
@ -190,12 +190,6 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
default: default:
logger.warn("Unhandled notification received: {}", result.action); logger.warn("Unhandled notification received: {}", result.action);
} }
} else if (result.action == Action.REGISTER) {
logger.debug("Event registration failed!");
if (vmSupported && "unsupported event vm_state_changed".equals(result.msg)) {
vmSupported = false;
retryConnectWithoutVm = true;
}
} }
} }
@ -233,11 +227,6 @@ public class WebSocketManager extends RestManager implements WebSocketListener {
public void onWebSocketClose(int statusCode, @NonNullByDefault({}) String reason) { public void onWebSocketClose(int statusCode, @NonNullByDefault({}) String reason) {
logger.debug("Socket Closed: [{}] - reason {}", statusCode, reason); logger.debug("Socket Closed: [{}] - reason {}", statusCode, reason);
this.wsSession = null; this.wsSession = null;
if (retryConnectWithoutVm) {
logger.debug("Retry connecting websocket client without VM support");
retryConnectWithoutVm = false;
startReconnect();
}
} }
@Override @Override