blob: 814355c20d4424444a0e0224cf534ed6df8007f6 [file] [log] [blame]
genia.likes.science@gmail.comc5f82a22013-05-08 02:44:35 -07001<!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 var serializer = {
9 /**
10 * Serializes a hashtable and returns it as a string
11 * @param {Object} data The data to serialize
12 * @returns The serialized string
13 * @type {String}
14 */
15 stringify: function(data){
16 var message = "";
17 for (var key in data) {
18 if (data.hasOwnProperty(key)) {
19 message += key + "=" + escape(data[key]) + "&";
20 }
21 }
22 return message.substring(0, message.length - 1);
23 },
24 /**
25 * Deserializes a string and returns a hashtable
26 * @param {String} message The string to deserialize
27 * @returns An hashtable populated with key-value pairs
28 * @type {Object}
29 */
30 parse: function(message){
31 var data = {};
32 var d = message.split("&");
33 var pair, key, value;
34 for (var i = 0, len = d.length; i < len; i++) {
35 pair = d[i];
36 key = pair.substring(0, pair.indexOf("="));
37 value = pair.substring(key.length + 1);
38 data[key] = unescape(value);
39 }
40 return data;
41 }
42 };
43
44 var socket = new easyXDM.Socket(/** The configuration */{
45 local: "../name.html",
46 swf: "../easyxdm.swf",
47 /**
48 * Register the method that should handle incoming data
49 * @param {Object} data
50 * @param {String} origin
51 */
52 onMessage: function(data, origin){
53 data = serializer.parse(data);
54 alert("Received data from '" + origin + "':");
55 for (var key in data) {
56 alert("Property '" + key + "'=" + data[key]);
57 }
58 }
59 });
60 </script>
61 </head>
62 <body>
63 </body>
64</html>