Description
There has been a discussion initiated on whether we might want to introduce an easier API for creating a TURN client in #276:
There is a slightly related PR in pion/stun#134, which introduces a new stun.DialURI()
function.
It can be used in conjunction with pion/turn.NewClient()
.
I am still pondering whether we also want to have a function in pion/turn to create a client directly by an TURN URI.
I think this would be a nice addition that would make the life of people that just want a quick TURN client connection a lot more easier. Currently it takes some 70 lines of code in the UDP example to create the socket, set up the Client, and then calling client.Listen and client.Allocate, it would ne a big win to cut this down to 1-5 lines for simple use cases that do not require a fully fledged client.
I'm wondering though how to pass the realm and the TURN credentials in to the Dial method, maybe we would need a simple Dialer that can hold these for the Dial?
I've introduced a new type in pion/stun
to pass additional settings to the stun.DialURI()
function:
// DialConfig is used to pass configuration to DialURI()
type DialConfig struct {
DTLSConfig dtls.Config
TLSConfig tls.Config
Net transport.Net
}
We could do the same for pion/turn
.
And thats where we probably need to discuss whether this addition would be a breaking API change as there exists already a ClientConfig
struct.
Maybe it could look something like this:
type ClientConfig struct {
stun.DialConfig
Username string
Password string
Realm string
Software string
RTO time.Duration
Conn net.PacketConn // Listening socket (net.PacketConn)
LoggerFactory logging.LoggerFactory
}
// Connect by conn and STUN/TURN server addresses
func NewClientFromConn(conn net.PacketConn, stunAddr net.Addr, turnAddr net.Addr, cfg *ClientConfig) (*Client, error) { ... }
// Connect by URI
func NewClientFromURI(uri stun.URI, *cfg ClientConfig) (*Client, error) { ... }
Ideas for a better API are welcome :)