Update package web with Quality structure

This commit is contained in:
Alexandre Iooss 2020-10-19 19:57:04 +02:00
parent d03d4fed40
commit d263f743f7
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
4 changed files with 15 additions and 14 deletions

View File

@ -153,19 +153,15 @@ func statisticsHandler(w http.ResponseWriter, r *http.Request) {
name := strings.SplitN(strings.Replace(r.URL.Path[7:], "/", "", -1), "@", 2)[0]
userCount := 0
// Get all substreams
for _, outputType := range []string{"", "@720p", "@480p", "@360p", "@240p", "@text"} {
// Get requested stream
stream, ok := streams[name+outputType]
if ok {
// Get number of output channels
userCount += stream.ClientCount()
}
// Get requested stream
stream, err := streams.Get(name)
if err == nil {
userCount = stream.ClientCount()
}
// Display connected users statistics
enc := json.NewEncoder(w)
err := enc.Encode(struct{ ConnectedViewers int }{userCount})
err = enc.Encode(struct{ ConnectedViewers int }{userCount})
if err != nil {
http.Error(w, "Failed to generate JSON.", http.StatusInternalServerError)
log.Printf("Failed to generate JSON: %s", err)

View File

@ -4,6 +4,8 @@ import (
"net/http"
"net/http/httptest"
"testing"
"gitlab.crans.org/nounous/ghostream/messaging"
)
func TestViewerPageGET(t *testing.T) {
@ -12,6 +14,9 @@ func TestViewerPageGET(t *testing.T) {
t.Errorf("Failed to load templates: %v", err)
}
// Init streams messaging
streams = messaging.New()
cfg = &Options{}
// Test GET request

View File

@ -11,7 +11,7 @@ import (
"github.com/markbates/pkger"
"github.com/pion/webrtc/v3"
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/messaging"
)
// Options holds web package configuration
@ -44,7 +44,7 @@ var (
templates *template.Template
// Streams to get statistics
streams map[string]*stream.Stream
streams *messaging.Streams
)
// Load templates with pkger
@ -78,7 +78,7 @@ func loadTemplates() error {
}
// Serve HTTP server
func Serve(s map[string]*stream.Stream, rSdpChan chan struct {
func Serve(s *messaging.Streams, rSdpChan chan struct {
StreamID string
RemoteDescription webrtc.SessionDescription
}, lSdpChan chan webrtc.SessionDescription, c *Options) {

View File

@ -5,13 +5,13 @@ import (
"testing"
"time"
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/messaging"
)
// TestHTTPServe tries to serve a real HTTP server and load some pages
func TestHTTPServe(t *testing.T) {
// Init streams messaging
streams := make(map[string]*stream.Stream)
streams := messaging.New()
// Create a disabled web server
go Serve(streams, nil, nil, &Options{Enabled: false, ListenAddress: "127.0.0.1:8081"})