mirror of
https://github.com/navidrome/navidrome.git
synced 2025-05-17 02:26:35 +03:00
Fleshing out ssdp init
This commit is contained in:
parent
e1a4f1c062
commit
7df8dbd992
@ -2,8 +2,10 @@ package dlna
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/md5"
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -53,9 +55,17 @@ type SSDPServer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(ds model.DataStore, broker events.Broker) *DLNAServer {
|
func New(ds model.DataStore, broker events.Broker) *DLNAServer {
|
||||||
s := &DLNAServer{ds: ds, broker: broker, ssdp: SSDPServer{}}
|
s := &DLNAServer{
|
||||||
s.ssdp.Interfaces = listInterfaces()
|
ds: ds,
|
||||||
s.ssdp.AnnounceInterval = time.Duration(30) * time.Second
|
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 {
|
s.ssdp.services = map[string]UPnPService {
|
||||||
"ContentDirectory": &contentDirectoryService{
|
"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>`,
|
return []byte(fmt.Sprintf(`<u:%[1]sResponse xmlns:u="%[2]s">%[3]s</u:%[1]sResponse>`,
|
||||||
sa.Action, sa.ServiceURN.String(), mustMarshalXML(soapArgs)))
|
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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user