Browse Source

Naming & style

pull/176/head
Jianghai He 4 years ago
parent
commit
c8c232cb6b
  1. 44
      protocol/api/api.go

44
protocol/api/api.go

@ -199,7 +199,7 @@ func (server *Server) GetLiveStatics(w http.ResponseWriter, req *http.Request) {
res.Data = msgs res.Data = msgs
} }
//http://127.0.0.1:8090/control/pull?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456 //http://127.0.0.1:8090/control/pull?&oper=start&app=live&channel_key={channel_key}&url=rtmp://{pull_streaming_server}/live/movie
func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) { func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
var retString string var retString string
var err error var err error
@ -214,26 +214,26 @@ func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
if req.ParseForm() != nil { if req.ParseForm() != nil {
res.Status = 400 res.Status = 400
res.Data = "url: /control/pull?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456" res.Data = "url: /control/pull?&oper=start&app=live&channel_key={channel_key}&url=rtmp://{pull_streaming_server}/live/movie"
return return
} }
oper := req.Form.Get("oper") oper := req.Form.Get("oper")
app := req.Form.Get("app") app := req.Form.Get("app")
name := req.Form.Get("name") channelKey := req.Form.Get("channelKey")
url := req.Form.Get("url") url := req.Form.Get("url")
log.Debugf("control pull: oper=%v, app=%v, name=%v, url=%v", oper, app, name, url) log.Debugf("control pull: oper=%v, app=%v, channelKey=%v, url=%v", oper, app, channelKey, url)
if (len(app) <= 0) || (len(name) <= 0) || (len(url) <= 0) { if (len(app) <= 0) || (len(channelKey) <= 0) || (len(url) <= 0) {
res.Status = 400 res.Status = 400
res.Data = "control pull parameter error, please check them." res.Data = "control pull parameter error, please check them."
return return
} }
remoteurl := "rtmp://127.0.0.1" + s.rtmpAddr + "/" + app + "/" + name publishUrl := "rtmp://127.0.0.1" + s.rtmpAddr + "/" + app + "/" + channelKey
localurl := url playUrl := url
keyString := "pull:" + app + "/" + name keyString := "pull:" + app + "/" + channelKey
if oper == "stop" { if oper == "stop" {
pullRtmprelay, found := s.session[keyString] pullRtmprelay, found := s.session[keyString]
@ -243,7 +243,7 @@ func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
res.Data = retString res.Data = retString
return return
} }
log.Debugf("rtmprelay stop pull %s from %s", remoteurl, localurl) log.Debugf("rtmprelay stop pull %s from %s", publishUrl, playUrl)
pullRtmprelay.Stop() pullRtmprelay.Stop()
delete(s.session, keyString) delete(s.session, keyString)
@ -251,8 +251,8 @@ func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
res.Data = retString res.Data = retString
log.Debugf("pull stop return %s", retString) log.Debugf("pull stop return %s", retString)
} else { } else {
pullRtmprelay := rtmprelay.NewRtmpRelay(&localurl, &remoteurl) pullRtmprelay := rtmprelay.NewRtmpRelay(&playUrl, &publishUrl)
log.Debugf("rtmprelay start pull %s from %s", remoteurl, localurl) log.Debugf("rtmprelay start pull %s from %s", publishUrl, playUrl)
err = pullRtmprelay.Start() err = pullRtmprelay.Start()
if err != nil { if err != nil {
retString = fmt.Sprintf("pull error=%v", err) retString = fmt.Sprintf("pull error=%v", err)
@ -267,7 +267,7 @@ func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
} }
} }
//http://127.0.0.1:8090/control/push?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456 //http://127.0.0.1:8090/control/push?&oper=start&app=live&channel_key={channel_key}&url=rtmp://{push_streaming_server}/live/movie
func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) { func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
var retString string var retString string
var err error var err error
@ -281,26 +281,26 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
defer res.SendJson() defer res.SendJson()
if req.ParseForm() != nil { if req.ParseForm() != nil {
res.Data = "url: /control/push?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456" res.Data = "url: /control/push?&oper=start&app=live&channel_key={channel_key}&url=rtmp://{push_streaming_server}/live/movie"
return return
} }
oper := req.Form.Get("oper") oper := req.Form.Get("oper")
app := req.Form.Get("app") app := req.Form.Get("app")
name := req.Form.Get("name") channelKey := req.Form.Get("channel_key")
url := req.Form.Get("url") url := req.Form.Get("url")
log.Debugf("control push: oper=%v, app=%v, name=%v, url=%v", oper, app, name, url) log.Debugf("control push: oper=%v, app=%v, channelKey=%v, url=%v", oper, app, channelKey, url)
if (len(app) <= 0) || (len(name) <= 0) || (len(url) <= 0) { if (len(app) <= 0) || (len(channelKey) <= 0) || (len(url) <= 0) {
res.Status = 400 res.Status = 400
res.Data = "control push parameter error, please check them." res.Data = "control push parameter error, please check them."
return return
} }
localurl := "rtmp://127.0.0.1" + s.rtmpAddr + "/" + app + "/" + name playUrl := "rtmp://127.0.0.1" + s.rtmpAddr + "/" + app + "/" + channelKey
remoteurl := url publishUrl := url
keyString := "push:" + app + "/" + name keyString := "push:" + app + "/" + channelKey
if oper == "stop" { if oper == "stop" {
pushRtmprelay, found := s.session[keyString] pushRtmprelay, found := s.session[keyString]
if !found { if !found {
@ -309,7 +309,7 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
res.Data = retString res.Data = retString
return return
} }
log.Debugf("rtmprelay stop push %s from %s", remoteurl, localurl) log.Debugf("rtmprelay stop push %s from %s", publishUrl, playUrl)
pushRtmprelay.Stop() pushRtmprelay.Stop()
delete(s.session, keyString) delete(s.session, keyString)
@ -317,8 +317,8 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
res.Data = retString res.Data = retString
log.Debugf("push stop return %s", retString) log.Debugf("push stop return %s", retString)
} else { } else {
pushRtmprelay := rtmprelay.NewRtmpRelay(&localurl, &remoteurl) pushRtmprelay := rtmprelay.NewRtmpRelay(&playUrl, &publishUrl)
log.Debugf("rtmprelay start push %s from %s", remoteurl, localurl) log.Debugf("rtmprelay start push %s from %s", publishUrl, playUrl)
err = pushRtmprelay.Start() err = pushRtmprelay.Start()
if err != nil { if err != nil {
retString = fmt.Sprintf("push error=%v", err) retString = fmt.Sprintf("push error=%v", err)

Loading…
Cancel
Save