88package rtmp
99
1010import (
11+ "crypto/tls"
1112 "net"
1213
1314 "github.com/pkg/errors"
@@ -17,6 +18,13 @@ func Dial(protocol, addr string, config *ConnConfig) (*ClientConn, error) {
1718 return DialWithDialer (& net.Dialer {}, protocol , addr , config )
1819}
1920
21+ func TLSDial (protocol , addr string , config * ConnConfig , tlsConfig * tls.Config ) (* ClientConn , error ) {
22+ return DialWithTLSDialer (& tls.Dialer {
23+ NetDialer : & net.Dialer {},
24+ Config : tlsConfig ,
25+ }, protocol , addr , config )
26+ }
27+
2028func DialWithDialer (dialer * net.Dialer , protocol , addr string , config * ConnConfig ) (* ClientConn , error ) {
2129 if protocol != "rtmp" {
2230 return nil , errors .Errorf ("Unknown protocol: %s" , protocol )
@@ -30,13 +38,15 @@ func DialWithDialer(dialer *net.Dialer, protocol, addr string, config *ConnConfi
3038 return newClientConnWithSetup (rwc , config )
3139}
3240
33- func makeValidAddr (addr string ) (string , error ) {
34- host , port , err := net .SplitHostPort (addr )
41+ func DialWithTLSDialer (dialer * tls.Dialer , protocol , addr string , config * ConnConfig ) (* ClientConn , error ) {
42+ if protocol != "rtmps" {
43+ return nil , errors .Errorf ("Unknown protocol: %s" , protocol )
44+ }
45+
46+ rwc , err := dialer .Dial ("tcp" , addr )
3547 if err != nil {
36- if err , ok := err .(* net.AddrError ); ok && err .Err == "missing port in address" {
37- return makeValidAddr (addr + ":1935" ) // Default RTMP port
38- }
39- return "" , err
48+ return nil , err
4049 }
41- return net .JoinHostPort (host , port ), nil
50+
51+ return newClientConnWithSetup (rwc , config )
4252}
0 commit comments