Skip to content

Commit 5a41f30

Browse files
committed
feat: Requests and Events
1 parent 0e57416 commit 5a41f30

File tree

43 files changed

+730
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+730
-180
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repositories {
2929

3030
dependencies {
3131
implementation 'org.eclipse.jetty.websocket:websocket-client:9.4.8.v20171121'
32-
implementation 'com.google.code.gson:gson:2.8.2'
32+
implementation 'com.google.code.gson:gson:2.8.6'
3333
implementation 'org.slf4j:slf4j-api:1.7.30'
3434
implementation 'org.slf4j:slf4j-simple:1.7.30'
3535

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

Lines changed: 186 additions & 81 deletions
Large diffs are not rendered by default.

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

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package net.twasi.obsremotejava;
22

3-
import com.google.gson.Gson;
43
import net.twasi.obsremotejava.callbacks.*;
54
import net.twasi.obsremotejava.events.responses.*;
65
import net.twasi.obsremotejava.objects.throwables.OBSResponseError;
76
import net.twasi.obsremotejava.requests.GetCurrentProfile.GetCurrentProfileResponse;
87
import net.twasi.obsremotejava.requests.GetCurrentScene.GetCurrentSceneResponse;
98
import net.twasi.obsremotejava.requests.GetPreviewScene.GetPreviewSceneResponse;
109
import net.twasi.obsremotejava.requests.GetSceneList.GetSceneListResponse;
11-
import net.twasi.obsremotejava.requests.GetSourceFilterInfo.GetSourceFilterInfoRequest;
1210
import net.twasi.obsremotejava.requests.GetSourceFilterInfo.GetSourceFilterInfoResponse;
13-
import net.twasi.obsremotejava.requests.GetSourceFilters.GetSourceFiltersRequest;
1411
import net.twasi.obsremotejava.requests.GetSourceFilters.GetSourceFiltersResponse;
1512
import net.twasi.obsremotejava.requests.GetSourceSettings.GetSourceSettingsResponse;
1613
import net.twasi.obsremotejava.requests.GetStreamingStatus.GetStreamingStatusResponse;
@@ -27,7 +24,6 @@
2724
import net.twasi.obsremotejava.requests.SetMute.SetMuteResponse;
2825
import net.twasi.obsremotejava.requests.SetPreviewScene.SetPreviewSceneResponse;
2926
import net.twasi.obsremotejava.requests.SetSceneItemProperties.SetSceneItemPropertiesResponse;
30-
import net.twasi.obsremotejava.requests.SetSourceFilterVisibility.SetSourceFilterVisibilityRequest;
3127
import net.twasi.obsremotejava.requests.SetSourceFilterVisibility.SetSourceFilterVisibilityResponse;
3228
import net.twasi.obsremotejava.requests.SetSourceSettings.SetSourceSettingsResponse;
3329
import net.twasi.obsremotejava.requests.SetStudioModeEnabled.SetStudioModeEnabledResponse;
@@ -91,7 +87,8 @@ public OBSRemoteController(String address, boolean debug) {
9187
public void connect() {
9288
try {
9389
client.start();
94-
} catch (Exception e) {
90+
}
91+
catch (Exception e) {
9592
runOnError("Failed to start WebSocketClient", e);
9693
return;
9794
}
@@ -104,15 +101,18 @@ public void connect() {
104101
try {
105102
connection.get();
106103
failed = false;
107-
} catch (ExecutionException e) {
104+
}
105+
catch (ExecutionException e) {
108106
if (e.getCause() instanceof ConnectException) {
109107
failed = true;
110108
runOnConnectionFailed("Failed to connect to OBS! Is it running and is the websocket plugin installed?", e);
111-
} else {
109+
}
110+
else {
112111
throw e;
113112
}
114113
}
115-
} catch (Throwable t) {
114+
}
115+
catch (Throwable t) {
116116
runOnConnectionFailed("Failed to setup connection with OBS", t);
117117
}
118118
}
@@ -124,7 +124,8 @@ public void disconnect() {
124124
log.debug("Closing connection.");
125125
}
126126
communicator.awaitClose(1, TimeUnit.SECONDS);
127-
} catch (InterruptedException e) {
127+
}
128+
catch (InterruptedException e) {
128129
runOnError("Error during closing websocket connection", e);
129130
}
130131

@@ -135,7 +136,8 @@ public void disconnect() {
135136
log.debug("Stopping client.");
136137
}
137138
client.stop();
138-
} catch (Exception e) {
139+
}
140+
catch (Exception e) {
139141
runOnError("Error during stopping websocket client", e);
140142
}
141143
}
@@ -231,6 +233,10 @@ public void registerSourceFilterVisibilityChangedCallback(Callback<SourceFilterV
231233
communicator.registerOnSourceFilterVisibilityChanged(onSourceVisibilityChanged);
232234
}
233235

