FIX utils.Conf() would not read easy-darwin.ini configuration due to Server Object initialization

pull/224/head
Quanqi Gu 4 years ago
parent 53642936b5
commit f9f4fd6950

@ -49,7 +49,7 @@ func (h *APIHandler) Pushers(c *gin.Context) {
} }
hostname := utils.GetRequestHostname(c.Request) hostname := utils.GetRequestHostname(c.Request)
pushers := make([]interface{}, 0) pushers := make([]interface{}, 0)
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
port := pusher.Server().TCPPort port := pusher.Server().TCPPort
rtsp := fmt.Sprintf("rtsp://%s:%d%s", hostname, port, pusher.Path()) rtsp := fmt.Sprintf("rtsp://%s:%d%s", hostname, port, pusher.Path())
if port == 554 { if port == 554 {
@ -102,7 +102,7 @@ func (h *APIHandler) Players(c *gin.Context) {
return return
} }
players := make([]*rtsp.Player, 0) players := make([]*rtsp.Player, 0)
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
for _, player := range pusher.GetPlayers() { for _, player := range pusher.GetPlayers() {
players = append(players, player) players = append(players, player)
} }

@ -50,9 +50,9 @@ func init() {
now := utils.DateTime(time.Now()) now := utils.DateTime(time.Now())
memData = append(memData, PercentData{Time: now, Used: mem.UsedPercent / 100}) memData = append(memData, PercentData{Time: now, Used: mem.UsedPercent / 100})
cpuData = append(cpuData, PercentData{Time: now, Used: cpu[0] / 100}) cpuData = append(cpuData, PercentData{Time: now, Used: cpu[0] / 100})
pusherData = append(pusherData, CountData{Time: now, Total: uint(rtsp.Instance.GetPusherSize())}) pusherData = append(pusherData, CountData{Time: now, Total: uint(rtsp.GetServer().GetPusherSize())})
playerCnt := 0 playerCnt := 0
for _, pusher := range rtsp.Instance.GetPushers() { for _, pusher := range rtsp.GetServer().GetPushers() {
playerCnt += len(pusher.GetPlayers()) playerCnt += len(pusher.GetPlayers())
} }
playerData = append(playerData, CountData{Time: now, Total: uint(playerCnt)}) playerData = append(playerData, CountData{Time: now, Total: uint(playerCnt)})

@ -27,17 +27,23 @@ type Server struct {
removePusherCh chan *Pusher removePusherCh chan *Pusher
} }
var Instance *Server = &Server{ var (
SessionLogger: SessionLogger{log.New(os.Stdout, "[RTSPServer]", log.LstdFlags|log.Lshortfile)}, instance *Server
Stoped: true, once sync.Once
TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554), )
pushers: make(map[string]*Pusher),
addPusherCh: make(chan *Pusher),
removePusherCh: make(chan *Pusher),
}
func GetServer() *Server { func GetServer() *Server {
return Instance once.Do(func() {
instance = &Server{
SessionLogger: SessionLogger{log.New(os.Stdout, "[RTSPServer]", log.LstdFlags|log.Lshortfile)},
Stoped: true,
TCPPort: utils.Conf().Section("rtsp").Key("port").MustInt(554),
pushers: make(map[string]*Pusher),
addPusherCh: make(chan *Pusher),
removePusherCh: make(chan *Pusher),
}
})
return instance
} }
func (server *Server) Start() (err error) { func (server *Server) Start() (err error) {

Loading…
Cancel
Save