mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 04:00:55 +02:00
Put webrtc SDP inside Quality struct
This commit is contained in:
@ -51,12 +51,27 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
// Get requested stream
|
||||
stream, err := streams.Get(path)
|
||||
if err != nil {
|
||||
http.Error(w, "Stream not found", http.StatusNotFound)
|
||||
log.Printf("Stream not found: %s", path)
|
||||
return
|
||||
}
|
||||
|
||||
// Get requested quality
|
||||
// FIXME: extract quality from request
|
||||
qualityName := "source"
|
||||
q, err := stream.GetQuality(qualityName)
|
||||
if err != nil {
|
||||
http.Error(w, "Quality not found", http.StatusNotFound)
|
||||
log.Printf("Quality not found: %s", qualityName)
|
||||
return
|
||||
}
|
||||
|
||||
// Exchange session descriptions with WebRTC stream server
|
||||
remoteSdpChan <- struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}{StreamID: path, RemoteDescription: remoteDescription}
|
||||
localDescription := <-localSdpChan
|
||||
q.WebRtcRemoteSdp <- remoteDescription
|
||||
localDescription := <-q.WebRtcLocalSdp
|
||||
|
||||
// Send server description as JSON
|
||||
jsonDesc, err := json.Marshal(localDescription)
|
||||
|
15
web/web.go
15
web/web.go
@ -10,7 +10,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/markbates/pkger"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"gitlab.crans.org/nounous/ghostream/messaging"
|
||||
)
|
||||
|
||||
@ -33,13 +32,6 @@ type Options struct {
|
||||
var (
|
||||
cfg *Options
|
||||
|
||||
// WebRTC session description channels
|
||||
remoteSdpChan chan struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}
|
||||
localSdpChan chan webrtc.SessionDescription
|
||||
|
||||
// Preload templates
|
||||
templates *template.Template
|
||||
|
||||
@ -78,13 +70,8 @@ func loadTemplates() error {
|
||||
}
|
||||
|
||||
// Serve HTTP server
|
||||
func Serve(s *messaging.Streams, rSdpChan chan struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}, lSdpChan chan webrtc.SessionDescription, c *Options) {
|
||||
func Serve(s *messaging.Streams, c *Options) {
|
||||
streams = s
|
||||
remoteSdpChan = rSdpChan
|
||||
localSdpChan = lSdpChan
|
||||
cfg = c
|
||||
|
||||
if !cfg.Enabled {
|
||||
|
@ -14,7 +14,7 @@ func TestHTTPServe(t *testing.T) {
|
||||
streams := messaging.New()
|
||||
|
||||
// Create a disabled web server
|
||||
go Serve(streams, nil, nil, &Options{Enabled: false, ListenAddress: "127.0.0.1:8081"})
|
||||
go Serve(streams, &Options{Enabled: false, ListenAddress: "127.0.0.1:8081"})
|
||||
|
||||
// Sleep 500ms to ensure that the web server is running, to avoid fails because the request came too early
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
@ -26,7 +26,7 @@ func TestHTTPServe(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now let's really start the web server
|
||||
go Serve(streams, nil, nil, &Options{Enabled: true, ListenAddress: "127.0.0.1:8081"})
|
||||
go Serve(streams, &Options{Enabled: true, ListenAddress: "127.0.0.1:8081"})
|
||||
|
||||
// Sleep 500ms to ensure that the web server is running, to avoid fails because the request came too early
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
Reference in New Issue
Block a user