diff --git a/configs/config.yaml b/configs/config.yaml index a14103eb..e34c58ef 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -252,6 +252,13 @@ webrtc: # turn off default Pion interceptors (see: https://github.com/pion/interceptor) # (performance) disableDefaultInterceptors: + # indicates the role of the DTLS transport (see: https://github.com/pion/webrtc/blob/master/dtlsrole.go) + # (debug) + # - (default) + # - 1 (auto) + # - 2 (client) + # - 3 (server) + dtlsRole: # a list of STUN/TURN servers to use iceServers: - url: stun:stun.l.google.com:19302 diff --git a/pkg/config/webrtc/config.go b/pkg/config/webrtc/config.go index 34d089ea..292542af 100644 --- a/pkg/config/webrtc/config.go +++ b/pkg/config/webrtc/config.go @@ -4,6 +4,7 @@ import "github.com/giongto35/cloud-game/v2/pkg/config/encoder" type Webrtc struct { DisableDefaultInterceptors bool + DtlsRole byte IceServers []IceServer IcePorts struct { Min uint16 diff --git a/pkg/webrtc/connection.go b/pkg/webrtc/connection.go index 270e1967..9e15bfb5 100644 --- a/pkg/webrtc/connection.go +++ b/pkg/webrtc/connection.go @@ -36,6 +36,12 @@ func DefaultPeerConnection(conf conf.Webrtc) (*PeerConnection, error) { settingsOnce.Do(func() { settingEngine := pion.SettingEngine{} + if conf.DtlsRole > 0 { + log.Printf("A custom DTLS role [%v]", conf.DtlsRole) + if err := settingEngine.SetAnsweringDTLSRole(pion.DTLSRole(conf.DtlsRole)); err != nil { + panic(err) + } + } if conf.IcePorts.Min > 0 && conf.IcePorts.Max > 0 { if err := settingEngine.SetEphemeralUDPPortRange(conf.IcePorts.Min, conf.IcePorts.Max); err != nil { panic(err)