Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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! :)

like image 820
wiseindy Avatar asked Sep 09 '12 11:09

wiseindy


3 Answers

Take a look at Plug.Play.js - A JavaScript API for communicating with Universal Plug and Play (UPnP) Services obtained via the W3C Network Service Discovery API

https://github.com/rexboy7/plug.play.js

And ssdp.js - (Simple Service Discovery Protocol) A Network Service Discovery API implementation based on the W3C Raw Socket API

https://github.com/schien/ssdp.js

And here is a sample implementation of a DLNA client using the above: https://github.com/mozilla-b2g/gaia/tree/master/tv_apps/dlna-player

like image 29
André Fiedler Avatar answered Sep 21 '22 05:09

André Fiedler


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.

like image 134
simonc Avatar answered Sep 19 '22 05:09

simonc


EDIT: Based on Firefox OS.

Looking around about this topic and based on André Fiedler answer I found that the libraries he posted about resides on UDPSocket from MDN webarchive.

In the main page you can see the discovery example:

var SSDP_PORT = 1900;
var SSDP_ADDRESS = "239.255.255.250";
var SSDP_DISCOVER_MX = 2;
var SEARCH_TARGET = "urn:schemas-upnp-org:service:ContentDirectory:1";

var SSDP_DISCOVER_PACKET =
    "M-SEARCH * HTTP/1.1\r\n" +
    "HOST: " + SSDP_ADDRESS + ":" + SSDP_PORT + "\r\n" +
    "MAN: \"ssdp:discover\"\r\n" +
    "MX: " + SSDP_DISCOVER_MX + "\r\n" +
    "ST: " + SEARCH_TARGET + "\r\n" +
    "\r\n";

var searchSocket = new UDPSocket({
    loopback: true
});

searchSocket.joinMulticastGroup(SSDP_ADDRESS);

searchSocket.onmessage = function (e) {

    var msg = String.fromCharCode.apply(null, new Uint8Array(e.data));
    
    console.log(msg);
};

searchSocket.opened.then(function() {
    
    searchSocket.send(SSDP_DISCOVER_PACKET, SSDP_ADDRESS, SSDP_PORT);
    
    setTimeout(function () { searchSocket.close(); }, SSDP_DISCOVER_MX * 1000);
});
like image 41
Sebastian Avatar answered Sep 22 '22 05:09

Sebastian