This commit is contained in:
et
2022-12-29 16:39:58 +08:00
parent e62ab20c32
commit 3b93822813
3 changed files with 23 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package rtmp
import (
"bufio"
"crypto/tls"
"errors"
"net"
"net/url"
@@ -18,16 +19,28 @@ func NewRTMPClient(addr string) (client *NetConnection, err error) {
RTMPPlugin.Error("connect url parse", zap.Error(err))
return nil, err
}
isRtmps := u.Scheme == "rtmps"
if strings.Count(u.Host, ":") == 0 {
u.Host += ":1935"
if isRtmps {
u.Host += ":443"
} else {
u.Host += ":1935"
}
}
var conn net.Conn
if isRtmps {
var tlsconn *tls.Conn
tlsconn, err = tls.Dial("tcp", u.Host, &tls.Config{})
conn = tlsconn
} else {
conn, err = net.Dial("tcp", u.Host)
}
conn, err := net.Dial("tcp", u.Host)
if err != nil {
RTMPPlugin.Error("dial tcp", zap.String("host", u.Host), zap.Error(err))
return nil, err
}
client = &NetConnection{
TCPConn: conn.(*net.TCPConn),
Conn: conn,
Reader: bufio.NewReader(conn),
writeChunkSize: conf.ChunkSize,
readChunkSize: RTMP_DEFAULT_CHUNK_SIZE,

View File

@@ -76,7 +76,7 @@ func newPlayResponseMessageData(streamid uint32, code, level string) (amfobj AMF
type NetConnection struct {
*bufio.Reader `json:"-"`
*net.TCPConn `json:"-"`
net.Conn `json:"-"`
bandwidth uint32
readSeqNum uint32 // 当前读的字节
writeSeqNum uint32 // 当前写的字节

View File

@@ -39,7 +39,7 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) {
senders := make(map[uint32]*RTMPSubscriber)
receivers := make(map[uint32]*RTMPReceiver)
nc := &NetConnection{
TCPConn: conn,
Conn: conn,
Reader: bufio.NewReader(conn),
writeChunkSize: RTMP_DEFAULT_CHUNK_SIZE,
readChunkSize: RTMP_DEFAULT_CHUNK_SIZE,
@@ -71,8 +71,11 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) {
case *CallMessage: //connect
app := cmd.Object["app"] // 客户端要连接到的服务应用名
objectEncoding := cmd.Object["objectEncoding"] // AMF编码方法
if objectEncoding != nil {
nc.objectEncoding = objectEncoding.(float64)
switch v := objectEncoding.(type) {
case float64:
nc.objectEncoding = v
default:
nc.objectEncoding = 0
}
nc.appName = app.(string)
RTMPPlugin.Info("connect", zap.String("appName", nc.appName), zap.Float64("objectEncoding", nc.objectEncoding))