236+
public void registerPreviewSceneChangesCallback(Callback<PreviewSceneChangedResponse> onPreviewSceneChanged) {
237+
communicator.registerOnPreviewSceneChanged(onPreviewSceneChanged);
238+
}
239+
234240
public void await() throws InterruptedException {
235241
communicator.await();
236242
}
@@ -293,6 +299,10 @@ public void setSourceSettings(String sourceName, Map<String, Object> settings, C
293299
communicator.setSourceSettings(sourceName, settings, callback);
294300
}
295301

302+
public void setSourceFilterSettings(String sourceName, String filterName, Map<String, Object> settings, Callback callback) {
303+
communicator.setSourceFilterSettings(sourceName, filterName, settings, callback);
304+
}
305+
296306
public void getStreamingStatus(Callback<GetStreamingStatusResponse> callback) {
297307
communicator.getStreamingStatus(callback);
298308
}
@@ -378,6 +388,42 @@ public void saveReplayBuffer(Callback<SaveReplayBufferResponse> callback) {
378388
communicator.saveReplayBuffer(callback);
379389
}
380390

391+
public void playPauseMedia(String sourceName, Boolean playPause, Callback callback) {
392+
communicator.playPauseMedia(sourceName, playPause, callback);
393+
}
394+
395+
public void restartMedia(String sourceName, Callback callback) {
396+
communicator.restartMedia(sourceName, callback);
397+
}
398+
399+
public void stopMedia(String sourceName, Callback callback) {
400+
communicator.stopMedia(sourceName, callback);
401+
}
402+
403+
public void nextMedia(String sourceName, Callback callback) {
404+
communicator.nextMedia(sourceName, callback);
405+
}
406+
407+
public void previousMedia(String sourceName, Callback callback) {
408+
communicator.previousMedia(sourceName, callback);
409+
}
410+
411+
public void refreshBrowserSource(String sourceName, Callback callback) {
412+
communicator.refreshBrowserSource(sourceName, callback);
413+
}
414+
415+
public void getAudioMonitorType(String sourceName, Callback callback) {
416+
communicator.getAudioMonitorType(sourceName, callback);
417+
}
418+
419+
public void setAudioMonitorType(String sourceName, String monitorType, Callback callback) {
420+
communicator.setAudioMonitorType(sourceName, monitorType, callback);
421+
}
422+
423+
public void getSpecialSources(Callback callback) {
424+
communicator.getSpecialSources(callback);
425+
}
426+
381427
private void runOnError(String message, Throwable throwable) {
382428
log.debug("Running onError with message: " + message + " and exception:", throwable);
383429
if (onError == null) {
@@ -387,7 +433,8 @@ private void runOnError(String message, Throwable throwable) {
387433

388434
try {
389435
onError.run(message, throwable);
390-
} catch (Exception e) {
436+
}
437+
catch (Exception e) {
391438
log.error("Unable to run OnError callback", e);
392439
}
393440
}
@@ -402,9 +449,9 @@ private void runOnConnectionFailed(String message, Throwable throwable) {
402449

403450
try {
404451
onConnectionFailed.run(message);
405-
} catch (Exception e) {
452+
}
453+
catch (Exception e) {
406454
log.error("Unable to run OnConnectionFailed callback", e);
407455
}
408456
}
409-
410457
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ public enum EventType {
1515
SwitchTransition,
1616
TransitionListChanged,
1717
TransitionBegin,
18-
TransitionEnd
18+
TransitionEnd,
19+
PreviewSceneChanged
1920
}
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 PreviewSceneChangedResponse 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+
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package net.twasi.obsremotejava.events.responses;
22

3+
import net.twasi.obsremotejava.objects.Scene;
34
import net.twasi.obsremotejava.requests.ResponseBase;
45

5-
public class ScenesChangedResponse extends ResponseBase {}
6+
import java.util.List;
7+
8+
public class ScenesChangedResponse extends ResponseBase {
9+
private List<Scene> scenes;
10+
11+
public List<Scene> getScenes() {
12+
return scenes;
13+
}
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package net.twasi.obsremotejava.objects;
2+
3+
import com.google.gson.JsonObject;
4+
5+
public class Filter {
6+
private boolean enabled;
7+
private String type;
8+
private String name;
9+
private JsonObject settings;
10+
11+
public boolean isEnabled() {
12+
return enabled;
13+
}
14+
15+
public void setEnabled(boolean enabled) {
16+
this.enabled = enabled;
17+
}
18+
19+
public String getType() {
20+
return type;
21+
}
22+
23+
public void setType(String type) {
24+
this.type = type;
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public void setName(String name) {
32+
this.name = name;
33+
}
34+
35+
public JsonObject getSettings() {
36+
return settings;
37+
}
38+
39+
public void setSettings(JsonObject settings) {
40+
this.settings = settings;
41+
}
42+
}

src/main/java/net/twasi/obsremotejava/objects/Scene.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.twasi.obsremotejava.objects;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
public class Scene {
@@ -13,4 +14,16 @@ public String getName() {
1314
public List<Source> getSources() {
1415
return sources;
1516
}
17+
18+
public List<Source> getAllSources() {
19+
List<Source> allSources = new ArrayList<>();
20+
this.sources.forEach(source -> {
21+
allSources.add(source);
22+
if (source.getGroupChildren() != null && source.getGroupChildren().size() > 0) {
23+
allSources.addAll(source.getGroupChildren());
24+
}
25+
});
26+
27+
return allSources;
28+
}
1629
}
Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
11
package net.twasi.obsremotejava.objects;
22

3+
import java.util.List;
4+
35
public class Source {
4-
private String name;
5-
private double cx;
66
private double cy;
7+
private double cx;
8+
private long alignment;
9+
private String name;
10+
private int id;
711
private boolean render;
12+
private boolean muted;
13+
private boolean locked;
814
private int source_cx;
915
private int source_cy;
1016
private String type;
1117
private double volume;
1218
private double x;
1319
private double y;
14-
//private List<Source> sources;
20+
private String parentGroupName;
21+
private List<Source> groupChildren;
22+
23+
public double getCY() {
24+
return cy;
25+
}
26+
27+
public double getCX() {
28+
return cx;
29+
}
30+
31+
public long getAlignment() {
32+
return alignment;
33+
}
1534

1635
public String getName() {
1736
return name;
1837
}
1938

20-
public double getCX() { return cx; }
21-
public double getCY() { return cy; }
22-
2339
public boolean isRender() {
2440
return render;
2541
}
2642

27-
public int getSourceCX() { return source_cx; }
28-
public int getSourceCY() { return source_cy; }
43+
public int getSourceCX() {
44+
return source_cx;
45+
}
46+
47+
public int getSourceCY() {
48+
return source_cy;
49+
}
50+
51+
public String getType() {
52+
return type;
53+
}
2954

30-
public String getType() { return type; }
55+
public double getVolume() {
56+
return volume;
57+
}
3158

32-
public double getVolume() { return volume; }
59+
public double getX() {
60+
return x;
61+
}
3362

34-
public double getX() { return x; }
35-
public double getY() { return y; }
63+
public double getY() {
64+
return y;
65+
}
3666

37-
/* public List<Source> getSources() {
38-
return sources;
39-
}*/
67+
public List<Source> getGroupChildren() {
68+
return groupChildren;
69+
}
4070
}

src/main/java/net/twasi/obsremotejava/objects/SourceFilterInfo.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)