8
8
package rtmp
9
9
10
10
import (
11
+ "crypto/tls"
11
12
"net"
12
13
13
14
"github.com/pkg/errors"
@@ -17,6 +18,13 @@ func Dial(protocol, addr string, config *ConnConfig) (*ClientConn, error) {
17
18
return DialWithDialer (& net.Dialer {}, protocol , addr , config )
18
19
}
19
20
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
+
20
28
func DialWithDialer (dialer * net.Dialer , protocol , addr string , config * ConnConfig ) (* ClientConn , error ) {
21
29
if protocol != "rtmp" {
22
30
return nil , errors .Errorf ("Unknown protocol: %s" , protocol )
@@ -30,13 +38,15 @@ func DialWithDialer(dialer *net.Dialer, protocol, addr string, config *ConnConfi
30
38
return newClientConnWithSetup (rwc , config )
31
39
}
32
40
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 )
35
47
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
40
49
}
41
- return net .JoinHostPort (host , port ), nil
50
+
51
+ return newClientConnWithSetup (rwc , config )
42
52
}
0 commit comments