Search code examples
javascriptvideoupnpdlna

Javascript: DLNA client


I am planning to write a DLNA (upnp) client in javascript. I would like to know if this is possible in the first place or not.

If yes, then where can do I start? What do I need to know to begin? Links to any documentation and tutorials will be highly appreciated. I've tried Googling, but didn't come across much helpful content.

I just need a prod in the right direction.

Thanks! :)


Solution

  • The best place for you to start is the UPnP device architecture doc in the docs bundle from the UPnP forum. This splits the protocol into a number of areas:

    • Discovery. This requires the ability to send multicast UDP packets and receive unicast UDP. You cannot do this from JavaScript so would require a native helper app to cover this portion if you want to search a network and offer to control any devices found on it. Alternatively, you can skip this section if you somehow already know the address of your target device.
    • Description. Given an address for a device, fetch (http get) an xml overview of its capabilities. You can do this easily from JavaScript.
    • Control. Instruct a given device to carry out given actions. Implemented using http post and soap. You can do this easily from JavaScript.
    • Eventing. A mechanism to be informed of changes in device state. Requires that you run a tcp server so cannot be done from JavaScript. Fortunately, this is often optional as most device services are designed to allow clients to poll state getters as an alternative to eventing. So, you can do this from JavaScript, albeit that your app will be less efficient than a native one.
    • Presentation. Some devices provide a web app allowing their control. This is hosted in a browser so will use JavaScript and is a good example that the sort of control app you want to write is possible.

    In summary then, a JavaScript UPnP client is possible only if you can use native code to handle device discovery. If you decide to try this, open source UPnP stacks exist to handle most of the work of discovery for you.