mirror of
https://github.com/jech/galene.git
synced 2024-11-14 04:35:57 +01:00
Use Pion's JSON support for ICE configuration.
This commit is contained in:
parent
2ec0c01458
commit
dbec9df288
6 changed files with 42 additions and 53 deletions
2
README
2
README
|
@ -38,7 +38,7 @@ It should look like this:
|
||||||
],
|
],
|
||||||
"username": "username",
|
"username": "username",
|
||||||
"credential": "password"
|
"credential": "password"
|
||||||
},
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
The port number, username and password should be the same as the ones in
|
The port number, username and password should be the same as the ones in
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -8,6 +8,6 @@ require (
|
||||||
github.com/pion/ice/v2 v2.0.14
|
github.com/pion/ice/v2 v2.0.14
|
||||||
github.com/pion/rtcp v1.2.6
|
github.com/pion/rtcp v1.2.6
|
||||||
github.com/pion/rtp v1.6.2
|
github.com/pion/rtp v1.6.2
|
||||||
github.com/pion/webrtc/v3 v3.0.0
|
github.com/pion/webrtc/v3 v3.0.2-0.20201230060242-921608c26b93
|
||||||
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
|
golang.org/x/crypto v0.0.0-20201217014255-9d1352758620
|
||||||
)
|
)
|
||||||
|
|
15
go.sum
15
go.sum
|
@ -54,12 +54,8 @@ github.com/pion/mdns v0.0.4 h1:O4vvVqr4DGX63vzmO6Fw9vpy3lfztVWHGCQfyw0ZLSY=
|
||||||
github.com/pion/mdns v0.0.4/go.mod h1:R1sL0p50l42S5lJs91oNdUL58nm0QHrhxnSegr++qC0=
|
github.com/pion/mdns v0.0.4/go.mod h1:R1sL0p50l42S5lJs91oNdUL58nm0QHrhxnSegr++qC0=
|
||||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||||
github.com/pion/rtcp v1.2.4 h1:NT3H5LkUGgaEapvp0HGik+a+CpflRF7KTD7H+o7OWIM=
|
|
||||||
github.com/pion/rtcp v1.2.4/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0=
|
|
||||||
github.com/pion/rtcp v1.2.6 h1:1zvwBbyd0TeEuuWftrd/4d++m+/kZSeiguxU61LFWpo=
|
github.com/pion/rtcp v1.2.6 h1:1zvwBbyd0TeEuuWftrd/4d++m+/kZSeiguxU61LFWpo=
|
||||||
github.com/pion/rtcp v1.2.6/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0=
|
github.com/pion/rtcp v1.2.6/go.mod h1:52rMNPWFsjr39z9B9MhnkqhPLoeHTv1aN63o/42bWE0=
|
||||||
github.com/pion/rtp v1.6.1 h1:2Y2elcVBrahYnHKN2X7rMHX/r1R4TEBMP1LaVu/wNhk=
|
|
||||||
github.com/pion/rtp v1.6.1/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
|
||||||
github.com/pion/rtp v1.6.2 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U=
|
github.com/pion/rtp v1.6.2 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U=
|
||||||
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||||
github.com/pion/sctp v1.7.10/go.mod h1:EhpTUQu1/lcK3xI+eriS6/96fWetHGCvBi9MSsnaBN0=
|
github.com/pion/sctp v1.7.10/go.mod h1:EhpTUQu1/lcK3xI+eriS6/96fWetHGCvBi9MSsnaBN0=
|
||||||
|
@ -67,8 +63,8 @@ github.com/pion/sctp v1.7.11 h1:UCnj7MsobLKLuP/Hh+JMiI/6W5Bs/VF45lWKgHFjSIE=
|
||||||
github.com/pion/sctp v1.7.11/go.mod h1:EhpTUQu1/lcK3xI+eriS6/96fWetHGCvBi9MSsnaBN0=
|
github.com/pion/sctp v1.7.11/go.mod h1:EhpTUQu1/lcK3xI+eriS6/96fWetHGCvBi9MSsnaBN0=
|
||||||
github.com/pion/sdp/v3 v3.0.3 h1:gJK9hk+JFD2NGIM1nXmqNCq1DkVaIZ9dlA3u3otnkaw=
|
github.com/pion/sdp/v3 v3.0.3 h1:gJK9hk+JFD2NGIM1nXmqNCq1DkVaIZ9dlA3u3otnkaw=
|
||||||
github.com/pion/sdp/v3 v3.0.3/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk=
|
github.com/pion/sdp/v3 v3.0.3/go.mod h1:bNiSknmJE0HYBprTHXKPQ3+JjacTv5uap92ueJZKsRk=
|
||||||
github.com/pion/srtp/v2 v2.0.0-rc.3 h1:1fPiK1nJlNyh235tSGgBnXrPc99wK1/D707f6ntb3qY=
|
github.com/pion/srtp/v2 v2.0.0 h1:rS4vRR0XHakmnXkaptPaXHxRiqSPWSCrDXFl/ZWMLo0=
|
||||||
github.com/pion/srtp/v2 v2.0.0-rc.3/go.mod h1:S6J9oY6ahAXdU3ni4nUwhWTJuBfssFjPxoB0u41TBpY=
|
github.com/pion/srtp/v2 v2.0.0/go.mod h1:QYOU1YKWaE/NJjR2WxtDMc+AfS9So0uz0RnadqOGJO8=
|
||||||
github.com/pion/stun v0.3.5 h1:uLUCBCkQby4S1cf6CGuR9QrVOKcvUwFeemaC865QHDg=
|
github.com/pion/stun v0.3.5 h1:uLUCBCkQby4S1cf6CGuR9QrVOKcvUwFeemaC865QHDg=
|
||||||
github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2UA=
|
github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2UA=
|
||||||
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
|
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
|
||||||
|
@ -78,12 +74,14 @@ github.com/pion/transport v0.10.1 h1:2W+yJT+0mOQ160ThZYUx5Zp2skzshiNgxrNE9GUfhJM
|
||||||
github.com/pion/transport v0.10.1/go.mod h1:PBis1stIILMiis0PewDw91WJeLJkyIMcEk+DwKOzf4A=
|
github.com/pion/transport v0.10.1/go.mod h1:PBis1stIILMiis0PewDw91WJeLJkyIMcEk+DwKOzf4A=
|
||||||
github.com/pion/transport v0.12.0 h1:UFmOBBZkTZ3LgvLRf/NGrfWdZEubcU6zkLU3PsA9YvU=
|
github.com/pion/transport v0.12.0 h1:UFmOBBZkTZ3LgvLRf/NGrfWdZEubcU6zkLU3PsA9YvU=
|
||||||
github.com/pion/transport v0.12.0/go.mod h1:N3+vZQD9HlDP5GWkZ85LohxNsDcNgofQmyL6ojX5d8Q=
|
github.com/pion/transport v0.12.0/go.mod h1:N3+vZQD9HlDP5GWkZ85LohxNsDcNgofQmyL6ojX5d8Q=
|
||||||
|
github.com/pion/transport v0.12.1 h1:6v8lxQGVZpwSICEZjhl/CCv6aErINZlrm3O5ncFXj/c=
|
||||||
|
github.com/pion/transport v0.12.1/go.mod h1:N3+vZQD9HlDP5GWkZ85LohxNsDcNgofQmyL6ojX5d8Q=
|
||||||
github.com/pion/turn/v2 v2.0.5 h1:iwMHqDfPEDEOFzwWKT56eFmh6DYC6o/+xnLAEzgISbA=
|
github.com/pion/turn/v2 v2.0.5 h1:iwMHqDfPEDEOFzwWKT56eFmh6DYC6o/+xnLAEzgISbA=
|
||||||
github.com/pion/turn/v2 v2.0.5/go.mod h1:APg43CFyt/14Uy7heYUOGWdkem/Wu4PhCO/bjyrTqMw=
|
github.com/pion/turn/v2 v2.0.5/go.mod h1:APg43CFyt/14Uy7heYUOGWdkem/Wu4PhCO/bjyrTqMw=
|
||||||
github.com/pion/udp v0.1.0 h1:uGxQsNyrqG3GLINv36Ff60covYmfrLoxzwnCsIYspXI=
|
github.com/pion/udp v0.1.0 h1:uGxQsNyrqG3GLINv36Ff60covYmfrLoxzwnCsIYspXI=
|
||||||
github.com/pion/udp v0.1.0/go.mod h1:BPELIjbwE9PRbd/zxI/KYBnbo7B6+oA6YuEaNE8lths=
|
github.com/pion/udp v0.1.0/go.mod h1:BPELIjbwE9PRbd/zxI/KYBnbo7B6+oA6YuEaNE8lths=
|
||||||
github.com/pion/webrtc/v3 v3.0.0 h1:/eTiY3NbfpKj5op8cqtCZlpTv9/yumd17YRinDNOUX0=
|
github.com/pion/webrtc/v3 v3.0.2-0.20201230060242-921608c26b93 h1:lyPYvMAKRkqG5dJYa/DbwFqrWkA0QIcOkH7g+MS4OKs=
|
||||||
github.com/pion/webrtc/v3 v3.0.0/go.mod h1:/xwKHOAk1Y8dspJcxMwuTtxpi8t/Gzks37iB3W6hNuM=
|
github.com/pion/webrtc/v3 v3.0.2-0.20201230060242-921608c26b93/go.mod h1:jq9Zm/SEnlXqCANHUr0Fk8G+j0lYznq+athpXb6kwLM=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
@ -129,6 +127,7 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|
66
group/ice.go
66
group/ice.go
|
@ -2,6 +2,7 @@ package group
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -17,16 +18,28 @@ type ICEServer struct {
|
||||||
CredentialType string `json:"credentialType,omitempty"`
|
CredentialType string `json:"credentialType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RTCConfiguration struct {
|
func getICEServer(server ICEServer) (webrtc.ICEServer, error) {
|
||||||
ICEServers []ICEServer `json:"iceServers,omitempty"`
|
s := webrtc.ICEServer{
|
||||||
ICETransportPolicy string `json:"iceTransportPolicy,omitempty"`
|
URLs: server.URLs,
|
||||||
|
Username: server.Username,
|
||||||
|
Credential: server.Credential,
|
||||||
|
}
|
||||||
|
switch server.CredentialType {
|
||||||
|
case "", "password":
|
||||||
|
s.CredentialType = webrtc.ICECredentialTypePassword
|
||||||
|
case "oauth":
|
||||||
|
s.CredentialType = webrtc.ICECredentialTypeOauth
|
||||||
|
default:
|
||||||
|
return webrtc.ICEServer{}, errors.New("unsupported credential type")
|
||||||
|
}
|
||||||
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var ICEFilename string
|
var ICEFilename string
|
||||||
var ICERelayOnly bool
|
var ICERelayOnly bool
|
||||||
|
|
||||||
type iceConf struct {
|
type iceConf struct {
|
||||||
conf RTCConfiguration
|
conf webrtc.Configuration
|
||||||
timestamp time.Time
|
timestamp time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +47,7 @@ var iceConfiguration atomic.Value
|
||||||
|
|
||||||
func updateICEConfiguration() *iceConf {
|
func updateICEConfiguration() *iceConf {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
var conf RTCConfiguration
|
var conf webrtc.Configuration
|
||||||
|
|
||||||
if ICEFilename != "" {
|
if ICEFilename != "" {
|
||||||
file, err := os.Open(ICEFilename)
|
file, err := os.Open(ICEFilename)
|
||||||
|
@ -43,15 +56,24 @@ func updateICEConfiguration() *iceConf {
|
||||||
} else {
|
} else {
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
d := json.NewDecoder(file)
|
d := json.NewDecoder(file)
|
||||||
err = d.Decode(&conf.ICEServers)
|
var servers []ICEServer
|
||||||
|
err = d.Decode(&servers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Get ICE configuration: %v", err)
|
log.Printf("Get ICE configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
for _, s := range servers {
|
||||||
|
ss, err := getICEServer(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("parse ICE server: %v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
conf.ICEServers = append(conf.ICEServers, ss)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ICERelayOnly {
|
if ICERelayOnly {
|
||||||
conf.ICETransportPolicy = "relay"
|
conf.ICETransportPolicy = webrtc.ICETransportPolicyRelay
|
||||||
}
|
}
|
||||||
|
|
||||||
iceConf := iceConf{
|
iceConf := iceConf{
|
||||||
|
@ -62,7 +84,7 @@ func updateICEConfiguration() *iceConf {
|
||||||
return &iceConf
|
return &iceConf
|
||||||
}
|
}
|
||||||
|
|
||||||
func ICEConfiguration() *RTCConfiguration {
|
func ICEConfiguration() *webrtc.Configuration {
|
||||||
conf, ok := iceConfiguration.Load().(*iceConf)
|
conf, ok := iceConfiguration.Load().(*iceConf)
|
||||||
if !ok || time.Since(conf.timestamp) > 5*time.Minute {
|
if !ok || time.Since(conf.timestamp) > 5*time.Minute {
|
||||||
conf = updateICEConfiguration()
|
conf = updateICEConfiguration()
|
||||||
|
@ -72,31 +94,3 @@ func ICEConfiguration() *RTCConfiguration {
|
||||||
|
|
||||||
return &conf.conf
|
return &conf.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToConfiguration(conf *RTCConfiguration) webrtc.Configuration {
|
|
||||||
var iceServers []webrtc.ICEServer
|
|
||||||
for _, s := range conf.ICEServers {
|
|
||||||
tpe := webrtc.ICECredentialTypePassword
|
|
||||||
if s.CredentialType == "oauth" {
|
|
||||||
tpe = webrtc.ICECredentialTypeOauth
|
|
||||||
}
|
|
||||||
iceServers = append(iceServers,
|
|
||||||
webrtc.ICEServer{
|
|
||||||
URLs: s.URLs,
|
|
||||||
Username: s.Username,
|
|
||||||
Credential: s.Credential,
|
|
||||||
CredentialType: tpe,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
policy := webrtc.ICETransportPolicyAll
|
|
||||||
if conf.ICETransportPolicy == "relay" {
|
|
||||||
policy = webrtc.ICETransportPolicyRelay
|
|
||||||
}
|
|
||||||
|
|
||||||
return webrtc.Configuration{
|
|
||||||
ICEServers: iceServers,
|
|
||||||
ICETransportPolicy: policy,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -138,9 +138,7 @@ type rtpDownConnection struct {
|
||||||
|
|
||||||
func newDownConn(c group.Client, id string, remote conn.Up) (*rtpDownConnection, error) {
|
func newDownConn(c group.Client, id string, remote conn.Up) (*rtpDownConnection, error) {
|
||||||
api := group.APIFromCodecs(remote.Codecs())
|
api := group.APIFromCodecs(remote.Codecs())
|
||||||
pc, err := api.NewPeerConnection(
|
pc, err := api.NewPeerConnection(*group.ICEConfiguration())
|
||||||
group.ToConfiguration(group.ICEConfiguration()),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -459,9 +457,7 @@ func pushConn(up *rtpUpConnection, g *group.Group, cs []group.Client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newUpConn(c group.Client, id string, labels map[string]string) (*rtpUpConnection, error) {
|
func newUpConn(c group.Client, id string, labels map[string]string) (*rtpUpConnection, error) {
|
||||||
pc, err := c.Group().API().NewPeerConnection(
|
pc, err := c.Group().API().NewPeerConnection(*group.ICEConfiguration())
|
||||||
group.ToConfiguration(group.ICEConfiguration()),
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@ type clientMessage struct {
|
||||||
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
Candidate *webrtc.ICECandidateInit `json:"candidate,omitempty"`
|
||||||
Labels map[string]string `json:"labels,omitempty"`
|
Labels map[string]string `json:"labels,omitempty"`
|
||||||
Request rateMap `json:"request,omitempty"`
|
Request rateMap `json:"request,omitempty"`
|
||||||
RTCConfiguration *group.RTCConfiguration `json:"rtcConfiguration,omitempty"`
|
RTCConfiguration *webrtc.Configuration `json:"rtcConfiguration,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type closeMessage struct {
|
type closeMessage struct {
|
||||||
|
|
Loading…
Reference in a new issue