0

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.

onaclov2000
  • 5,741
  • 9
  • 40
  • 54
  • I am not familiar with the internals of roku so I don't know what APIs it provides. Regardless, I am not sure I understand the circumstances where you are running into the same origin issue. Could you please explain who is sending an XHR request to who? As a side note, you can start your chrome browser with appropriate flags to disable same origin security checks. – Ali Naddaf Nov 13 '13 at 06:54
  • So the Chrome Extension *should* send a POST message to the path /keypress/Select I have accomplished it in nodejs (function which sends the message I am trying to "duplicate" in an extension: https://github.com/onaclov2000/roku/blob/master/roku.js#L128) I am able to send a json object (here: https://github.com/onaclov2000/roku/blob/master/roku.js#L112) I am just not sure how to do a comparable operation from my extension. If I want to provide this extension to other users won't they require those same security check flags? How does the Chromecast work around it? – onaclov2000 Nov 13 '13 at 13:51
  • Why are you trying to copy the chromecast messaging between the extension and the device? Why don't you just write your own that works best for you? I would imagine that would be easier rather than trying to copy the one that chromecast does. – Ali Naddaf Nov 13 '13 at 15:54
  • I'm not literally copying what chromecast does, but I assume that when you send a command to the chomecast device from the extension it's having to "post" a request, and if that works, I want to know how, so I can do it in mine (the roku is commanded by a post request according to the SDK). They have to be working around the same origin issue in some way. – onaclov2000 Nov 13 '13 at 17:13
  • Side note, I'm not a web developer by trade, so some of the concepts of how to send a post request to another site, with a different port isn't exactly "common knowledge" to me, so I'm just trying to break the problem into the smallest set of pieces, right now I need to be able to post that way, and it *appears* that the chromecast is achieving what I'm trying to do, and I am interested in how they're doing it. – onaclov2000 Nov 13 '13 at 17:33
  • I imagine you are trying to write an "extension" for chrome or firefox. I am not familiar with how those are written but I would be very surprised if you are limited to the same same-origin policy inside the extensions since I believe they can have native code as well. But that is a question for those who write extensions. – Ali Naddaf Nov 14 '13 at 01:29

1 Answers1

0

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.

onaclov2000
  • 5,741
  • 9
  • 40
  • 54