Skip to content

Commit f6baac8

Browse files
committed
1 parent 2d7c4c7 commit f6baac8

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

src/main/java/net/twasi/obsremotejava/OBSCommunicator.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.gson.JsonObject;
66
import com.google.gson.JsonParser;
77
import net.twasi.obsremotejava.events.EventType;
8+
import net.twasi.obsremotejava.events.responses.SwitchScenesResponse;
89
import net.twasi.obsremotejava.requests.GetAuthRequired.GetAuthRequiredRequest;
910
import net.twasi.obsremotejava.requests.GetAuthRequired.GetAuthRequiredResponse;
1011
import net.twasi.obsremotejava.requests.GetCurrentProfile.GetCurrentProfileRequest;
@@ -95,6 +96,7 @@ public class OBSCommunicator {
9596
private Callback onReplayStarting;
9697
private Callback onReplayStopped;
9798
private Callback onReplayStopping;
99+
private Callback onSwitchScenes;
98100

99101
private GetVersionResponse versionInfo;
100102

@@ -111,8 +113,6 @@ public void await() throws InterruptedException {
111113
this.closeLatch.await();
112114
}
113115

114-
;
115-
116116
@OnWebSocketClose
117117
public void onClose(int statusCode, String reason) {
118118
System.out.printf("Connection closed: %d - %s%n", statusCode, reason);
@@ -200,6 +200,11 @@ public void onMessage(String msg) {
200200
if (onReplayStopping != null)
201201
onReplayStopping.run(null);
202202
break;
203+
case SwitchScenes:
204+
if (onSwitchScenes != null) {
205+
onSwitchScenes.run(new Gson().fromJson(msg, SwitchScenesResponse.class));
206+
}
207+
break;
203208
}
204209
}
205210
} catch (Exception e) {
@@ -231,6 +236,10 @@ public void registerOnReplayStopping(Callback onReplayStopping) {
231236
this.onReplayStopping = onReplayStopping;
232237
}
233238

239+
public void registerOnSwitchScenes(Callback onSwitchScenes) {
240+
this.onSwitchScenes = onSwitchScenes;
241+
}
242+
234243
public void getScenes(Callback callback) {
235244
session.getRemote().sendStringByFuture(new Gson().toJson(new GetSceneListRequest(this)));
236245
callbacks.put(GetSceneListResponse.class, callback);

src/main/java/net/twasi/obsremotejava/OBSRemoteController.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ public void registerReplayStoppingCallback(Callback onReplayStopping) {
9595
communicator.registerOnReplayStopping(onReplayStopping);
9696
}
9797

98+
public void registerSwitchScenesCallback(Callback onSwitchScenes) {
99+
communicator.registerOnSwitchScenes(onSwitchScenes);
100+
}
101+
98102
public void await() throws InterruptedException {
99103
communicator.await();
100104
}

src/main/java/net/twasi/obsremotejava/events/EventType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public enum EventType {
44
ReplayStarting,
55
ReplayStarted,
66
ReplayStopping,
7-
ReplayStopped
7+
ReplayStopped,
8+
SwitchScenes
89
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package net.twasi.obsremotejava.events.responses;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import net.twasi.obsremotejava.objects.Source;
5+
import net.twasi.obsremotejava.requests.ResponseBase;
6+
7+
import java.util.List;
8+
9+
public class SwitchScenesResponse extends ResponseBase {
10+
@SerializedName("scene-name")
11+
private String sceneName;
12+
private List<Source> sources;
13+
14+
public String getSceneName() {
15+
return sceneName;
16+
}
17+
18+
public List<Source> getSources() {
19+
return sources;
20+
}
21+
}

src/test/java/net/twasi/obsremotejava/test/OBSRemoteControllerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.twasi.obsremotejava.Callback;
44
import net.twasi.obsremotejava.OBSRemoteController;
5+
import net.twasi.obsremotejava.events.responses.SwitchScenesResponse;
56
import net.twasi.obsremotejava.requests.GetVersion.GetVersionResponse;
67
import net.twasi.obsremotejava.requests.ResponseBase;
78
import org.junit.jupiter.api.Test;
@@ -236,6 +237,12 @@ public void run(ResponseBase response) {
236237
/* controller.setStudioModeEnabled(false, res -> {
237238
System.out.println("Done");
238239
}); */
240+
241+
242+
controller.registerSwitchScenesCallback(res -> {
243+
SwitchScenesResponse switchScenesResponse = (SwitchScenesResponse) res;
244+
System.out.println("Switched to scene: " + switchScenesResponse.getSceneName());
245+
});
239246
}
240247
});
241248

0 commit comments

Comments
 (0)