What is SOAP in this context?
SOAP (Simple Object Access Protocol) is the control layer of UPnP. After a client discovers the server and fetches its device description, it issues commands by sending XML-wrapped HTTP POST requests. Each request targets a specific UPnP service action. In this server, all SOAP traffic is handled by an HTTP server running on port 8080. Incoming requests are parsed bySoapRequest.from(), which reads the raw body buffer and extracts the SOAPAction header to determine which action to invoke.
Control endpoints
The device description declares two ContentDirectory URLs:| Endpoint | Purpose |
|---|---|
POST /upnp/control/ContentDirectory | Control — clients send Browse, GetSortCapabilities, and GetSearchCapabilities actions here |
POST /upnp/event/ContentDirectory | Events — clients subscribe here to receive notifications when the content library changes |
Both endpoints use the same dispatch logic: the incoming request body is parsed via
SoapRequest.from() and the SOAPAction header is used to look up the handler in services.ts. The event endpoint does not implement a separate subscription registry in this version.ContentDirectory:1 actions
The server handles three standard ContentDirectory:1 actions, all identified by theSOAPAction header:
Browse
SOAPAction:urn:schemas-upnp-org:service:ContentDirectory:1#Browse
The primary action. The client requests a listing of media items. The server reads from gallery.json and returns a DIDL-Lite XML payload describing each video — its title, URL, MIME type, and metadata.
Example DIDL-Lite response:
GetSortCapabilities
SOAPAction:urn:schemas-upnp-org:service:ContentDirectory:1#GetSortCapabilities
The client asks which metadata properties can be used to sort results. The server returns an empty SortCapabilities element, indicating no sort constraints are imposed.
GetSearchCapabilities
SOAPAction:urn:schemas-upnp-org:service:ContentDirectory:1#GetSearchCapabilities
The client asks which metadata properties can be used in search queries. The server returns * in SearchCaps, indicating that all search properties are supported.
How SoapRequest.from() parses a request
- Reads the full HTTP request body into a buffer.
- Extracts the
SOAPActionheader — this is a quoted string like"urn:schemas-upnp-org:service:ContentDirectory:1#Browse". - Parses the XML body using Cheerio to extract action-specific parameters (for example, the
BrowseFlagandStartingIndexfields in a Browse request). - Returns a structured object the router uses to dispatch to the correct service handler.
A full SOAP Browse request
Here is what a client sends to/upnp/control/ContentDirectory:
NumberReturned, TotalMatches, and UpdateID fields.
Further reading
- DLNA and UPnP overview — the full protocol stack
- SSDP device discovery — how clients find the server before issuing SOAP requests
- Configure your gallery — how to add videos that appear in Browse responses