mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-27 19:12:07 +02:00
💩 Split webrtc tracks by stream id (need to clean this, stream ID must pass between the session descriptor and the webrtc flux transmit)
This commit is contained in:
@ -19,6 +19,21 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
// Limit response body to 128KB
|
||||
r.Body = http.MaxBytesReader(w, r.Body, 131072)
|
||||
|
||||
// Get stream ID from URL, or from domain name
|
||||
path := r.URL.Path[1:]
|
||||
if cfg.OneStreamPerDomain {
|
||||
host := r.Host
|
||||
if strings.Contains(host, ":") {
|
||||
realHost, _, err := net.SplitHostPort(r.Host)
|
||||
if err != nil {
|
||||
log.Printf("Failed to split host and port from %s", r.Host)
|
||||
return
|
||||
}
|
||||
host = realHost
|
||||
}
|
||||
path = host
|
||||
}
|
||||
|
||||
// Decode client description
|
||||
dec := json.NewDecoder(r.Body)
|
||||
dec.DisallowUnknownFields()
|
||||
@ -29,7 +44,10 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Exchange session descriptions with WebRTC stream server
|
||||
remoteSdpChan <- remoteDescription
|
||||
remoteSdpChan <- struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}{StreamID: path, RemoteDescription: remoteDescription}
|
||||
localDescription := <-localSdpChan
|
||||
|
||||
// Send server description as JSON
|
||||
@ -40,7 +58,10 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, _ = w.Write(jsonDesc)
|
||||
_, err = w.Write(jsonDesc)
|
||||
if err != nil {
|
||||
log.Println("An error occurred while sending session description", err)
|
||||
}
|
||||
|
||||
// Increment monitoring
|
||||
monitoring.WebSessions.Inc()
|
||||
|
12
web/web.go
12
web/web.go
@ -30,8 +30,11 @@ var (
|
||||
cfg *Options
|
||||
|
||||
// WebRTC session description channels
|
||||
remoteSdpChan chan webrtc.SessionDescription
|
||||
localSdpChan chan webrtc.SessionDescription
|
||||
remoteSdpChan chan struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}
|
||||
localSdpChan chan webrtc.SessionDescription
|
||||
|
||||
// Preload templates
|
||||
templates *template.Template
|
||||
@ -71,7 +74,10 @@ func loadTemplates() error {
|
||||
}
|
||||
|
||||
// Serve HTTP server
|
||||
func Serve(rSdpChan chan webrtc.SessionDescription, lSdpChan chan webrtc.SessionDescription, c *Options) {
|
||||
func Serve(rSdpChan chan struct {
|
||||
StreamID string
|
||||
RemoteDescription webrtc.SessionDescription
|
||||
}, lSdpChan chan webrtc.SessionDescription, c *Options) {
|
||||
remoteSdpChan = rSdpChan
|
||||
localSdpChan = lSdpChan
|
||||
cfg = c
|
||||
|
Reference in New Issue
Block a user