0

I am following this tutorial: https://sdkdocs.roku.com/display/sdkdoc/External+Control+API ...trying to grab a list of devices via ssdp / http get.

        let query: string = "M-SEARCH * HTTP/1.1\r\n" +
            "HOST: 239.255.255.250:1900\r\n" +
            "MAN: \"ssdp:discover\"\r\n" +
            "ST: roku: ecp\r\n\r\n";

        this.http
            .get(query)
            .map(res => res.json())
            .subscribe(
            (data) => this.devices = data,
            (err) => this.error = err);

... but I'm getting a 404 error (also, localhost is being appended to the string):

Failed to load resource: the server responded with a status of 404 (Not Found)

http://localhost:52125/M-SEARCH%20*%20HTTP/1.1HOST:%20239.255.255.250:1900MAN:%20%22ssdp:discover%22ST:%20roku:%20ecp
Jason Smith
  • 333
  • 3
  • 15

1 Answers1

1

SSDP uses HTTPU or HTTP over UDP. Node's HTTP client only sends data over TCP. You'll need to use a udp socket to send this manually and listen for data, or use a pre-existing library such as node-ssdp.

jostrander
  • 745
  • 5
  • 18
  • Thanks. Have you used node-ssdp? I am having trouble getting it up and running in my project: TS Property 'Client' does not exist on type '{}' – Jason Smith Feb 13 '18 at 13:05
  • looks like node-ssdp is a dead-end because of its dependency on dgram (which no longer exists). I will have to look into udp sockets, I guess. – Jason Smith Feb 13 '18 at 14:01
  • That looks very promising! I will check it out tonight. – Jason Smith Feb 14 '18 at 14:04
  • Thanks again for your responses and ideas. I am still learning this client-side development and what I have found is that some of the node modules will not work in the browser without additional configuration. So, for example: the node-roku package was written to only run in a node.js server (not inside chrome). This may seem obvious to others -- but it is something I did not consider. I am going to mark your answer as the solution because it is correct. – Jason Smith Feb 15 '18 at 18:55
  • Depending on the solution you're after, You may be able to build a small express server to proxy the `node.js` only modules to your browser. So you would build the roku integration in node, then present a web interface in chrome to control the roku device across the network. The other alternative would be to use `electron` as it is basically a browser with both execution environments. – jostrander Feb 15 '18 at 19:01
  • hmmm... my initial thought was a browser-based solution (I am experimenting with Progressive Web Apps)... but electron looks interesting. – Jason Smith Feb 15 '18 at 21:00