Skip to content

Commit 8947830

Browse files
committed
[feature] Add external vision client to UI, integrate backend
1 parent a425aee commit 8947830

File tree

6 files changed

+107
-261
lines changed

6 files changed

+107
-261
lines changed

cmd/ssl-game-controller/main.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,51 @@
11
package main
22

33
import (
4+
"flag"
45
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/controller"
6+
"github.com/RoboCup-SSL/ssl-vision-client/pkg/vision"
57
"github.com/gobuffalo/packr"
68
"log"
79
"net/http"
810
)
911

12+
var address = flag.String("address", "localhost:8081", "The address on which the UI and API is served, default: localhost:8081")
13+
var visionAddress = flag.String("visionAddress", "224.5.23.2:10006", "The multicast address of ssl-vision, default: 224.5.23.2:10006")
14+
1015
func main() {
16+
flag.Parse()
17+
18+
setupGameController()
19+
setupVisionClient()
20+
setupUi()
21+
22+
err := http.ListenAndServe(*address, nil)
23+
if err != nil {
24+
log.Fatal(err)
25+
}
26+
}
27+
28+
func setupGameController() {
29+
gameController := controller.NewGameController()
30+
gameController.Run()
31+
// serve the bidirectional web socket
32+
http.HandleFunc("/api/control", gameController.ApiServer.WsHandler)
33+
}
1134

12-
g := controller.NewGameController()
13-
g.Run()
35+
func setupVisionClient() {
36+
receiver := vision.NewReceiver()
37+
publisher := vision.NewPublisher()
38+
publisher.PackageProvider = receiver.ToPackage
39+
http.HandleFunc("/api/vision", publisher.Handler)
40+
go receiver.Receive(*visionAddress)
41+
}
1442

43+
func setupUi() {
1544
box := packr.NewBox("../../ui/dist")
1645
http.Handle("/", http.FileServer(box))
17-
1846
if box.Has("index.html") {
19-
log.Print("UI is available at http://localhost:8081")
47+
log.Printf("UI is available at http://%v", *address)
2048
} else {
2149
log.Print("Backend-only version started. Run the UI separately or get a binary that has the UI included")
2250
}
23-
24-
// serve the bidirectional web socket
25-
http.HandleFunc("/ws", g.ApiServer.WsHandler)
26-
http.ListenAndServe(":8081", nil)
2751
}

ui/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title>ssl-game-controller</title>
99
</head>
10-
<body>
10+
<body style="height: 100vh">
1111
<noscript>
1212
<strong>We're sorry but ssl-game-controller doesn't work properly without JavaScript enabled. Please enable it to
1313
continue.</strong>

ui/src/App.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ControlTeam class="team-views" team-color="Yellow"/>
1111
</div>
1212
<div id="field">
13-
<Field/>
13+
<iframe src="http://localhost:8082/" frameborder="none"></iframe>
1414
</div>
1515
<div class="team-container">
1616
<TeamOverview class="team-views" team-color="Blue"/>
@@ -29,12 +29,10 @@
2929
import ControlTeam from "./components/control/ControlTeam";
3030
import Debug from "./components/Debug";
3131
import ControlMatch from "./components/control/ControlMatch";
32-
import Field from "./components/field/Field";
3332
3433
export default {
3534
name: 'app',
3635
components: {
37-
Field,
3836
ControlMatch,
3937
Debug,
4038
ControlTeam,
@@ -52,6 +50,10 @@
5250
-moz-osx-font-smoothing: grayscale;
5351
text-align: center;
5452
color: #2c3e50;
53+
height: 100%;
54+
display: flex;
55+
flex-direction: column;
56+
justify-content: stretch;
5557
}
5658
5759
#app-header {
@@ -77,7 +79,7 @@
7779
flex-direction: row;
7880
flex-wrap: wrap;
7981
justify-content: flex-start;
80-
align-items: flex-start;
82+
align-items: stretch;
8183
align-content: flex-start;
8284
flex-grow: 1;
8385
}
@@ -86,6 +88,11 @@
8688
flex-grow: 1;
8789
}
8890
91+
#field iframe {
92+
width: 100%;
93+
height: 100%;
94+
}
95+
8996
.team-container {
9097
display: flex;
9198
flex-direction: column;

ui/src/components/field/Field.vue

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

0 commit comments

Comments
 (0)