Started using session interface again - tested and everything seems to be working

This commit is contained in:
saxon 2018-08-10 22:17:01 +09:30
parent 1c7fc111f0
commit ed536b2cdd
1 changed files with 11 additions and 5 deletions

View File

@ -215,8 +215,14 @@ var RTMPProtocolStringsLower = [...]string{
"rtmfp", "rtmfp",
} }
type Session interface {
Open() error
Write([]byte) (int, error)
Close() error
}
// session provides parameters required for an rtmp communication session. // session provides parameters required for an rtmp communication session.
type Session struct { type session struct {
rtmp *C.RTMP rtmp *C.RTMP
url string url string
timeout uint timeout uint
@ -374,7 +380,7 @@ type C_AMFObject struct {
// NewSession returns a new session. // NewSession returns a new session.
func NewSession(url string, connectTimeout uint) Session { func NewSession(url string, connectTimeout uint) Session {
return Session{ return &session{
url: url, url: url,
timeout: connectTimeout, timeout: connectTimeout,
} }
@ -382,7 +388,7 @@ func NewSession(url string, connectTimeout uint) Session {
// Open establishes an rtmp connection with the url passed into the // Open establishes an rtmp connection with the url passed into the
// constructor // constructor
func (s *Session) Open() error { func (s *session) Open() error {
if s.rtmp != nil { if s.rtmp != nil {
return errors.New("rtmp: attempt to start already running session") return errors.New("rtmp: attempt to start already running session")
} }
@ -395,7 +401,7 @@ func (s *Session) Open() error {
} }
// Close terminates the rtmp connection // Close terminates the rtmp connection
func (s *Session) Close() error { func (s *session) Close() error {
if s.rtmp == nil { if s.rtmp == nil {
return Err(3) return Err(3)
} }
@ -408,7 +414,7 @@ func (s *Session) Close() error {
} }
// Write writes a frame (flv tag) to the rtmp connection // Write writes a frame (flv tag) to the rtmp connection
func (s *Session) Write(data []byte) (int, error) { func (s *session) Write(data []byte) (int, error) {
if s.rtmp == nil { if s.rtmp == nil {
return 0, Err(3) return 0, Err(3)
} }