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

View File

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

View File

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

View File

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