Skip to content

Commit fcffa1e

Browse files
authored
Merge pull request #28 from cloudwebrtc/golang
Golang
2 parents aae24a3 + 72dfcc5 commit fcffa1e

37 files changed

+67842
-1264
lines changed

.babelrc

-10
This file was deleted.

Makefile

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
VERSION=$(shell git describe --tags)
2+
3+
all: linux darwin windows
4+
5+
release: all zip
6+
7+
clean:
8+
rm -rf bin/* *.zip
9+
10+
upx:
11+
upx -9 bin/*
12+
13+
linux:
14+
CGO_ENABLE=0 GOOS=linux GOARCH=amd64 go build -o bin/server-linux-amd64 -ldflags "-s -w" cmd/server/main.go
15+
CGO_ENABLE=0 GOOS=linux GOARCH=386 go build -o bin/server-linux-i386 -ldflags "-s -w" cmd/server/main.go
16+
17+
darwin:
18+
CGO_ENABLE=0 GOOS=darwin GOARCH=amd64 go build -o bin/server-darwin-amd64 -ldflags "-s -w" cmd/server/main.go
19+
20+
windows:
21+
CGO_ENABLE=0 GOOS=windows GOARCH=amd64 go build -o bin/server-windows-amd64.exe -ldflags "-s -w" cmd/server/main.go
22+
CGO_ENABLE=0 GOOS=windows GOARCH=386 go build -o bin/server-windows-i386.exe -ldflags "-s -w" cmd/server/main.go
23+
24+
zip:
25+
zip -r flutter-webrtc-server-bin-${VERSION}.zip bin configs web

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ A simple WebRTC Signaling server for flutter-webrtc and html5.
55
Chrome/Firefox/Safari
66

77
## Usage
8-
- Clone the repository, run `npm install`.
9-
- Run `npm start` and open https://your_sever_ip_or_domain:8086 to use html5 demo.
10-
- If you need to test mobile app, please check the [webrtc-flutter-demo](https://github.com/cloudwebrtc/flutter-webrtc-demo).
8+
- Clone the repository, run `make`.
9+
- Run `./bin/server-{platform}-{arch}` and open https://your_sever_ip_or_domain:4443 to use html5 demo.
10+
- If you need to test mobile app, please check the [webrtc-flutter-demo](https://github.com/cloudwebrtc/flutter-webrtc-demo/tree/golang).
1111

1212
## Note
1313
This example can only be used for LAN testing. If you need to use it in a production environment, you need more testing and and deploy an available turn server.

certs/cert.pem

-19
This file was deleted.

certs/key.pem

-27
This file was deleted.

cmd/server/main.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/logger"
7+
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/signaler"
8+
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/turn"
9+
"github.com/cloudwebrtc/flutter-webrtc-server/pkg/websocket"
10+
"gopkg.in/ini.v1"
11+
)
12+
13+
func main() {
14+
15+
cfg, err := ini.Load("configs/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+
28+
turnConfig := turn.DefaultConfig()
29+
turnConfig.PublicIP = publicIP
30+
turnConfig.Port = stunPort
31+
turnConfig.Realm = realm
32+
turn := turn.NewTurnServer(turnConfig)
33+
34+
signaler := signaler.NewSignaler(turn)
35+
wsServer := websocket.NewWebSocketServer(signaler.HandleNewWebSocket, signaler.HandleTurnServerCredentials)
36+
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+
48+
config := websocket.DefaultConfig()
49+
config.Host = bindAddress
50+
config.Port = port
51+
config.CertFile = sslCert
52+
config.KeyFile = sslKey
53+
config.HTMLRoot = htmlRoot
54+
55+
wsServer.Bind(config)
56+
}

configs/certs/cert.pem

+47
Original file line numberDiff line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BBYEFBKGRGYmCFQmj2U3silOJiHgk77bMB8GA1UdIwQY
35+
MBaAFAPeUDVW0Uy7ZvCj4hsbw5eyPdFVMA4GA1UdDwEB/wQEAwIBhjAdBgNVHSUE
36+
FjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwEgYDVR0TAQH/BAgwBgEB/wIBADA0Bggr
37+
BgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2ljZXJ0LmNv
38+
bTBCBgNVHR8EOzA5MDegNaAzhjFodHRwOi8vY3JsMy5kaWdpY2VydC5jb20vRGln
39+
aUNlcnRHbG9iYWxSb290Q0EuY3JsMEwGA1UdIARFMEMwNwYJYIZIAYb9bAECMCow
40+
KAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LmRpZ2ljZXJ0LmNvbS9DUFMwCAYGZ4EM
41+
AQIBMA0GCSqGSIb3DQEBCwUAA4IBAQBZcGGhLE09CbQD5xP93NAuNC85G1BMa1OG
42+
2Q01TWvvgp7Qt1wNfRLAnhQT5pb7kRs+E7nM4IS894ufmuL452q8gYaq5HmvOmfh
43+
XMmL6K+eICfvyqjb/tSi8iy20ULO/TZhLhPor9tle52Yx811FG4i5vqwPIUEOEJ7
44+
pXe6RPVoBiwi4rbLspQGD/vYqrj9OJV4JctoIhhGq+y/sozU6nBXHfhVSD3x+hkO
45+
Ost6tyRq481IyUWQHcFtwda3gfMnaA3dsag2dtJz33RIJIUfxXmVK7w4YzHOHifn
46+
7TYk8iNrDDLtql6vS8FjiUx3kJnI6zge1C9lUHhZ/aD3RiTJrwWI
47+
-----END CERTIFICATE-----

configs/certs/key.pem

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg5IB7nx+zBYxQ9HNx
3+
wRnmQ5ySsXH/i66wdqxxIOYYqYKhRANCAATXEqrYLiHRTiy4YwMe24gdAdOm2GNp
4+
IWDqBNz0wYhp2Zlxq5s4T+g88iy31cKI6MLGPhHB/OdG7f2bmfZEgU0s
5+
-----END PRIVATE KEY-----

configs/config.ini

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[general]
2+
domain=demo.cloudwebrtc.com
3+
cert=configs/certs/cert.pem
4+
key=configs/certs/key.pem
5+
bind=0.0.0.0
6+
port=8086
7+
html_root=web
8+
9+
[turn]
10+
public_ip=127.0.0.1
11+
port=19302
12+
realm=flutter-webrtc

go.mod

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module github.com/cloudwebrtc/flutter-webrtc-server
2+
3+
go 1.12
4+
5+
require (
6+
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
7+
github.com/gorilla/mux v1.7.3 // indirect
8+
github.com/gorilla/websocket v1.4.1
9+
github.com/pion/turn/v2 v2.0.3
10+
github.com/rs/zerolog v1.14.3
11+
github.com/smartystreets/goconvey v1.6.4 // indirect
12+
gopkg.in/ini.v1 v1.51.1
13+
)

go.sum

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4=
2+
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2wSM9zJkl1UQEFZgSd68NfCgRz1VL1jzy/RjCg+ULrs=
3+
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
4+
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
5+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
7+
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
8+
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
9+
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
10+
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
11+
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
12+
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
13+
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
14+
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
15+
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
16+
github.com/pion/stun v0.3.3 h1:brYuPl9bN9w/VM7OdNzRSLoqsnwlyNvD9MVeJrHjDQw=
17+
github.com/pion/stun v0.3.3/go.mod h1:xrCld6XM+6GWDZdvjPlLMsTU21rNxnO6UO8XsAvHr/M=
18+
github.com/pion/transport v0.8.10 h1:lTiobMEw2PG6BH/mgIVqTV2mBp/mPT+IJLaN8ZxgdHk=
19+
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
20+
github.com/pion/turn v1.4.0 h1:7NUMRehQz4fIo53Qv9ui1kJ0Kr1CA82I81RHKHCeM80=
21+
github.com/pion/turn/v2 v2.0.1 h1:TO6NsNCqSIrhk33Eg3l7+KPeUOjLY3Ff70l+DAxAQOQ=
22+
github.com/pion/turn/v2 v2.0.1/go.mod h1:kl1hmT3NxcLynpXVnwJgObL8C9NaCyPTeqI2DcCpSZs=
23+
github.com/pion/turn/v2 v2.0.3 h1:SJUUIbcPoehlyZgMyIUbBBDhI03sBx32x3JuSIBKBWA=
24+
github.com/pion/turn/v2 v2.0.3/go.mod h1:kl1hmT3NxcLynpXVnwJgObL8C9NaCyPTeqI2DcCpSZs=
25+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
26+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
27+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
28+
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
29+
github.com/rs/zerolog v1.14.3 h1:4EGfSkR2hJDB0s3oFfrlPqjU1e4WLncergLil3nEKW0=
30+
github.com/rs/zerolog v1.14.3/go.mod h1:3WXPzbXEEliJ+a6UFE4vhIxV8qR1EML6ngzP9ug4eYg=
31+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
32+
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
33+
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
34+
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
35+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
36+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
37+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
38+
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
39+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
40+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
41+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
42+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
43+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
44+
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
45+
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
46+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
47+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
48+
gopkg.in/ini.v1 v1.51.1 h1:GyboHr4UqMiLUybYjd22ZjQIKEJEpgtLXtuGbR21Oho=
49+
gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
50+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
51+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

package.json

-55
This file was deleted.

0 commit comments

Comments
 (0)