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! :)
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
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:
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.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With