4 changed files with 175 additions and 144 deletions
@ -1,18 +1,44 @@ |
|||||||
package rtmp |
package rtmp |
||||||
|
|
||||||
import ( |
import ( |
||||||
|
"bufio" |
||||||
|
"context" |
||||||
|
"net" |
||||||
|
"net/url" |
||||||
|
|
||||||
"github.com/notedit/rtmp/format/rtmp" |
"github.com/notedit/rtmp/format/rtmp" |
||||||
) |
) |
||||||
|
|
||||||
// Dial connects to a server in reading mode.
|
// DialContext connects to a server in reading mode.
|
||||||
func Dial(address string) (*Conn, error) { |
func DialContext(ctx context.Context, address string) (*Conn, error) { |
||||||
rconn, nconn, err := rtmp.NewClient().Dial(address, rtmp.PrepareReading) |
// https://github.com/aler9/rtmp/blob/master/format/rtmp/client.go#L74
|
||||||
|
|
||||||
|
u, err := url.Parse(address) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
host := rtmp.UrlGetHost(u) |
||||||
|
|
||||||
|
var d net.Dialer |
||||||
|
nconn, err := d.DialContext(ctx, "tcp", host) |
||||||
if err != nil { |
if err != nil { |
||||||
return nil, err |
return nil, err |
||||||
} |
} |
||||||
|
|
||||||
|
rw := &bufio.ReadWriter{ |
||||||
|
Reader: bufio.NewReaderSize(nconn, 4096), |
||||||
|
Writer: bufio.NewWriterSize(nconn, 4096), |
||||||
|
} |
||||||
|
rconn := rtmp.NewConn(rw) |
||||||
|
rconn.URL = u |
||||||
|
|
||||||
return &Conn{ |
return &Conn{ |
||||||
rconn: rconn, |
rconn: rconn, |
||||||
nconn: nconn, |
nconn: nconn, |
||||||
}, nil |
}, nil |
||||||
} |
} |
||||||
|
|
||||||
|
// ClientHandshake performs the handshake of a client-side connection.
|
||||||
|
func (c *Conn) ClientHandshake() error { |
||||||
|
return c.rconn.Prepare(rtmp.StageGotPublishOrPlayCommand, rtmp.PrepareReading) |
||||||
|
} |
||||||
|
|||||||
Loading…
Reference in new issue