Add support RTSP over WebSocket

This commit is contained in:
Alexey Khit
2023-05-06 14:31:46 +03:00
parent 3139189975
commit 8b126c0d37
6 changed files with 258 additions and 36 deletions
+44
View File
@@ -0,0 +1,44 @@
package rtsp
import (
"crypto/tls"
"errors"
"net"
"net/url"
"strings"
"time"
)
func Dial(uri string) (net.Conn, error) {
u, err := url.Parse(uri)
if err != nil {
return nil, err
}
switch u.Scheme {
case "rtsp":
return dialTCP(u.Host, nil)
case "rtsps":
tlsConf := &tls.Config{ServerName: u.Hostname()}
return dialTCP(u.Host, tlsConf)
case "rtspx":
tlsConf := &tls.Config{InsecureSkipVerify: true}
return dialTCP(u.Host, tlsConf)
}
return nil, errors.New("unsupported scheme: " + u.Scheme)
}
func dialTCP(address string, tlsConf *tls.Config) (net.Conn, error) {
if strings.IndexByte(address, ':') < 0 {
address += ":554"
}
conn, err := net.DialTimeout("tcp", address, time.Second*5)
if tlsConf == nil || err != nil {
return conn, err
}
tlsConn := tls.Client(conn, tlsConf)
return tlsConn, tlsConn.Handshake()
}