|
|
@ -8,18 +8,45 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
type streamStats struct { |
|
|
|
messageIn int |
|
|
|
messageOut int |
|
|
|
maxUsers int |
|
|
|
start time.Time |
|
|
|
mutex sync.Mutex |
|
|
|
|
|
|
|
messageIn int |
|
|
|
messageOut int |
|
|
|
maxUsers int |
|
|
|
start time.Time |
|
|
|
mutex sync.Mutex |
|
|
|
streamStart time.Time |
|
|
|
streamLive bool // True if live
|
|
|
|
viewers map[string]string |
|
|
|
maxViewers int |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) addViewer(ip string) { |
|
|
|
s.mutex.Lock() |
|
|
|
s.viewers[ip] = ip |
|
|
|
s.updateMaxViewers(len(s.viewers)) |
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
common.LogDebugf("Viewer connect from: %s\n", ip) |
|
|
|
} |
|
|
|
func (s *streamStats) removeViewer(ip string) { |
|
|
|
s.mutex.Lock() |
|
|
|
delete(s.viewers, ip) |
|
|
|
s.mutex.Unlock() |
|
|
|
|
|
|
|
common.LogDebugf("Viewer left from: %s\n", ip) |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) updateMaxViewers(size int) { |
|
|
|
if s.maxViewers < size { |
|
|
|
s.maxViewers = size |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) resetViewers() { |
|
|
|
s.viewers = make(map[string]string) |
|
|
|
} |
|
|
|
|
|
|
|
func newStreamStats() streamStats { |
|
|
|
return streamStats{start: time.Now(), streamLive: false} |
|
|
|
return streamStats{start: time.Now(), streamLive: false, viewers: make(map[string]string)} |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) msgInInc() { |
|
|
@ -57,6 +84,7 @@ func (s *streamStats) Print() { |
|
|
|
common.LogInfof("Messages Out: %d\n", s.messageOut) |
|
|
|
common.LogInfof("Max users in chat: %d\n", s.maxUsers) |
|
|
|
common.LogInfof("Total Time: %s\n", time.Since(s.start)) |
|
|
|
common.LogInfof("Max Stream Viewer: %d\n", s.maxViewers) |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) startStream() { |
|
|
@ -83,3 +111,24 @@ func (s *streamStats) getStreamLength() time.Duration { |
|
|
|
} |
|
|
|
return time.Since(s.streamStart) |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) getViewerCount() int { |
|
|
|
s.mutex.Lock() |
|
|
|
defer s.mutex.Unlock() |
|
|
|
|
|
|
|
return len(s.viewers) |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) getMaxViewerCount() int { |
|
|
|
s.mutex.Lock() |
|
|
|
defer s.mutex.Unlock() |
|
|
|
|
|
|
|
return s.maxViewers |
|
|
|
} |
|
|
|
|
|
|
|
func (s *streamStats) getViewers() map[string]string { |
|
|
|
s.mutex.Lock() |
|
|
|
defer s.mutex.Unlock() |
|
|
|
|
|
|
|
return s.viewers |
|
|
|
} |
|
|
|