Skip to content

Commit 7fa95da

Browse files
author
Niels van de Weem
committed
#22 - Reconnect to OBS less often
1 parent f374169 commit 7fa95da

File tree

1 file changed

+9
-4
lines changed
  • src/main/java/com/getpcpanel/obs

1 file changed

+9
-4
lines changed

src/main/java/com/getpcpanel/obs/OBS.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private void applicationEnding() {
7676

7777
private void buildAndConnectObsController() {
7878
var save = this.save.get();
79-
if (!save.isObsEnabled() || connected || shuttingDown) {
79+
if (!save.isObsEnabled() || (connected && !settingsStillSame(false)) || shuttingDown) {
8080
log.trace("Obs is disabled({})/already connected({})/we are shutting down({})", save.isObsEnabled(), connected, shuttingDown);
8181
disconnectController();
8282
return;
@@ -94,7 +94,10 @@ private void buildAndConnectObsController() {
9494
private void doBuildAndConnectObsController() {
9595
var save = this.save.get();
9696
log.debug("Connecting to OBS");
97-
if (settingsStillSame() && controller != null) {
97+
if (settingsStillSame(true) && controller != null) {
98+
if (connected) {
99+
return;
100+
}
98101
connected = true;
99102
controller.connect();
100103
return;
@@ -197,15 +200,17 @@ private void onError(ReasonThrowable reasonThrowable) {
197200
connected = false;
198201
}
199202

200-
private boolean settingsStillSame() {
203+
private boolean settingsStillSame(boolean updatePrevious) {
201204
var port = NumberUtils.toInt(save.get().getObsPort(), -1);
202205
var address = save.get().getObsAddress();
203206
var password = StringUtils.trimToNull(save.get().getObsPassword());
204207
var settings = List.<Object>of(port, Objects.requireNonNullElse(address, "-"), Objects.requireNonNullElse(password, "-"));
205208
if (settings.equals(previousSettings)) {
206209
return true;
207210
}
208-
previousSettings = settings;
211+
if (updatePrevious) {
212+
previousSettings = settings;
213+
}
209214
return false;
210215
}
211216

0 commit comments

Comments
 (0)