Browse Source

fix manage page

pull/83/head
DKing 6 years ago
parent
commit
8f69e4d760
  1. 20
      configure/channel.go
  2. 10
      container/flv/muxer.go
  3. 70
      protocol/httpopera/http_opera.go

20
configure/channel.go

@ -109,6 +109,26 @@ func (r *RoomKeysType) GetChannel(key string) string { @@ -109,6 +109,26 @@ func (r *RoomKeysType) GetChannel(key string) string {
}
}
func (r *RoomKeysType) DeleteChannel(channel string) bool {
key, ok := r.mapChanKey.Load(channel)
if ok {
r.mapChanKey.Delete(channel)
r.mapKeyChan.Delete(key)
return true
}
return false
}
func (r *RoomKeysType) DeleteKey(key string) bool {
channel, ok := r.mapKeyChan.Load(key)
if ok {
r.mapChanKey.Delete(channel)
r.mapKeyChan.Delete(key)
return true
}
return false
}
// helpers
var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

10
container/flv/muxer.go

@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"path"
"strings"
"time"
@ -16,9 +17,10 @@ import ( @@ -16,9 +17,10 @@ import (
var (
flvHeader = []byte{0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09}
flvFile = flag.String("filFile", "./out.flv", "output flv file name")
flvDir = flag.String("flvDir", "tmp", "output flv file at flvDir/APP/KEY_TIME.flv")
)
/*
func NewFlv(handler av.Handler, info av.Info) {
patths := strings.SplitN(info.Key, "/", 2)
@ -41,6 +43,7 @@ func NewFlv(handler av.Handler, info av.Info) { @@ -41,6 +43,7 @@ func NewFlv(handler av.Handler, info av.Info) {
log.Println("close flv file")
writer.ctx.Close()
}
*/
const (
headerLen = 11
@ -144,18 +147,17 @@ type FlvDvr struct{} @@ -144,18 +147,17 @@ type FlvDvr struct{}
func (f *FlvDvr) GetWriter(info av.Info) av.WriteCloser {
paths := strings.SplitN(info.Key, "/", 2)
if len(paths) != 2 {
log.Println("invalid info")
return nil
}
err := os.MkdirAll(paths[0], 0755)
err := os.MkdirAll(path.Join(*flvDir, paths[0]), 0755)
if err != nil {
log.Println("mkdir error:", err)
return nil
}
fileName := fmt.Sprintf("%s_%d.%s", info.Key, time.Now().Unix(), "flv")
fileName := fmt.Sprintf("%s_%d.%s", path.Join(*flvDir, info.Key), time.Now().Unix(), "flv")
log.Println("flv dvr save stream to: ", fileName)
w, err := os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0755)
if err != nil {

70
protocol/httpopera/http_opera.go

@ -3,6 +3,7 @@ package httpopera @@ -3,6 +3,7 @@ package httpopera
import (
"encoding/json"
"fmt"
"github.com/gwuhaolin/livego/configure"
"io"
"log"
"net"
@ -61,7 +62,7 @@ func NewServer(h av.Handler, rtmpAddr string) *Server { @@ -61,7 +62,7 @@ func NewServer(h av.Handler, rtmpAddr string) *Server {
func (s *Server) Serve(l net.Listener) error {
mux := http.NewServeMux()
mux.Handle("/statics", http.FileServer(http.Dir("statics")))
mux.Handle("/statics/", http.StripPrefix("/statics/", http.FileServer(http.Dir("statics"))))
mux.HandleFunc("/control/push", func(w http.ResponseWriter, r *http.Request) {
s.handlePush(w, r)
@ -69,6 +70,15 @@ func (s *Server) Serve(l net.Listener) error { @@ -69,6 +70,15 @@ func (s *Server) Serve(l net.Listener) error {
mux.HandleFunc("/control/pull", func(w http.ResponseWriter, r *http.Request) {
s.handlePull(w, r)
})
mux.HandleFunc("/control/get", func(w http.ResponseWriter, r *http.Request) {
s.handleGet(w, r)
})
mux.HandleFunc("/control/reset", func(w http.ResponseWriter, r *http.Request) {
s.handleReset(w, r)
})
mux.HandleFunc("/control/delete", func(w http.ResponseWriter, r *http.Request) {
s.handleDelete(w, r)
})
mux.HandleFunc("/stat/livestat", func(w http.ResponseWriter, r *http.Request) {
s.GetLiveStatics(w, r)
})
@ -78,12 +88,12 @@ func (s *Server) Serve(l net.Listener) error { @@ -78,12 +88,12 @@ func (s *Server) Serve(l net.Listener) error {
type stream struct {
Key string `json:"key"`
Url string `json:"Url"`
StreamId uint32 `json:"StreamId"`
VideoTotalBytes uint64 `json:123456`
VideoSpeed uint64 `json:123456`
AudioTotalBytes uint64 `json:123456`
AudioSpeed uint64 `json:123456`
Url string `json:"url"`
StreamId uint32 `json:"stream_id"`
VideoTotalBytes uint64 `json:"video_total_bytes"`
VideoSpeed uint64 `json:"video_speed"`
AudioTotalBytes uint64 `json:"audio_total_bytes"`
AudioSpeed uint64 `json:"audio_speed"`
}
type streams struct {
@ -135,12 +145,15 @@ func (server *Server) GetLiveStatics(w http.ResponseWriter, req *http.Request) { @@ -135,12 +145,15 @@ func (server *Server) GetLiveStatics(w http.ResponseWriter, req *http.Request) {
w.Write(resp)
}
//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/pull?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456
func (s *Server) handlePull(w http.ResponseWriter, req *http.Request) {
var retString string
var err error
req.ParseForm()
if req.ParseForm() != nil {
fmt.Fprintf(w, "url: /control/pull?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456")
return
}
oper := req.Form["oper"]
app := req.Form["app"]
@ -192,7 +205,10 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) { @@ -192,7 +205,10 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
var retString string
var err error
req.ParseForm()
if req.ParseForm() != nil {
fmt.Fprintf(w, "url: /control/push?&oper=start&app=live&name=123456&url=rtmp://192.168.16.136/live/123456")
return
}
oper := req.Form["oper"]
app := req.Form["app"]
@ -238,3 +254,37 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) { @@ -238,3 +254,37 @@ func (s *Server) handlePush(w http.ResponseWriter, req *http.Request) {
log.Printf("push start return %s", retString)
}
}
//http://127.0.0.1:8090/control/reset?room=ROOM_NAME
func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) {
if r.ParseForm() != nil {
fmt.Fprintf(w, "url: /control/reset?room=ROOM_NAME")
return
}
room := r.Form["room"][0]
fmt.Fprintf(w, configure.RoomKeys.SetKey(room))
}
//http://127.0.0.1:8090/control/get?room=ROOM_NAME
func (s *Server) handleGet(w http.ResponseWriter, r *http.Request) {
if r.ParseForm() != nil {
fmt.Fprintf(w, "url: /control/get?room=ROOM_NAME")
return
}
room := r.Form["room"][0]
fmt.Fprintf(w, configure.RoomKeys.GetKey(room))
}
//http://127.0.0.1:8090/control/delete?room=ROOM_NAME
func (s *Server) handleDelete(w http.ResponseWriter, r *http.Request) {
if r.ParseForm() != nil {
fmt.Fprintf(w, "url: /control/delete?room=ROOM_NAME")
return
}
room := r.Form["room"][0]
if configure.RoomKeys.DeleteChannel(room) {
fmt.Fprintf(w, "OK")
} else {
fmt.Fprintf(w, "Room Not Found")
}
}

Loading…
Cancel
Save