Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtmp: create methods to allow API caller to instanciate its own Listener/etc #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions format/rtmp/rtmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func (self *Server) ListenAndServe() (err error) {
fmt.Println("rtmp: server: listening on", addr)
}

return self.Serve(listener)
}

// Serve will accept connections on a given net.Listener and instanciate
// RTMP clients for each connection.
func (self *Server) Serve(listener net.Listener) (err error) {
for {
var netconn net.Conn
if netconn, err = listener.Accept(); err != nil {
Expand All @@ -112,17 +118,23 @@ func (self *Server) ListenAndServe() (err error) {
fmt.Println("rtmp: server: accepted")
}

conn := NewConn(netconn)
conn.isserver = true
go func() {
err := self.handleConn(conn)
err := self.Server(netconn)
if Debug {
fmt.Println("rtmp: server: client closed err:", err)
}
}()
}
}

// Server will initiate server-side RTMP protocol negociation on a given
// net.Conn.
func (self *Server) Server(netconn net.Conn) error {
conn := NewConn(netconn)
conn.isserver = true
return self.handleConn(conn)
}

const (
stageHandshakeDone = iota + 1
stageCommandDone
Expand Down