Skip to content

Commit 28b4ba1

Browse files
committed
CLI used to configure HTTP port, visible on network and easy connect
server port
1 parent 7dbe0ab commit 28b4ba1

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

src/cli/cli.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import (
77
func init() {
88
networkVisible := flag.Bool("network_visible", false, "Indicate to use all network interfaces (0.0.0.0) instead of loopback-only (127.0.0.1)")
99
httpPort := flag.Uint("port", 8080, "Port used for serving http Web client")
10-
10+
easyConnectPort := flag.Uint("easyport", 8081, "Port used for Easy Connect Server")
11+
1112
flag.Parse()
1213

1314
config = configT{
1415
networkVisible: *networkVisible,
1516
httpPort: uint16(*httpPort),
17+
easyConnectPort: uint16(*easyConnectPort),
1618
}
1719
}
1820

1921
type configT struct {
2022
networkVisible bool
2123
httpPort uint16
24+
easyConnectPort uint16
2225
}
2326

2427
func (c configT) GetNetworkVisible() bool {
@@ -29,6 +32,10 @@ func (c configT) GetHTTPPort() uint16 {
2932
return c.httpPort
3033
}
3134

35+
func (c configT) GetEasyConnectPort() uint16 {
36+
return c.easyConnectPort
37+
}
38+
3239
var config configT
3340

3441
func GetConfig() configT {

src/net/http/http.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ import (
77
"io/fs"
88
"net/http"
99
"strings"
10+
11+
"github.com/PiterWeb/RemoteController/src/cli"
1012
)
1113

12-
func InitHTTPAssets(serverMux *http.ServeMux, clientPort uint16, assets embed.FS) error {
14+
func InitHTTPAssets(serverMux *http.ServeMux, assets embed.FS) error {
15+
16+
config := cli.GetConfig()
17+
clientPort := config.GetHTTPPort()
18+
19+
var addr string
20+
21+
if config.GetNetworkVisible() {
22+
addr = fmt.Sprintf("0.0.0.0:%d", clientPort)
23+
} else {
24+
addr = fmt.Sprintf("127.0.0.1:%d", clientPort)
25+
}
1326

1427
staticFS, err := fs.Sub(assets, "frontend/build")
1528

@@ -21,7 +34,7 @@ func InitHTTPAssets(serverMux *http.ServeMux, clientPort uint16, assets embed.FS
2134

2235
httpServer := &http.Server{
2336
Handler: serverMux,
24-
Addr: fmt.Sprintf("127.0.0.1:%d", clientPort),
37+
Addr: addr,
2538
}
2639

2740
err = httpServer.ListenAndServe()

src/oninit/oninit_linux.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
"net/http"
77

88
LRPSignals "github.com/PiterWeb/LibreRemotePlaySignals/v1"
9+
"github.com/PiterWeb/RemoteController/src/cli"
910
net_http "github.com/PiterWeb/RemoteController/src/net/http"
1011
"github.com/PiterWeb/RemoteController/src/net/websocket"
1112
)
1213

1314
func Execute(assets embed.FS) error {
1415

15-
serverPort := uint16(8080)
16-
1716
httpServerMux := http.NewServeMux()
1817

1918
websocket.SetupWebsocketHandler(httpServerMux)
@@ -22,22 +21,20 @@ func Execute(assets embed.FS) error {
2221
errChan := make(chan error, 2)
2322

2423
go func() {
25-
err := net_http.InitHTTPAssets(httpServerMux, serverPort, assets)
24+
err := net_http.InitHTTPAssets(httpServerMux, assets)
2625

2726
if err != nil {
2827
errChan <- err
2928
}
3029
}()
31-
32-
easyConnectPort := uint16(8081)
3330

3431
go func() {
3532

3633
options := LRPSignals.ServerOptions{
37-
Port: easyConnectPort,
34+
Port: cli.GetConfig().GetEasyConnectPort(),
3835
}
3936

40-
log.Println("Easy Connect Server started on port 8081")
37+
log.Printf("Easy Connect Server started on port %d\n", options.Port)
4138
err := LRPSignals.InitServer(options, ips_channel)
4239
if err != nil {
4340
errChan <- err

src/oninit/oninit_windows.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ func Execute(assets embed.FS) error {
1616
return err
1717
}
1818

19-
serverPort := uint16(8080)
20-
2119
httpServerMux := http.NewServeMux()
2220

2321
ips_channel := make(chan []string, 1)
2422
errChan := make(chan error, 2)
2523

2624
go func() {
27-
err := net_http.InitHTTPAssets(httpServerMux, serverPort, assets)
25+
err := net_http.InitHTTPAssets(httpServerMux, assets)
2826

2927
if err != nil {
3028
errChan <- err

0 commit comments

Comments
 (0)