Fleshing out ssdp init

This commit is contained in:
Rob Emery 2025-01-02 10:22:06 +00:00
parent e1a4f1c062
commit 7df8dbd992

View File

@ -2,8 +2,10 @@ package dlna
import (
"context"
"crypto/md5"
"encoding/xml"
"fmt"
"io"
"log"
"net"
"net/http"
@ -53,9 +55,17 @@ type SSDPServer struct {
}
func New(ds model.DataStore, broker events.Broker) *DLNAServer {
s := &DLNAServer{ds: ds, broker: broker, ssdp: SSDPServer{}}
s.ssdp.Interfaces = listInterfaces()
s.ssdp.AnnounceInterval = time.Duration(30) * time.Second
s := &DLNAServer{
ds: ds,
broker: broker,
ssdp: SSDPServer{
AnnounceInterval: time.Duration(30) * time.Second,
Interfaces: listInterfaces(),
FriendlyName: "Navidrome",
RootDeviceUUID: makeDeviceUUID("Navidrome"),
waitChan: make(chan struct{}),
},
}
s.ssdp.services = map[string]UPnPService {
"ContentDirectory": &contentDirectoryService{
@ -260,3 +270,12 @@ func marshalSOAPResponse(sa upnp.SoapAction, args map[string]string) []byte {
return []byte(fmt.Sprintf(`<u:%[1]sResponse xmlns:u="%[2]s">%[3]s</u:%[1]sResponse>`,
sa.Action, sa.ServiceURN.String(), mustMarshalXML(soapArgs)))
}
func makeDeviceUUID(unique string) string {
h := md5.New()
if _, err := io.WriteString(h, unique); err != nil {
log.Panicf("makeDeviceUUID write failed: %s", err)
}
buf := h.Sum(nil)
return upnp.FormatUUID(buf)
}