Changes to be committed:
modified: cmd/pmomusic/main.go new file: internal/netutils/ip_detect.go new file: internal/netutils/list_all_ip.go modified: internal/soap/soap.go modified: internal/ssdp/responder.go modified: internal/ssdp/ssdp.go modified: internal/upnp/http.go new file: internal/upnp/server.go new file: internal/upnp/xml/AVTransport.xml new file: internal/upnp/xml/ConnectionManager.xml new file: internal/upnp/xml/RenderingControl.xml
This commit is contained in:
45
internal/upnp/server.go
Normal file
45
internal/upnp/server.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package upnp
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"gargoton.petite-maison-orange.fr/eric/pmomusic/internal/soap"
|
||||
)
|
||||
|
||||
//go:embed xml/*.xml
|
||||
var embeddedXML embed.FS
|
||||
|
||||
// ServeStaticXML mounts handlers for SCPD XML files.
|
||||
func ServeStaticXML(mux *http.ServeMux) {
|
||||
subFS, err := fs.Sub(embeddedXML, "xml")
|
||||
if err != nil {
|
||||
panic("failed to create sub FS: " + err.Error())
|
||||
}
|
||||
mux.Handle("/scpd/", http.StripPrefix("/scpd/", http.FileServer(http.FS(subFS))))
|
||||
}
|
||||
|
||||
func StartHTTPServer(usn, ip string, port uint) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// Device description
|
||||
mux.HandleFunc("/description.xml", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/xml")
|
||||
w.Write([]byte(generateDeviceDescription(usn, ip, port)))
|
||||
})
|
||||
|
||||
// SOAP control endpoints
|
||||
mux.HandleFunc("/upnp/control/AVTransport", soap.HandleSOAP)
|
||||
mux.HandleFunc("/upnp/control/RenderingControl", soap.HandleSOAP)
|
||||
mux.HandleFunc("/upnp/control/ConnectionManager", soap.HandleSOAP)
|
||||
|
||||
// Serve static SCPD XML files
|
||||
ServeStaticXML(mux)
|
||||
|
||||
addr := fmt.Sprintf("%s:%d", ip, port)
|
||||
log.Printf("Serving UPnP fake renderer at http://%s", addr)
|
||||
log.Fatal(http.ListenAndServe(addr, mux))
|
||||
}
|
||||
Reference in New Issue
Block a user