Update tcp.Dial func

This commit is contained in:
Alex X
2023-09-17 14:11:47 +03:00
parent 4dffceaf7e
commit 8163c7a520
3 changed files with 14 additions and 5 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ func Dial(rawURL string) (core.Producer, error) {
return nil, err
}
conn, err := tcp.Dial(u, "1935", core.ConnDialTimeout)
conn, err := tcp.Dial(u, core.ConnDialTimeout)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -35,7 +35,7 @@ func (c *Conn) Dial() (err error) {
if c.Timeout != 0 {
timeout = time.Second * time.Duration(c.Timeout)
}
conn, err = tcp.Dial(c.URL, "554", timeout)
conn, err = tcp.Dial(c.URL, timeout)
} else {
conn, err = websocket.Dial(c.Transport)
}
+12 -3
View File
@@ -10,13 +10,22 @@ import (
)
// Dial - for RTSP(S|X) and RTMP(S|X)
func Dial(u *url.URL, port string, timeout time.Duration) (net.Conn, error) {
func Dial(u *url.URL, timeout time.Duration) (net.Conn, error) {
var address string
var hostname string // without port
if i := strings.IndexByte(u.Host, ':'); i > 0 {
address = u.Host
hostname = u.Host[:i]
} else {
switch u.Scheme {
case "rtsp", "rtsps", "rtspx":
address = u.Host + ":554"
case "rtmp":
address = u.Host + ":1935"
case "rtmps", "rtmpx":
address = u.Host + ":443"
}
hostname = u.Host
u.Host += ":" + port
}
var secure *tls.Config
@@ -33,7 +42,7 @@ func Dial(u *url.URL, port string, timeout time.Duration) (net.Conn, error) {
return nil, errors.New("unsupported scheme: " + u.Scheme)
}
conn, err := net.DialTimeout("tcp", u.Host, timeout)
conn, err := net.DialTimeout("tcp", address, timeout)
if err != nil {
return nil, err
}