Skip to content

Commit 0c037b1

Browse files
Create OBSController, OBSWebSocketService, WebSocketConfig
1 parent b0842b9 commit 0c037b1

6 files changed

Lines changed: 120 additions & 10 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.gravitylab.obscontrollerapi.config;
2+
3+
import java.net.URI;
4+
import java.net.URISyntaxException;
5+
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
import com.gravitylab.obscontrollerapi.websocket.OBSWebSocketClient;
10+
11+
@Configuration
12+
public class WebSocketConfig {
13+
private final static String WS = "ws://";
14+
private final static String DEFAULT_IP_ADDRESS = "localhost";
15+
private final static int DEFAULT_PORT = 4444;
16+
17+
@Bean
18+
public OBSWebSocketClient obsWebSocketClient() throws URISyntaxException {
19+
return new OBSWebSocketClient(new URI(WS + DEFAULT_IP_ADDRESS + ":" + DEFAULT_PORT));
20+
}
21+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.gravitylab.obscontrollerapi.controller;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.PostMapping;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
9+
import com.gravitylab.obscontrollerapi.service.OBSWebSocketService;
10+
11+
import lombok.extern.slf4j.Slf4j;
12+
13+
@RestController
14+
@RequestMapping("/obs")
15+
@Slf4j
16+
public class OBSController {
17+
18+
private final OBSWebSocketService obsWebSocketService;
19+
20+
@Autowired
21+
public OBSController(OBSWebSocketService obsWebSocketService) {
22+
this.obsWebSocketService = obsWebSocketService;
23+
}
24+
25+
@PostMapping("/authenticate")
26+
public ResponseEntity<?> authenticate() {
27+
this.obsWebSocketService.authenticate();
28+
return ResponseEntity.ok().build();
29+
}
30+
31+
@PostMapping("/reconnect")
32+
public ResponseEntity<?> reconnect() {
33+
this.obsWebSocketService.reconnect();
34+
return ResponseEntity.ok().build();
35+
}
36+
37+
@PostMapping("disconnect")
38+
public ResponseEntity<?> disconnect() {
39+
obsWebSocketService.disconnect();
40+
return ResponseEntity.ok().build();
41+
}
42+
43+
@PostMapping("/startRecording")
44+
public ResponseEntity<?> startRecording() {
45+
// Call service method to start recording
46+
this.obsWebSocketService.startRecording();
47+
return ResponseEntity.ok().build();
48+
}
49+
50+
@PostMapping("/stopRecording")
51+
public ResponseEntity<?> stopRecording() {
52+
// Call service method to stop recording
53+
obsWebSocketService.stopRecording();
54+
return ResponseEntity.ok().build();
55+
}
56+
57+
}

src/main/java/com/gravitylab/obscontrollerapi/obswebsocket/package-info.java

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

src/main/java/com/gravitylab/obscontrollerapi/package-info.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.gravitylab.obscontrollerapi.service;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.stereotype.Service;
5+
6+
import com.gravitylab.obscontrollerapi.websocket.OBSWebSocketClient;
7+
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
@Slf4j
11+
@Service
12+
public class OBSWebSocketService {
13+
private final OBSWebSocketClient obsWebSocketClient;
14+
15+
@Autowired
16+
public OBSWebSocketService(OBSWebSocketClient obsWebSocketClient) {
17+
this.obsWebSocketClient = obsWebSocketClient;
18+
obsWebSocketClient.connect();
19+
}
20+
21+
public void authenticate() {
22+
obsWebSocketClient.authenticate();
23+
}
24+
25+
public void disconnect() {
26+
obsWebSocketClient.close();
27+
}
28+
29+
public void startRecording() {
30+
this.obsWebSocketClient.startRecording();
31+
}
32+
33+
public void stopRecording() {
34+
this.obsWebSocketClient.stopRecording();
35+
}
36+
37+
public void reconnect() {
38+
obsWebSocketClient.reconnect();
39+
}
40+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
1+
obs.websocket.uri=ws://localhost:4444
2+
obs.websocket.password=secret

0 commit comments

Comments
 (0)