From 025a5b1b0cf97ebae0be2e465f34a1e781babb94 Mon Sep 17 00:00:00 2001 From: Mark Karpeles Date: Tue, 3 Jul 2018 17:15:37 +0900 Subject: [PATCH] create methods to allow API caller to instanciate its own Listener/etc --- format/rtmp/rtmp.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/format/rtmp/rtmp.go b/format/rtmp/rtmp.go index 212ee06c..5de06115 100644 --- a/format/rtmp/rtmp.go +++ b/format/rtmp/rtmp.go @@ -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 { @@ -112,10 +118,8 @@ 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) } @@ -123,6 +127,14 @@ func (self *Server) ListenAndServe() (err error) { } } +// 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