Fix redirect for rtspx source #565

This commit is contained in:
Alexey Khit
2023-08-23 06:07:23 +03:00
parent f5cca50830
commit 75a3dad745
4 changed files with 67 additions and 86 deletions
+2 -32
View File
@@ -1,14 +1,11 @@
package rtmp
import (
"crypto/tls"
"errors"
"net"
"net/url"
"strings"
"github.com/AlexxIT/go2rtc/pkg/core"
"github.com/AlexxIT/go2rtc/pkg/flv"
"github.com/AlexxIT/go2rtc/pkg/tcp"
)
func Dial(rawURL string) (core.Producer, error) {
@@ -17,38 +14,11 @@ func Dial(rawURL string) (core.Producer, error) {
return nil, err
}
var hostname string // without port
if i := strings.IndexByte(u.Host, ':'); i > 0 {
hostname = u.Host[:i]
} else {
hostname = u.Host
u.Host += ":1935"
}
conn, err := net.DialTimeout("tcp", u.Host, core.ConnDialTimeout)
conn, err := tcp.Dial(u, "1935")
if err != nil {
return nil, err
}
if u.Scheme != "rtmp" {
var conf *tls.Config
switch {
case u.Scheme == "rtmpx" || net.ParseIP(hostname) != nil:
conf = &tls.Config{InsecureSkipVerify: true}
case u.Scheme == "rtmps":
conf = &tls.Config{ServerName: hostname}
default:
return nil, errors.New("unsupported scheme: " + u.Scheme)
}
tlsConn := tls.Client(conn, conf)
if err = tlsConn.Handshake(); err != nil {
return nil, err
}
conn = tlsConn
}
rd, err := NewReader(u, conn)
if err != nil {
return nil, err