Search code examples
javascriptgoogle-chrome-extensionxmlhttprequestchromecastroku

Chromecast Network Implementation Details, and kinda duplicating it with a roku


Primer: I'm trying to duplicate "similar" functionality as a chromecast in a roku, for my project I need to discover the roku (using udp), and then subsequently send a http post request controlling it.

I was recently inspired by the chromecast (from a dev fest I recently attended), and found it uses SSDP to be discovered, this got me going and wrote (modified more than anything) an extension that will find my roku, so I have that vworking.

However controlling it has proven difficult, I cannot seem to send to a different port (using the XMLHttpRequest object to typically :8060 I believe) due to a same origin policy (I think), so I'm wondering if anyone knows how the chromecast works and if that methodology might be able to be adapted to my project, or if you have a solution for how to get my extension to send a http post request to :8060 with a path of /keypress/Select (for example)

NOTE: If I send an XMLHttpRequest with just the IP address (no Port) it at least returns 200 successful, but it doesn't control the roku, my understanding is that you HAVE to have the port so it knows what to do.


Solution

  • So Long story short I was having some confusion on what to do for my inputs, I played around a little more tonight, so here is what worked for me:

    var xmlhttp = new XMLHttpRequest();
    
    xmlhttp.open("POST","http://" + <ip>:<port> + "/keypress/Select",true);
    xmlhttp.send();
    

    So yea, apparently I had been playing with a packaged app, and so once i converted over to extension, it appears that I cannot use "sockets", so I'm still in a similar boat, I am wondering how chromecast manages to work around it being an extension still.