Browse Source

httpoperation to api

webui
Ruben Cid 5 years ago
parent
commit
aebb5dafa1
  1. 4
      configure/channel.go
  2. 1
      configure/liveconfig.go
  3. 12
      main.go
  4. 16
      protocol/api/api.go

4
configure/channel.go

@ -27,6 +27,10 @@ func Init() { @@ -27,6 +27,10 @@ func Init() {
localCache: cache.New(cache.NoExpiration, 0),
}
if saveInLocal {
return
}
RoomKeys.redisCli = redis.NewClient(&redis.Options{
Addr: *GetRedisAddr(),
Password: *GetRedisPwd(),

1
configure/liveconfig.go

@ -37,7 +37,6 @@ type JWTCfg struct { @@ -37,7 +37,6 @@ type JWTCfg struct {
}
type ServerCfg struct {
DashBoard bool `json:"dashboard"`
KeyFile string `json:"key_file"`
RedisAddr string `json:"redis_addr"`
RedisPwd string `json:"redis_pwd"`
JWTCfg `json:"jwt"`

12
main.go

@ -7,9 +7,9 @@ import ( @@ -7,9 +7,9 @@ import (
"time"
"livego/configure"
"livego/protocol/api"
"livego/protocol/hls"
"livego/protocol/httpflv"
"livego/protocol/httpopera"
"livego/protocol/rtmp"
)
@ -89,20 +89,20 @@ func startHTTPFlv(stream *rtmp.RtmpStream) { @@ -89,20 +89,20 @@ func startHTTPFlv(stream *rtmp.RtmpStream) {
}()
}
func startHTTPOpera(stream *rtmp.RtmpStream) {
func startAPI(stream *rtmp.RtmpStream) {
if *operaAddr != "" {
opListen, err := net.Listen("tcp", *operaAddr)
if err != nil {
log.Fatal(err)
}
opServer := httpopera.NewServer(stream, *rtmpAddr)
opServer := api.NewServer(stream, *rtmpAddr)
go func() {
defer func() {
if r := recover(); r != nil {
log.Println("HTTP-Operation server panic: ", r)
log.Println("HTTP-API server panic: ", r)
}
}()
log.Println("HTTP-Operation listen On", *operaAddr)
log.Println("HTTP-API listen On", *operaAddr)
opServer.Serve(opListen)
}()
}
@ -124,7 +124,7 @@ func main() { @@ -124,7 +124,7 @@ func main() {
stream := rtmp.NewRtmpStream()
hlsServer := startHls()
startHTTPFlv(stream)
startHTTPOpera(stream)
startAPI(stream)
startRtmp(stream, hlsServer)
//startRtmp(stream, nil)

16
protocol/httpopera/http_opera.go → protocol/api/api.go

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
package httpopera
package api
import (
"encoding/json"
@ -338,14 +338,14 @@ func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) { @@ -338,14 +338,14 @@ func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
res.Status = 400
res.Data = "url: /control/reset?room=ROOM_NAME"
res.Data = "url: /control/reset?room=<ROOM_NAME>"
return
}
room := r.Form.Get("room")
if len(room) == 0 {
res.Status = 400
res.Data = "url: /control/get?room=ROOM_NAME"
res.Data = "url: /control/get?room=<ROOM_NAME>"
return
}
@ -370,7 +370,7 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request) { @@ -370,7 +370,7 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
res.Status = 400
res.Data = "url: /control/get?room=ROOM_NAME"
res.Data = "url: /control/get?room=<ROOM_NAME>"
return
}
@ -378,7 +378,7 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request) { @@ -378,7 +378,7 @@ func (s *Server) handleGet(w http.ResponseWriter, r *http.Request) {
if len(room) == 0 {
res.Status = 400
res.Data = "url: /control/get?room=ROOM_NAME"
res.Data = "url: /control/get?room=<ROOM_NAME>"
return
}
@ -401,7 +401,7 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) { @@ -401,7 +401,7 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
res.Status = 400
res.Data = "url: /control/delete?room=ROOM_NAME"
res.Data = "url: /control/delete?room=<ROOM_NAME>"
return
}
@ -409,7 +409,7 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) { @@ -409,7 +409,7 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) {
if len(room) == 0 {
res.Status = 400
res.Data = "url: /control/get?room=ROOM_NAME"
res.Data = "url: /control/get?room=<ROOM_NAME>"
return
}
@ -418,5 +418,5 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) { @@ -418,5 +418,5 @@ func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) {
return
}
res.Status = 404
res.Data = "Room not found"
res.Data = "room not found"
}
Loading…
Cancel
Save