Javascript: DLNA client

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

If so, where can I start? What do I need to know to get started? Links to any documentation and tutorials will be highly appreciated. I tried Googling but did not find a lot of useful content.

I just need prod in the right direction.

Thanks!:)

+6
source share
3 answers

The best place to start is the UPnP device architecture document in the docs bundle from the UPnP forum. This divides the protocol into several areas:

  • Discovery This requires the ability to send multicast UDP packets and receive unicast UDP. You cannot do this from JavaScript, therefore, to support this part, you will need a built-in auxiliary application if you want to search the network and offer to manage any devices found on it. In addition, you can skip this section if you already know the address of your target device.
  • Description. Given the address for the device, select (http get) xml an overview of its capabilities. You can do it easily with JavaScript.
  • Control To instruct this device to perform the specified actions. Implemented using http post and soap. You can do it easily with JavaScript.
  • eventing. The mechanism that should be informed about changes in the state of the device. It requires you to run the tcp server, so this cannot be done from JavaScript. Fortunately, this is often not necessary, since most device services are designed to enable customers to poll government getters as an alternative to events. This way you can do this using JavaScript, although your application will be less efficient than your own.
  • Presentation. Some devices provide a web application to control them. This is hosted in a browser, so JavaScript will be used and is a good example of what a control application you want to write is possible.

Thus, the UPnP JavaScript client is only possible if you can use your own code to handle device discovery. If you decide to try this, there are open source UPnP stacks to handle most of the discovery work for you.

+12
source

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

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

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

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

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

+4
source

EDIT: Based on the Firefox operating system.

Looking around this topic and based on Andre Fiedler’s answer, I found that the libraries he hosted are on a UDPSocket from MDN.

On the main page you can see an example of detection:

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); }); 
0
source

Source: https://habr.com/ru/post/924953/


All Articles