ID:1755334
 
(See the best response by Lummox JR.)
Code:
if (button == OuyaController.BUTTON_MENU) {
updateController(controller, button, true);
var e = $.Event("keydown", { keyCode: 32});
$("#IFRAMEid").trigger(e);

setTimeout(function(){ updateController(controller, button, false)}, 1000);
}


Problem description:
The web client iframe expects the spacebar key as input. I push menu button it shows the menu png for a moment then nothing- no input registered to the iframe.


I got a BYOND game to work on OUYA, I'm stuck, what do I need to route keyboard presses to simulate keyboard input? Shouldn't this work? I'm using the virtual controller example.


full link
Rather than try to force an event--to be honest, I never found a good multi-platform way to generate a key event--why not call byond.fn.fireMacro()? (Or if this is for a control, call its fireMacro() member directly.) Calling fireMacro('Space') ought to do the trick.

[edit]
Or maybe not. If this is being done outside of the iframe, that's gonna be tougher to handle. I don't know if you can generate events and have them trigger inside an iframe, at least not one with a different domain.
Best response
If this is in fact being done on another site, and you can control JS code on their site that can send events, then I think what I'm going to have to do is improve connectivity between the webclient and the outer-outer frame. I've had some ideas for that and can think of a number of other reasons that'd be desirable anyway.
I haven't compared and contrast how different it is from regular web browsers, but it's a chromium build and can stream web content like normal, hence why the web client does run.

Besides that block of code all I have done is include the web client iframe in the body tag and gave it an id of "IFRAMEid"
<script src="http://code.jquery.com/jquery-latest.js"></script>

<iframe src="http://www.byond.com/play/embed/(address)" width="640" height="480" id="IFRAMEid"></iframe></>


I changed the code around a bit to see if I could get it to work.

Here is the whole function for clarity
      function onKeyDown(playerNum, button) {
var controller = getController(playerNum);
if (controller == undefined) {
return;
}
if (button == OuyaController.BUTTON_MENU) {
updateController(controller, button, true);
var e = jQuery.Event("keydown");
e.which = 32;
e.keyCode = 32;
$("#IFRAMEid").trigger(e);

setTimeout(function(){ updateController(controller, button, false)}, 1000);
} else {
updateController(controller, button, true);
}
}
Ah, interesting. I hadn't heard of Ouya before this. I wonder if the device's memory is really adequate for this sort of thing.

At any rate the central limiting factor here, I think, is trying to send an event to an iframe. JavaScript really doesn't support rerouting events to other elements, so all this would do would be to trigger any event handlers registered in jQuery. But even if you fired a keyboard event manually--which is far easier said than done because every browser in the world is different when it comes to initializing keyboard events--I don't think it could be sent to a cross-domain iframe, let alone the iframe within the iframe.

This is definitely going to require some sort of bridge between the frames. I'll have to figure out what to do there.
So you're saying BYOND's web client is an iframe within an iframe? Guess I have to research sending key simulations between iframes.

I don't think you can send key events through iframes, leastwise not with different domains. The only thing you have real access to is postMessage().
Is changing the domain of the iframe possible? https://developer.mozilla.org/en-US/docs/Web/Security/ Same-origin_policy

So key events work the app as an html page one in the same?
A domain can only be made more or less specific (it's one or the other, but I forget which). It can't be changed outright; that would be a security flaw.

The only way you can communicate is with postMessage().
Trying to find what I need to do. I will post a response I got from OUYA staff. Hope this will be helpful. Either this is something that I need to configure or something that needs to be done with the web client.

Question: Is it possible can you make everything run as if the same domain via some packaging magic?


tgraupmanntgraupmann January 8
If you have to interact with the web, you would just use streaming and point the url to some http place. The domain would have a crossdomain.xml in the root which controls the allowed domains. And security would be turned on.


tgraupmanntgraupmann 11:34AM
When you hit a URL on the server normally there's a crossdomain.xml policy setup.

http://google.com/crossdomain.xml

It allows you to do cross-site scripting when security is on.

<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*.domain.com"/>
<allow-access-from domain="*.cloudfront.net"/>
<allow-access-from domain="*.amazonaws.com"/>
</cross-domain-policy>


Edit: I guess from this is something that I need to define in my html for my website/app.
Is there any reason to believe that if I define a "http://www.byond.com/play/embed/(address)" it won't allow the app to access it?

Starting to think the web client and both my html app/website needs to both have some form/interpretation of this cross domain policy.

Unity has something like this. All apart of the research.
Generally, the side that is asked for information is the side that requires CORS to be active. In this case, it would be byond.com, since that is where the iframe is located. Your site would not need CORS active since it is not serving information. This could vary based on the method of communication, but I cannot think of such an example at this time.
You are almost right.


tgraupmann 12:28PM
Looks like no cross domains were specified in the root.

http://www.byond.com/crossdomain.xml

Web client needs update.

That is what is stated above. However, CORS is not necessarily defined in a crossdomain.xml file, it can be declared in a .htaccess file as well, so checking the xml file will not necessarily tell you anything. I believe it was Flash that originally used the crossdomain.xml. It could reduce security to enable CORS, so it must be done with caution. I would not expect BYOND to just enable it on a whim; they would think it through first, if they do it at all.
Either way I want this to work.
This is never going to work with a keyboard event. I'm not even sure you can transfer a keyboard event between iframes when the domain is a match, but generated keyboard events are kind of iffy to begin with. You're trying to fit a square peg into a round hole.

As I said, postMessage() is what you want. In the middle of a coughing fit last night I had a thought: If you define a control, I believe it can call window.parent.parent.postMessage() in the control's create() member, to try to make contact with the outer frame. If you have a message handler on your page, you can send a reply to event.source. I need to make this kind of thing easier to access, though, since this is something the hotbar is mostly doing already (except it only talks to byond.com, not the outer frame).
Simple example code for the html page and for the DMS would be appreciated. Best wishes for that cold.
Question: What do you mean between iframes? Input is essentially going from a html webpage to the iframe. In the meantime I will confirm whether it is actually possible to transfer a keyboard event between a webpage and a iframe and also between iframes. Since, for some reason you keep saying between iframes.

I thought I was trying to run Javascript from the main page(index.html) to the iframe.
In response to Sir Quizalot
It's kind of hard for me to provide a simple example offhand, but I plan to improve the communication with the outer frame when I can.

Sir Quizalot wrote:
Question: What do you mean between iframes? Input is essentially going from a html webpage to the iframe. In the meantime I will confirm whether it is actually possible to transfer a keyboard event between a webpage and a iframe and also between iframes. Since, for some reason you keep saying between iframes.

I thought I was trying to run Javascript from the main page(index.html) to the iframe.

I'm using "between iframes" interchangeably with "between the main page and an iframe". Fundamentally there's not any real difference. The main issue in play is cross-domain security.

You can't actually run JS directly in an iframe from another frame unless the security issues such as same-domain policy are accounted for. Dispatching events is going to be a similar problem.
I took a look for some hacks to get this working, as I don't think dispatching events should be an issue. I've seen multiple examples of dispatching events with buttons that's why I think if they can dispatch events with buttons how hard should directly dispatching it in a function be.

Anyone who finds topics like this that covers different tactics let me know. Something so simple as a domain name should be easily emulated.

Anyone who can supply an example based on what Lummox Jr. suggested would be greatly appreciated.
Page: 1 2