genia.likes.science@gmail.com | c5f82a2 | 2013-05-08 02:44:35 -0700 | [diff] [blame^] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>easyXDM</title> |
| 5 | <script type="text/javascript" src="../easyXDM.debug.js"> |
| 6 | </script> |
| 7 | <script type="text/javascript"> |
| 8 | /** |
| 9 | * Request the use of the JSON object |
| 10 | */ |
| 11 | easyXDM.DomHelper.requiresJSON("../json2.js"); |
| 12 | </script> |
| 13 | <script type="text/javascript"> |
| 14 | var REMOTE = (function(){ |
| 15 | var remote = location.href; |
| 16 | switch (location.host) { |
| 17 | case "provider.easyxdm.net": |
| 18 | location.href = remote.replace("provider", "consumer"); |
| 19 | break; |
| 20 | case "easyxdm.net": |
| 21 | remote = remote.replace("easyxdm.net", "consumer.easyxdm.net"); |
| 22 | break; |
| 23 | case "consumer.easyxdm.net": |
| 24 | remote = remote.replace("consumer", "provider"); |
| 25 | break; |
| 26 | case "xdm1": |
| 27 | remote = remote.replace("xdm1", "xdm2"); |
| 28 | break; |
| 29 | } |
| 30 | return remote.substring(0, remote.lastIndexOf("/")); |
| 31 | }()); |
| 32 | var remote = new easyXDM.Rpc(/** The channel configuration */{ |
| 33 | /** |
| 34 | * Register the url to hash.html, this must be an absolute path |
| 35 | * or a path relative to the root. |
| 36 | * @field |
| 37 | */ |
| 38 | local: "../name.html", |
| 39 | swf: REMOTE + "/../easyxdm.swf", |
| 40 | /** |
| 41 | * Register the url to the remote interface |
| 42 | * @field |
| 43 | */ |
| 44 | remote: REMOTE + "/remotemethods.html", |
| 45 | remoteHelper: REMOTE + "/../name.html", |
| 46 | /** |
| 47 | * Register the DOMElement that the generated IFrame should be inserted into |
| 48 | */ |
| 49 | container: "embedded", |
| 50 | props: { |
| 51 | style: { |
| 52 | border: "2px dotted red", |
| 53 | height: "200px" |
| 54 | } |
| 55 | }, |
| 56 | onReady: function(){ |
| 57 | /** |
| 58 | * Call a method on the other side |
| 59 | */ |
| 60 | remote.noOp(); |
| 61 | } |
| 62 | }, /** The interface configuration */ { |
| 63 | remote: { |
| 64 | addNumbers: {}, |
| 65 | multiplyNumbers: {}, |
| 66 | noOp: {} |
| 67 | }, |
| 68 | local: { |
| 69 | alertMessage: function(msg){ |
| 70 | alert(msg); |
| 71 | } |
| 72 | } |
| 73 | }); |
| 74 | |
| 75 | function add(a, b){ |
| 76 | remote.addNumbers(a, b, function(result){ |
| 77 | alert(a + " + " + b + " = " + result); |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | function multiply(a, b){ |
| 82 | remote.multiplyNumbers(a, b, function(result){ |
| 83 | alert(a + " x " + b + " = " + result); |
| 84 | }); |
| 85 | } |
| 86 | </script> |
| 87 | <style type="text/css"> |
| 88 | |
| 89 | #embedded iframe { |
| 90 | width: 100%; |
| 91 | height: 100%; |
| 92 | } |
| 93 | </style> |
| 94 | </head> |
| 95 | <body> |
| 96 | <div style="border:1px solid black;padding:3px;margin:10px;"> |
| 97 | <a href="index.html">Index of examples</a> |
| 98 | | <a href="http://github.com/oyvindkinsey/easyXDM/#readme">Readme at github</a> |
| 99 | | |
| 100 | | <a href="http://easyxdm.net/">easyXDM.net</a> |
| 101 | | <a href="http://groups.google.com/group/easyxdm">easyXDM at Google Groups</a> |
| 102 | <br/> |
| 103 | The examples are executing slower than the production build due to the extensive tracing. |
| 104 | <br/> |
| 105 | If you are alerted about a popup, then this is only the trace log feature. You can ignore this. |
| 106 | </div> |
| 107 | <script type="text/javascript"> |
| 108 | document.write("Domain: " + location.host); |
| 109 | </script> |
| 110 | <!-- easyXDM.Debug.trace(msg) will output its messages to any element with the id "log" --> |
| 111 | <div id="log" style="height:100px;border:1px dotted black;overflow:auto"> |
| 112 | </div> |
| 113 | <div id="embedded"> |
| 114 | </div> |
| 115 | <div> |
| 116 | The remote implementation is synchronous and will return immediately |
| 117 | <br/> |
| 118 | <input type="button" onclick="add(3,5);" value="call addNumbers on remote domain"/> |
| 119 | <br/> |
| 120 | <br/> |
| 121 | The remote implementation of multiplyNumbers is asynchronous and will return after 5seconds |
| 122 | <br/> |
| 123 | This shows that you can use async calls in the remote method, eg. XHR calls |
| 124 | <br/> |
| 125 | <input type="button" onclick="multiply(3,5);" value="call multiplyNumbers on remote domain"/> |
| 126 | <br/> |
| 127 | <br/> |
| 128 | This calls a non-returning method on the remote side |
| 129 | <br/> |
| 130 | <input type="button" onclick="remote.noOp();" value="call noOp on the remote domain"/> |
| 131 | </div> |
| 132 | <script type="text/javascript"> |
| 133 | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 134 | document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| 135 | </script> |
| 136 | <script type="text/javascript"> |
| 137 | if (location.host.indexOf("easyxdm.net") !== -1) { |
| 138 | try { |
| 139 | var pageTracker = _gat._getTracker("UA-9535591-3"); |
| 140 | pageTracker._setDomainName(".easyxdm.net"); |
| 141 | pageTracker._trackPageview(); |
| 142 | } |
| 143 | catch (err) { |
| 144 | } |
| 145 | } |
| 146 | </script> |
| 147 | </body> |
| 148 | </html> |