Skip to content

Commit 6219c14

Browse files
committed
Add config file.
1 parent fdf1d6e commit 6219c14

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ windows:
2020
CGO_ENABLE=0 GOOS=windows GOARCH=386 go build -o bin/server-windows-i386.exe -ldflags "-s -w" main/server/main.go
2121

2222
tar:
23-
tar jcvf flutter-webrtc-server-bin.tar.bz2 bin certs html
23+
tar jcvf flutter-webrtc-server-bin.tar.bz2 bin certs html config

config/config.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[general]
2+
cert=certs/cert.pem
3+
key=certs/key.pem
4+
bind=0.0.0.0
5+
port=4443
6+
html_root=./html
7+
8+
[turn]
9+
public_ip=127.0.0.1
10+
port=19302
11+
realm=flutter-webrtc

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ require (
77
github.com/gorilla/websocket v1.4.1
88
github.com/pion/turn/v2 v2.0.1
99
github.com/rs/zerolog v1.14.3
10+
github.com/smartystreets/goconvey v1.6.4 // indirect
11+
gopkg.in/ini.v1 v1.51.1
1012
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcw
22
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2wSM9zJkl1UQEFZgSd68NfCgRz1VL1jzy/RjCg+ULrs=
33
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
44
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
56
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
67
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
8+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
9+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
710
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
811
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
912
github.com/pion/stun v0.3.3 h1:brYuPl9bN9w/VM7OdNzRSLoqsnwlyNvD9MVeJrHjDQw=
@@ -17,6 +20,10 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
1720
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
1821
github.com/rs/zerolog v1.14.3 h1:4EGfSkR2hJDB0s3oFfrlPqjU1e4WLncergLil3nEKW0=
1922
github.com/rs/zerolog v1.14.3/go.mod h1:3WXPzbXEEliJ+a6UFE4vhIxV8qR1EML6ngzP9ug4eYg=
23+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
24+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
25+
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
26+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
2027
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2128
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
2229
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
@@ -25,6 +32,9 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
2532
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2633
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2734
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
35+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
2836
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
2937
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38+
gopkg.in/ini.v1 v1.51.1 h1:GyboHr4UqMiLUybYjd22ZjQIKEJEpgtLXtuGbR21Oho=
39+
gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
3040
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

main/server/main.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,56 @@
11
package main
22

33
import (
4+
"os"
5+
6+
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/logger"
47
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/signaler"
58
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/turn"
69
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/websocket"
10+
"gopkg.in/ini.v1"
711
)
812

913
func main() {
14+
15+
cfg, err := ini.Load("config/config.ini")
16+
if err != nil {
17+
logger.Errorf("Fail to read file: %v", err)
18+
os.Exit(1)
19+
}
20+
21+
publicIP := cfg.Section("turn").Key("public_ip").String()
22+
stunPort, err := cfg.Section("turn").Key("port").Int()
23+
if err != nil {
24+
stunPort = 3478
25+
}
26+
realm := cfg.Section("turn").Key("realm").String()
27+
1028
turnConfig := turn.DefaultConfig()
11-
turnConfig.PublicIP = "123.45.67.89"
12-
turnConfig.Port = 19302
13-
turnConfig.Realm = "flutter-webrtc"
29+
turnConfig.PublicIP = publicIP
30+
turnConfig.Port = stunPort
31+
turnConfig.Realm = realm
1432
turn := turn.NewTurnServer(turnConfig)
1533

1634
signaler := signaler.NewSignaler(turn)
1735
wsServer := websocket.NewWebSocketServer(signaler.HandleNewWebSocket, signaler.HandleTurnServerCredentials)
1836

37+
sslCert := cfg.Section("general").Key("cert").String()
38+
sslKey := cfg.Section("general").Key("key").String()
39+
bindAddress := cfg.Section("general").Key("bind").String()
40+
41+
port, err := cfg.Section("general").Key("port").Int()
42+
if err != nil {
43+
port = 8086
44+
}
45+
46+
htmlRoot := cfg.Section("general").Key("html_root").String()
47+
1948
config := websocket.DefaultConfig()
20-
config.Port = 4443
21-
config.CertFile = "certs/cert.pem"
22-
config.KeyFile = "certs/key.pem"
23-
config.HTMLRoot = "html"
49+
config.Host = bindAddress
50+
config.Port = port
51+
config.CertFile = sslCert
52+
config.KeyFile = sslKey
53+
config.HTMLRoot = htmlRoot
2454

2555
wsServer.Bind(config)
2656
}

0 commit comments

Comments
 (0)