UPnP/SSDP: respond with multiple service descriptors
Instead of violating the standard and putting multiple locations in one SSDP response, just send a single response for each possible location.
This commit is contained in:
parent
a19aa86c4e
commit
ca2bf7ff25
@ -23,7 +23,6 @@ package upnp_ssdp
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -104,26 +103,21 @@ func (c *Client) Response(message gossdp.ResponseMessage) {
|
||||
}
|
||||
|
||||
logger.Debug().Msg("UPnP/SSDP message received")
|
||||
c.appendURLs(message.Location)
|
||||
c.appendURL(message.Location)
|
||||
}
|
||||
|
||||
func (c *Client) appendURLs(location string) {
|
||||
urls := strings.Split(location, LocationSeparator)
|
||||
|
||||
func (c *Client) appendURL(url string) {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
|
||||
// Only append URLs that we haven't seen yet.
|
||||
for _, url := range urls {
|
||||
if c.seenURLs[url] {
|
||||
continue
|
||||
return
|
||||
}
|
||||
c.urls = append(c.urls, url)
|
||||
c.seenURLs[url] = true
|
||||
}
|
||||
|
||||
c.log.Debug().
|
||||
Int("new", len(urls)).
|
||||
Int("total", len(c.urls)).
|
||||
Msg("new URLs received")
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ package upnp_ssdp
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/fromkeith/gossdp"
|
||||
"github.com/rs/zerolog"
|
||||
@ -62,12 +61,9 @@ func (s *Server) AddAdvertisement(serviceLocation string) {
|
||||
// AddAdvertisementURLs constructs a service location from the given URLs, and
|
||||
// adds the advertisement for it.
|
||||
func (s *Server) AddAdvertisementURLs(urls []url.URL) {
|
||||
urlStrings := make([]string, len(urls))
|
||||
for idx := range urls {
|
||||
urlStrings[idx] = urls[idx].String()
|
||||
for _, url := range urls {
|
||||
s.AddAdvertisement(url.String())
|
||||
}
|
||||
location := strings.Join(urlStrings, LocationSeparator)
|
||||
s.AddAdvertisement(location)
|
||||
}
|
||||
|
||||
// Run starts the advertisement, and blocks until the context is closed.
|
||||
|
@ -24,6 +24,4 @@ package upnp_ssdp
|
||||
const (
|
||||
FlamencoUUID = "aa80bc5f-d0af-46b8-8630-23bd7e80ec4d"
|
||||
FlamencoServiceType = "urn:flamenco:manager:0"
|
||||
|
||||
LocationSeparator = ";"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user