Skip to content

Commit f83e806

Browse files
author
TinaTiel
committed
Added test for browser source refreshing
1 parent e0d6b68 commit f83e806

File tree

3 files changed

+123
-4
lines changed

3 files changed

+123
-4
lines changed

obs-resources/AnonymizedSceneCollection.json

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,38 @@
195195
}
196196
],
197197
"sources": [
198+
{
199+
"balance": 0.5,
200+
"deinterlace_field_order": 0,
201+
"deinterlace_mode": 0,
202+
"enabled": true,
203+
"flags": 0,
204+
"hotkeys": {
205+
"libobs.mute": [],
206+
"libobs.push-to-mute": [],
207+
"libobs.push-to-talk": [],
208+
"libobs.unmute": []
209+
},
210+
"id": "browser_source",
211+
"mixers": 255,
212+
"monitoring_type": 0,
213+
"muted": false,
214+
"name": "browser",
215+
"prev_ver": 436273153,
216+
"private_settings": {},
217+
"push-to-mute": false,
218+
"push-to-mute-delay": 0,
219+
"push-to-talk": false,
220+
"push-to-talk-delay": 0,
221+
"settings": {
222+
"is_local_file": true,
223+
"local_file": "REPLACE_ME/static/index.html",
224+
"url": "http://localhost:8090/static/index.html"
225+
},
226+
"sync": 0,
227+
"versioned_id": "browser_source",
228+
"volume": 1.0
229+
},
198230
{
199231
"balance": 0.5,
200232
"deinterlace_field_order": 0,
@@ -463,12 +495,14 @@
463495
"flags": 0,
464496
"hotkeys": {
465497
"OBSBasic.SelectScene": [],
498+
"libobs.hide_scene_item.browser": [],
466499
"libobs.hide_scene_item.group": [],
467500
"libobs.hide_scene_item.grouptext": [],
468501
"libobs.hide_scene_item.media": [],
469502
"libobs.hide_scene_item.red_square": [],
470503
"libobs.hide_scene_item.scenename1": [],
471504
"libobs.hide_scene_item.vlc-media": [],
505+
"libobs.show_scene_item.browser": [],
472506
"libobs.show_scene_item.group": [],
473507
"libobs.show_scene_item.grouptext": [],
474508
"libobs.show_scene_item.media": [],
@@ -489,7 +523,7 @@
489523
"push-to-talk-delay": 0,
490524
"settings": {
491525
"custom_size": false,
492-
"id_counter": 15,
526+
"id_counter": 16,
493527
"items": [
494528
{
495529
"align": 5,
@@ -551,6 +585,35 @@
551585
"scale_filter": "disable",
552586
"visible": false
553587
},
588+
{
589+
"align": 5,
590+
"bounds": {
591+
"x": 0.0,
592+
"y": 0.0
593+
},
594+
"bounds_align": 0,
595+
"bounds_type": 0,
596+
"crop_bottom": 0,
597+
"crop_left": 0,
598+
"crop_right": 0,
599+
"crop_top": 0,
600+
"group_item_backup": false,
601+
"id": 16,
602+
"locked": false,
603+
"name": "browser",
604+
"pos": {
605+
"x": 851.0,
606+
"y": 269.0
607+
},
608+
"private_settings": {},
609+
"rot": 0.0,
610+
"scale": {
611+
"x": 1.2775000333786011,
612+
"y": 1.278333306312561
613+
},
614+
"scale_filter": "disable",
615+
"visible": true
616+
},
554617
{
555618
"align": 5,
556619
"bounds": {

obs-resources/static/index.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
h1, h2 {
6+
font-size: 100px;
7+
text-align: center;
8+
}
9+
</style>
10+
</head>
11+
<body>
12+
13+
<h1>OBS Browser Source</h1>
14+
<h2 id="random-num"></h2>
15+
16+
<script>
17+
document.getElementById("random-num").innerHTML = Math.random();
18+
var x = Math.floor(Math.random() * 256);
19+
var y = Math.floor(Math.random() * 256);
20+
var z = Math.floor(Math.random() * 256);
21+
var bgColor = "rgb(" + x + "," + y + "," + z + ")";
22+
document.body.style.background = bgColor;
23+
</script>
24+
25+
</body>
26+
</html>

src/integrationTest/java/net/twasi/obsremotejava/test/ObsRemoteE2eObservationIT.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
44
import static org.junit.jupiter.api.Assertions.fail;
55

6+
import com.sun.net.httpserver.Headers;
7+
import com.sun.net.httpserver.HttpExchange;
8+
import com.sun.net.httpserver.HttpHandler;
9+
import com.sun.net.httpserver.HttpServer;
610
import java.io.File;
11+
import java.io.FileInputStream;
12+
import java.io.IOException;
13+
import java.io.OutputStream;
14+
import java.net.InetSocketAddress;
15+
import java.net.URL;
716
import java.util.HashMap;
817
import java.util.Map;
18+
import java.util.Properties;
919
import java.util.function.Consumer;
1020
import net.twasi.obsremotejava.OBSRemoteController;
1121
import org.junit.jupiter.api.AfterAll;
@@ -26,7 +36,9 @@ public class ObsRemoteE2eObservationIT {
2636
private final String SOURCE_VLC_MEDIA = "vlc-media";
2737
private final String SOURCE_RED_SQUARE = "red_square";
2838
private final String SOURCE_RED_SQUARE_FILTER = "Color Correction";
39+
private final String SOURCE_BROWSER = "browser";
2940
private final String SCENE1 = "scene1";
41+
private final String SOURCE_TEXT_SCENE1 = "scenename1";
3042
private final String SCENE2 = "scene2";
3143
private final String TRANSITION_SLIDE = "Slide";
3244
private final String TRANSITION_CUT = "Cut";
@@ -35,7 +47,7 @@ public class ObsRemoteE2eObservationIT {
3547
@BeforeAll
3648
static void beforeAll() {
3749

38-
// Connect
50+
// Connect to OBS
3951
remote = new OBSRemoteController("ws://localhost:4444", false);
4052
remote.registerConnectionFailedCallback(message -> {
4153
fail("Failed to connect to OBS: " + message);
@@ -44,6 +56,7 @@ static void beforeAll() {
4456
fail("Failed to connect to OBS due to error: " + message);
4557
});
4658
remote.connect();
59+
4760
try {
4861
Thread.sleep(1000);
4962
} catch (InterruptedException e) {
@@ -138,10 +151,10 @@ void setSourceSettings() {
138151
obsShould("Curse the 'scene1' text");
139152
Map<String, Object> settings = new HashMap<>();
140153
settings.put("text", "S̼͚̞̼̩̱̽̓̍̽͊́ͨ̍̀ċͭ̚҉̪̖̤̥ͅȩ͉̣̜̖̖͙͇́̀̒ͥ̓̚͠͞n̦͍͆͑ͤ̕e̶̖̝̗̻͂̑̽̔ͩ̅́͜ͅ ̢͉̬͔͙̺̖͂͂ͣ͢1̮̥͇̏̇͋̈́ͨͥ͝ͅ");
141-
remote.setSourceSettings(SCENE1, settings, loggingCallback);
154+
remote.setSourceSettings(SOURCE_TEXT_SCENE1, settings, loggingCallback);
142155
obsShould("Change the 'scene1' text back to normal");
143156
settings.put("text", "Scene 1");
144-
remote.setSourceSettings(SCENE1, settings, loggingCallback);
157+
remote.setSourceSettings(SOURCE_TEXT_SCENE1, settings, loggingCallback);
145158
}
146159

147160
@Test
@@ -228,6 +241,23 @@ void playPauseVlcMedia() {
228241

229242
}
230243

244+
@Test
245+
void triggerHotkey() {
246+
obsShould("Show the red square via hotkey name");
247+
remote.triggerHotkeyByName("libobs.show_scene_item.red_square", loggingCallback);
248+
}
249+
250+
@Test
251+
void refreshBrowserSource() {
252+
253+
obsShould("Show the browser source", 1);
254+
remote.setSourceVisibility(null, SOURCE_BROWSER, true, loggingCallback);
255+
256+
obsShould("Refresh the browser source (new random color and number)");
257+
remote.refreshBrowserSource(SOURCE_BROWSER, loggingCallback);
258+
259+
}
260+
231261
// Private Test Helpers
232262
private void obsShould(String expected) {
233263
obsShould(expected, 3);

0 commit comments

Comments
 (0)