Advertisement
Guest User

Untitled

a guest
Nov 24th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*! Socket.IO.js build:0.9.11, development. Copyright(c) 2011 LearnBoost <dev@learnboost.com> MIT Licensed */
  2.  
  3. var io = ('undefined' === typeof module ?
  4. {
  5. } : module.exports);
  6. (function()
  7. {
  8.  
  9.     /**
  10.      * socket.io
  11.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  12.      * MIT Licensed
  13.      */
  14.  
  15.     (function(exports, global)
  16.     {
  17.  
  18.         /**
  19.          * IO namespace.
  20.          *
  21.          * @namespace
  22.          */
  23.  
  24.         var io = exports;
  25.  
  26.         /**
  27.          * Socket.IO version
  28.          *
  29.          * @api public
  30.          */
  31.  
  32.         io.version = '0.9.11';
  33.  
  34.         /**
  35.          * Protocol implemented.
  36.          *
  37.          * @api public
  38.          */
  39.  
  40.         io.protocol = 1;
  41.  
  42.         /**
  43.          * Available transports, these will be populated with the available transports
  44.          *
  45.          * @api public
  46.          */
  47.  
  48.         io.transports = [];
  49.  
  50.         /**
  51.          * Keep track of jsonp callbacks.
  52.          *
  53.          * @api private
  54.          */
  55.  
  56.         io.j = [];
  57.  
  58.         /**
  59.          * Keep track of our io.Sockets
  60.          *
  61.          * @api private
  62.          */
  63.         io.sockets =
  64.         {
  65.         };
  66.  
  67.         /**
  68.          * Manages connections to hosts.
  69.          *
  70.          * @param {String} uri
  71.          * @Param {Boolean} force creation of new socket (defaults to false)
  72.          * @api public
  73.          */
  74.  
  75.         io.connect = function(host, details)
  76.         {
  77.             var uri = io.util.parseUri(host), uuri, socket;
  78.  
  79.             if (global && global.location)
  80.             {
  81.                 uri.protocol = uri.protocol || global.location.protocol.slice(0, -1);
  82.                 uri.host = uri.host || (global.document ? global.document.domain : global.location.hostname);
  83.                 uri.port = uri.port || global.location.port;
  84.             }
  85.  
  86.             uuri = io.util.uniqueUri(uri);
  87.  
  88.             var options =
  89.             {
  90.                 host : uri.host,
  91.                 secure : 'https' == uri.protocol,
  92.                 port : uri.port || ('https' == uri.protocol ? 443 : 80),
  93.                 query : uri.query || ''
  94.             };
  95.  
  96.             io.util.merge(options, details);
  97.  
  98.             if (options['force new connection'] || !io.sockets[uuri])
  99.             {
  100.                 socket = new io.Socket(options);
  101.             }
  102.  
  103.             if (!options['force new connection'] && socket)
  104.             {
  105.                 io.sockets[uuri] = socket;
  106.             }
  107.  
  108.             socket = socket || io.sockets[uuri];
  109.  
  110.             // if path is different from '' or /
  111.             return socket.of(uri.path.length > 1 ? uri.path : '');
  112.         };
  113.  
  114.     })('object' === typeof module ? module.exports : (this.io =
  115.     {
  116.     }), this);
  117.     /**
  118.      * socket.io
  119.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  120.      * MIT Licensed
  121.      */
  122.  
  123.     (function(exports, global)
  124.     {
  125.  
  126.         /**
  127.          * Utilities namespace.
  128.          *
  129.          * @namespace
  130.          */
  131.  
  132.         var util = exports.util =
  133.         {
  134.         };
  135.  
  136.         /**
  137.          * Parses an URI
  138.          *
  139.          * @author Steven Levithan <stevenlevithan.com> (MIT license)
  140.          * @api public
  141.          */
  142.  
  143.         var re = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  144.  
  145.         var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
  146.  
  147.         util.parseUri = function(str)
  148.         {
  149.             var m = re.exec(str || ''), uri =
  150.             {
  151.             }, i = 14;
  152.  
  153.             while (i--)
  154.             {
  155.                 uri[parts[i]] = m[i] || '';
  156.             }
  157.  
  158.             return uri;
  159.         };
  160.  
  161.         /**
  162.          * Produces a unique url that identifies a Socket.IO connection.
  163.          *
  164.          * @param {Object} uri
  165.          * @api public
  166.          */
  167.  
  168.         util.uniqueUri = function(uri)
  169.         {
  170.             var protocol = uri.protocol, host = uri.host, port = uri.port;
  171.  
  172.             if ('document' in global)
  173.             {
  174.                 host = host || document.domain;
  175.                 port = port || (protocol == 'https' && document.location.protocol !== 'https:' ? 443 : document.location.port);
  176.             }
  177.             else
  178.             {
  179.                 host = host || 'localhost';
  180.  
  181.                 if (!port && protocol == 'https')
  182.                 {
  183.                     port = 443;
  184.                 }
  185.             }
  186.  
  187.             return (protocol || 'http') + '://' + host + ':' + (port || 80);
  188.         };
  189.  
  190.         /**
  191.          * Mergest 2 query strings in to once unique query string
  192.          *
  193.          * @param {String} base
  194.          * @param {String} addition
  195.          * @api public
  196.          */
  197.  
  198.         util.query = function(base, addition)
  199.         {
  200.             var query = util.chunkQuery(base || ''), components = [];
  201.  
  202.             util.merge(query, util.chunkQuery(addition || ''));
  203.             for (var part in query)
  204.             {
  205.                 if (query.hasOwnProperty(part))
  206.                 {
  207.                     components.push(part + '=' + query[part]);
  208.                 }
  209.             }
  210.  
  211.             return components.length ? '?' + components.join('&') : '';
  212.         };
  213.  
  214.         /**
  215.          * Transforms a querystring in to an object
  216.          *
  217.          * @param {String} qs
  218.          * @api public
  219.          */
  220.  
  221.         util.chunkQuery = function(qs)
  222.         {
  223.             var query =
  224.             {
  225.             }, params = qs.split('&'), i = 0, l = params.length, kv;
  226.  
  227.             for (; i < l; ++i)
  228.             {
  229.                 kv = params[i].split('=');
  230.                 if (kv[0])
  231.                 {
  232.                     query[kv[0]] = kv[1];
  233.                 }
  234.             }
  235.  
  236.             return query;
  237.         };
  238.  
  239.         /**
  240.          * Executes the given function when the page is loaded.
  241.          *
  242.          *     io.util.load(function () { console.log('page loaded'); });
  243.          *
  244.          * @param {Function} fn
  245.          * @api public
  246.          */
  247.  
  248.         var pageLoaded = false;
  249.  
  250.         util.load = function(fn)
  251.         {
  252.             if ('document' in global && document.readyState === 'complete' || pageLoaded)
  253.             {
  254.                 return fn();
  255.             }
  256.  
  257.             util.on(global, 'load', fn, false);
  258.         };
  259.  
  260.         /**
  261.          * Adds an event.
  262.          *
  263.          * @api private
  264.          */
  265.  
  266.         util.on = function(element, event, fn, capture)
  267.         {
  268.             if (element.attachEvent)
  269.             {
  270.                 element.attachEvent('on' + event, fn);
  271.             }
  272.             else if (element.addEventListener)
  273.             {
  274.                 element.addEventListener(event, fn, capture);
  275.             }
  276.         };
  277.  
  278.         /**
  279.          * Generates the correct `XMLHttpRequest` for regular and cross domain requests.
  280.          *
  281.          * @param {Boolean} [xdomain] Create a request that can be used cross domain.
  282.          * @returns {XMLHttpRequest|false} If we can create a XMLHttpRequest.
  283.          * @api private
  284.          */
  285.  
  286.         util.request = function(xdomain)
  287.         {
  288.  
  289.             if (xdomain && 'undefined' != typeof XDomainRequest && !util.ua.hasCORS)
  290.             {
  291.                 return new XDomainRequest();
  292.             }
  293.  
  294.             if ('undefined' != typeof XMLHttpRequest && (!xdomain || util.ua.hasCORS))
  295.             {
  296.                 return new XMLHttpRequest();
  297.             }
  298.  
  299.             if (!xdomain)
  300.             {
  301.                 try
  302.                 {
  303.                     return new window[(['Active'].concat('Object').join('X'))]('Microsoft.XMLHTTP');
  304.                 }
  305.                 catch(e)
  306.                 {
  307.                 }
  308.             }
  309.  
  310.             return null;
  311.         };
  312.  
  313.         /**
  314.          * XHR based transport constructor.
  315.          *
  316.          * @constructor
  317.          * @api public
  318.          */
  319.  
  320.         /**
  321.          * Change the internal pageLoaded value.
  322.          */
  323.  
  324.         if ('undefined' != typeof window)
  325.         {
  326.             util.load(function()
  327.             {
  328.                 pageLoaded = true;
  329.             });
  330.         }
  331.  
  332.         /**
  333.          * Defers a function to ensure a spinner is not displayed by the browser
  334.          *
  335.          * @param {Function} fn
  336.          * @api public
  337.          */
  338.  
  339.         util.defer = function(fn)
  340.         {
  341.             if (!util.ua.webkit || 'undefined' != typeof importScripts)
  342.             {
  343.                 return fn();
  344.             }
  345.  
  346.             util.load(function()
  347.             {
  348.                 setTimeout(fn, 100);
  349.             });
  350.         };
  351.  
  352.         /**
  353.          * Merges two objects.
  354.          *
  355.          * @api public
  356.          */
  357.  
  358.         util.merge = function merge(target, additional, deep, lastseen)
  359.         {
  360.             var seen = lastseen || [], depth = typeof deep == 'undefined' ? 2 : deep, prop;
  361.  
  362.             for (prop in additional)
  363.             {
  364.                 if (additional.hasOwnProperty(prop) && util.indexOf(seen, prop) < 0)
  365.                 {
  366.                     if ( typeof target[prop] !== 'object' || !depth)
  367.                     {
  368.                         target[prop] = additional[prop];
  369.                         seen.push(additional[prop]);
  370.                     }
  371.                     else
  372.                     {
  373.                         util.merge(target[prop], additional[prop], depth - 1, seen);
  374.                     }
  375.                 }
  376.             }
  377.  
  378.             return target;
  379.         };
  380.  
  381.         /**
  382.          * Merges prototypes from objects
  383.          *
  384.          * @api public
  385.          */
  386.  
  387.         util.mixin = function(ctor, ctor2)
  388.         {
  389.             util.merge(ctor.prototype, ctor2.prototype);
  390.         };
  391.  
  392.         /**
  393.          * Shortcut for prototypical and static inheritance.
  394.          *
  395.          * @api private
  396.          */
  397.  
  398.         util.inherit = function(ctor, ctor2)
  399.         {
  400.             function f()
  401.             {
  402.             };
  403.             f.prototype = ctor2.prototype;
  404.             ctor.prototype = new f;
  405.         };
  406.  
  407.         /**
  408.          * Checks if the given object is an Array.
  409.          *
  410.          *     io.util.isArray([]); // true
  411.          *     io.util.isArray({}); // false
  412.          *
  413.          * @param Object obj
  414.          * @api public
  415.          */
  416.  
  417.         util.isArray = Array.isArray ||
  418.         function(obj)
  419.         {
  420.             return Object.prototype.toString.call(obj) === '[object Array]';
  421.         };
  422.  
  423.         /**
  424.          * Intersects values of two arrays into a third
  425.          *
  426.          * @api public
  427.          */
  428.  
  429.         util.intersect = function(arr, arr2)
  430.         {
  431.             var ret = [], longest = arr.length > arr2.length ? arr : arr2, shortest = arr.length > arr2.length ? arr2 : arr;
  432.  
  433.             for (var i = 0, l = shortest.length; i < l; i++)
  434.             {
  435.                 if (~util.indexOf(longest, shortest[i]))
  436.                     ret.push(shortest[i]);
  437.             }
  438.  
  439.             return ret;
  440.         };
  441.  
  442.         /**
  443.          * Array indexOf compatibility.
  444.          *
  445.          * @see bit.ly/a5Dxa2
  446.          * @api public
  447.          */
  448.  
  449.         util.indexOf = function(arr, o, i)
  450.         {
  451.  
  452.             for (var j = arr.length, i = i < 0 ? i + j < 0 ? 0 : i + j : i || 0; i < j && arr[i] !== o; i++)
  453.             {
  454.             }
  455.  
  456.             return j <= i ? -1 : i;
  457.         };
  458.  
  459.         /**
  460.          * Converts enumerables to array.
  461.          *
  462.          * @api public
  463.          */
  464.  
  465.         util.toArray = function(enu)
  466.         {
  467.             var arr = [];
  468.  
  469.             for (var i = 0, l = enu.length; i < l; i++)
  470.                 arr.push(enu[i]);
  471.  
  472.             return arr;
  473.         };
  474.  
  475.         /**
  476.          * UA / engines detection namespace.
  477.          *
  478.          * @namespace
  479.          */
  480.  
  481.         util.ua =
  482.         {
  483.         };
  484.  
  485.         /**
  486.          * Whether the UA supports CORS for XHR.
  487.          *
  488.          * @api public
  489.          */
  490.  
  491.         util.ua.hasCORS = 'undefined' != typeof XMLHttpRequest && (function()
  492.         {
  493.             try
  494.             {
  495.                 var a = new XMLHttpRequest();
  496.             }
  497.             catch (e)
  498.             {
  499.                 return false;
  500.             }
  501.  
  502.             return a.withCredentials != undefined;
  503.         })();
  504.  
  505.         /**
  506.          * Detect webkit.
  507.          *
  508.          * @api public
  509.          */
  510.  
  511.         util.ua.webkit = 'undefined' != typeof navigator && /webkit/i.test(navigator.userAgent);
  512.  
  513.         /**
  514.          * Detect iPad/iPhone/iPod.
  515.          *
  516.          * @api public
  517.          */
  518.  
  519.         util.ua.iDevice = 'undefined' != typeof navigator && /iPad|iPhone|iPod/i.test(navigator.userAgent);
  520.  
  521.     })('undefined' != typeof io ? io : module.exports, this);
  522.     /**
  523.      * socket.io
  524.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  525.      * MIT Licensed
  526.      */
  527.  
  528.     (function(exports, io)
  529.     {
  530.  
  531.         /**
  532.          * Expose constructor.
  533.          */
  534.  
  535.         exports.EventEmitter = EventEmitter;
  536.  
  537.         /**
  538.          * Event emitter constructor.
  539.          *
  540.          * @api public.
  541.          */
  542.  
  543.         function EventEmitter()
  544.         {
  545.         };
  546.  
  547.         /**
  548.          * Adds a listener
  549.          *
  550.          * @api public
  551.          */
  552.  
  553.         EventEmitter.prototype.on = function(name, fn)
  554.         {
  555.             if (!this.$events)
  556.             {
  557.                 this.$events =
  558.                 {
  559.                 };
  560.             }
  561.  
  562.             if (!this.$events[name])
  563.             {
  564.                 this.$events[name] = fn;
  565.             }
  566.             else if (io.util.isArray(this.$events[name]))
  567.             {
  568.                 this.$events[name].push(fn);
  569.             }
  570.             else
  571.             {
  572.                 this.$events[name] = [this.$events[name], fn];
  573.             }
  574.  
  575.             return this;
  576.         };
  577.  
  578.         EventEmitter.prototype.addListener = EventEmitter.prototype.on;
  579.  
  580.         /**
  581.          * Adds a volatile listener.
  582.          *
  583.          * @api public
  584.          */
  585.  
  586.         EventEmitter.prototype.once = function(name, fn)
  587.         {
  588.             var self = this;
  589.  
  590.             function on()
  591.             {
  592.                 self.removeListener(name, on);
  593.                 fn.apply(this, arguments);
  594.             };
  595.  
  596.             on.listener = fn;
  597.             this.on(name, on);
  598.  
  599.             return this;
  600.         };
  601.  
  602.         /**
  603.          * Removes a listener.
  604.          *
  605.          * @api public
  606.          */
  607.  
  608.         EventEmitter.prototype.removeListener = function(name, fn)
  609.         {
  610.             if (this.$events && this.$events[name])
  611.             {
  612.                 var list = this.$events[name];
  613.  
  614.                 if (io.util.isArray(list))
  615.                 {
  616.                     var pos = -1;
  617.  
  618.                     for (var i = 0, l = list.length; i < l; i++)
  619.                     {
  620.                         if (list[i] === fn || (list[i].listener && list[i].listener === fn))
  621.                         {
  622.                             pos = i;
  623.                             break;
  624.                         }
  625.                     }
  626.  
  627.                     if (pos < 0)
  628.                     {
  629.                         return this;
  630.                     }
  631.  
  632.                     list.splice(pos, 1);
  633.  
  634.                     if (!list.length)
  635.                     {
  636.                         delete this.$events[name];
  637.                     }
  638.                 }
  639.                 else if (list === fn || (list.listener && list.listener === fn))
  640.                 {
  641.                     delete this.$events[name];
  642.                 }
  643.             }
  644.  
  645.             return this;
  646.         };
  647.  
  648.         /**
  649.          * Removes all listeners for an event.
  650.          *
  651.          * @api public
  652.          */
  653.  
  654.         EventEmitter.prototype.removeAllListeners = function(name)
  655.         {
  656.             if (name === undefined)
  657.             {
  658.                 this.$events =
  659.                 {
  660.                 };
  661.                 return this;
  662.             }
  663.  
  664.             if (this.$events && this.$events[name])
  665.             {
  666.                 this.$events[name] = null;
  667.             }
  668.  
  669.             return this;
  670.         };
  671.  
  672.         /**
  673.          * Gets all listeners for a certain event.
  674.          *
  675.          * @api publci
  676.          */
  677.  
  678.         EventEmitter.prototype.listeners = function(name)
  679.         {
  680.             if (!this.$events)
  681.             {
  682.                 this.$events =
  683.                 {
  684.                 };
  685.             }
  686.  
  687.             if (!this.$events[name])
  688.             {
  689.                 this.$events[name] = [];
  690.             }
  691.  
  692.             if (!io.util.isArray(this.$events[name]))
  693.             {
  694.                 this.$events[name] = [this.$events[name]];
  695.             }
  696.  
  697.             return this.$events[name];
  698.         };
  699.  
  700.         /**
  701.          * Emits an event.
  702.          *
  703.          * @api public
  704.          */
  705.  
  706.         EventEmitter.prototype.emit = function(name)
  707.         {
  708.             if (!this.$events)
  709.             {
  710.                 return false;
  711.             }
  712.  
  713.             var handler = this.$events[name];
  714.  
  715.             if (!handler)
  716.             {
  717.                 return false;
  718.             }
  719.  
  720.             var args = Array.prototype.slice.call(arguments, 1);
  721.  
  722.             if ('function' == typeof handler)
  723.             {
  724.                 handler.apply(this, args);
  725.             }
  726.             else if (io.util.isArray(handler))
  727.             {
  728.                 var listeners = handler.slice();
  729.  
  730.                 for (var i = 0, l = listeners.length; i < l; i++)
  731.                 {
  732.                     listeners[i].apply(this, args);
  733.                 }
  734.             }
  735.             else
  736.             {
  737.                 return false;
  738.             }
  739.  
  740.             return true;
  741.         };
  742.  
  743.     })('undefined' != typeof io ? io : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  744.  
  745.     /**
  746.      * socket.io
  747.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  748.      * MIT Licensed
  749.      */
  750.  
  751.     /**
  752.      * Based on JSON2 (http://www.JSON.org/js.html).
  753.      */
  754.  
  755.     (function(exports, nativeJSON)
  756.     {
  757.         "use strict";
  758.  
  759.         // use native JSON if it's available
  760.         if (nativeJSON && nativeJSON.parse)
  761.         {
  762.             return exports.JSON =
  763.             {
  764.                 parse : nativeJSON.parse,
  765.                 stringify : nativeJSON.stringify
  766.             };
  767.         }
  768.  
  769.         var JSON = exports.JSON =
  770.         {
  771.         };
  772.  
  773.         function f(n)
  774.         {
  775.             // Format integers to have at least two digits.
  776.             return n < 10 ? '0' + n : n;
  777.         }
  778.  
  779.         function date(d, key)
  780.         {
  781.             return isFinite(d.valueOf()) ? d.getUTCFullYear() + '-' + f(d.getUTCMonth() + 1) + '-' + f(d.getUTCDate()) + 'T' + f(d.getUTCHours()) + ':' + f(d.getUTCMinutes()) + ':' + f(d.getUTCSeconds()) + 'Z' : null;
  782.         };
  783.  
  784.         var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta =
  785.         {
  786.             // table of character substitutions
  787.             '\b' : '\\b',
  788.             '\t' : '\\t',
  789.             '\n' : '\\n',
  790.             '\f' : '\\f',
  791.             '\r' : '\\r',
  792.             '"' : '\\"',
  793.             '\\' : '\\\\'
  794.         }, rep;
  795.  
  796.         function quote(string)
  797.         {
  798.  
  799.             // If the string contains no control characters, no quote characters, and no
  800.             // backslash characters, then we can safely slap some quotes around it.
  801.             // Otherwise we must also replace the offending characters with safe escape
  802.             // sequences.
  803.  
  804.             escapable.lastIndex = 0;
  805.             return escapable.test(string) ? '"' + string.replace(escapable, function(a)
  806.             {
  807.                 var c = meta[a];
  808.                 return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  809.             }) + '"' : '"' + string + '"';
  810.         }
  811.  
  812.         function str(key, holder)
  813.         {
  814.  
  815.             // Produce a string from holder[key].
  816.  
  817.             var i, // The loop counter.
  818.             k, // The member key.
  819.             v, // The member value.
  820.             length, mind = gap, partial, value = holder[key];
  821.  
  822.             // If the value has a toJSON method, call it to obtain a replacement value.
  823.  
  824.             if ( value instanceof Date)
  825.             {
  826.                 value = date(key);
  827.             }
  828.  
  829.             // If we were called with a replacer function, then call the replacer to
  830.             // obtain a replacement value.
  831.  
  832.             if ( typeof rep === 'function')
  833.             {
  834.                 value = rep.call(holder, key, value);
  835.             }
  836.  
  837.             // What happens next depends on the value's type.
  838.  
  839.             switch (typeof value)
  840.             {
  841.                 case 'string':
  842.                     return quote(value);
  843.  
  844.                 case 'number':
  845.  
  846.                     // JSON numbers must be finite. Encode non-finite numbers as null.
  847.  
  848.                     return isFinite(value) ? String(value) : 'null';
  849.  
  850.                 case 'boolean':
  851.                 case 'null':
  852.  
  853.                     // If the value is a boolean or null, convert it to a string. Note:
  854.                     // typeof null does not produce 'null'. The case is included here in
  855.                     // the remote chance that this gets fixed someday.
  856.  
  857.                     return String(value);
  858.  
  859.                 // If the type is 'object', we might be dealing with an object or an array or
  860.                 // null.
  861.  
  862.                 case 'object':
  863.  
  864.                     // Due to a specification blunder in ECMAScript, typeof null is 'object',
  865.                     // so watch out for that case.
  866.  
  867.                     if (!value)
  868.                     {
  869.                         return 'null';
  870.                     }
  871.  
  872.                     // Make an array to hold the partial results of stringifying this object value.
  873.  
  874.                     gap += indent;
  875.                     partial = [];
  876.  
  877.                     // Is the value an array?
  878.  
  879.                     if (Object.prototype.toString.apply(value) === '[object Array]')
  880.                     {
  881.  
  882.                         // The value is an array. Stringify every element. Use null as a placeholder
  883.                         // for non-JSON values.
  884.  
  885.                         length = value.length;
  886.                         for ( i = 0; i < length; i += 1)
  887.                         {
  888.                             partial[i] = str(i, value) || 'null';
  889.                         }
  890.  
  891.                         // Join all of the elements together, separated with commas, and wrap them in
  892.                         // brackets.
  893.  
  894.                         v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
  895.                         gap = mind;
  896.                         return v;
  897.                     }
  898.  
  899.                     // If the replacer is an array, use it to select the members to be stringified.
  900.  
  901.                     if (rep && typeof rep === 'object')
  902.                     {
  903.                         length = rep.length;
  904.                         for ( i = 0; i < length; i += 1)
  905.                         {
  906.                             if ( typeof rep[i] === 'string')
  907.                             {
  908.                                 k = rep[i];
  909.                                 v = str(k, value);
  910.                                 if (v)
  911.                                 {
  912.                                     partial.push(quote(k) + ( gap ? ': ' : ':') + v);
  913.                                 }
  914.                             }
  915.                         }
  916.                     }
  917.                     else
  918.                     {
  919.  
  920.                         // Otherwise, iterate through all of the keys in the object.
  921.  
  922.                         for (k in value)
  923.                         {
  924.                             if (Object.prototype.hasOwnProperty.call(value, k))
  925.                             {
  926.                                 v = str(k, value);
  927.                                 if (v)
  928.                                 {
  929.                                     partial.push(quote(k) + ( gap ? ': ' : ':') + v);
  930.                                 }
  931.                             }
  932.                         }
  933.                     }
  934.  
  935.                     // Join all of the member texts together, separated with commas,
  936.                     // and wrap them in braces.
  937.  
  938.                     v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
  939.                     gap = mind;
  940.                     return v;
  941.             }
  942.         }
  943.  
  944.         // If the JSON object does not yet have a stringify method, give it one.
  945.  
  946.         JSON.stringify = function(value, replacer, space)
  947.         {
  948.  
  949.             // The stringify method takes a value and an optional replacer, and an optional
  950.             // space parameter, and returns a JSON text. The replacer can be a function
  951.             // that can replace values, or an array of strings that will select the keys.
  952.             // A default replacer method can be provided. Use of the space parameter can
  953.             // produce text that is more easily readable.
  954.  
  955.             var i;
  956.             gap = '';
  957.             indent = '';
  958.  
  959.             // If the space parameter is a number, make an indent string containing that
  960.             // many spaces.
  961.  
  962.             if ( typeof space === 'number')
  963.             {
  964.                 for ( i = 0; i < space; i += 1)
  965.                 {
  966.                     indent += ' ';
  967.                 }
  968.  
  969.                 // If the space parameter is a string, it will be used as the indent string.
  970.  
  971.             }
  972.             else if ( typeof space === 'string')
  973.             {
  974.                 indent = space;
  975.             }
  976.  
  977.             // If there is a replacer, it must be a function or an array.
  978.             // Otherwise, throw an error.
  979.  
  980.             rep = replacer;
  981.             if (replacer && typeof replacer !== 'function' && ( typeof replacer !== 'object' || typeof replacer.length !== 'number'))
  982.             {
  983.                 throw new Error('JSON.stringify');
  984.             }
  985.  
  986.             // Make a fake root object containing our value under the key of ''.
  987.             // Return the result of stringifying the value.
  988.  
  989.             return str('',
  990.             {
  991.                 '' : value
  992.             });
  993.         };
  994.  
  995.         // If the JSON object does not yet have a parse method, give it one.
  996.  
  997.         JSON.parse = function(text, reviver)
  998.         {
  999.             // The parse method takes a text and an optional reviver function, and returns
  1000.             // a JavaScript value if the text is a valid JSON text.
  1001.  
  1002.             var j;
  1003.  
  1004.             function walk(holder, key)
  1005.             {
  1006.  
  1007.                 // The walk method is used to recursively walk the resulting structure so
  1008.                 // that modifications can be made.
  1009.  
  1010.                 var k, v, value = holder[key];
  1011.                 if (value && typeof value === 'object')
  1012.                 {
  1013.                     for (k in value)
  1014.                     {
  1015.                         if (Object.prototype.hasOwnProperty.call(value, k))
  1016.                         {
  1017.                             v = walk(value, k);
  1018.                             if (v !== undefined)
  1019.                             {
  1020.                                 value[k] = v;
  1021.                             }
  1022.                             else
  1023.                             {
  1024.                                 delete value[k];
  1025.                             }
  1026.                         }
  1027.                     }
  1028.                 }
  1029.                 return reviver.call(holder, key, value);
  1030.             }
  1031.  
  1032.             // Parsing happens in four stages. In the first stage, we replace certain
  1033.             // Unicode characters with escape sequences. JavaScript handles many characters
  1034.             // incorrectly, either silently deleting them, or treating them as line endings.
  1035.  
  1036.             text = String(text);
  1037.             cx.lastIndex = 0;
  1038.             if (cx.test(text))
  1039.             {
  1040.                 text = text.replace(cx, function(a)
  1041.                 {
  1042.                     return '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  1043.                 });
  1044.             }
  1045.  
  1046.             // In the second stage, we run the text against regular expressions that look
  1047.             // for non-JSON patterns. We are especially concerned with '()' and 'new'
  1048.             // because they can cause invocation, and '=' because it can cause mutation.
  1049.             // But just to be safe, we want to reject all unexpected forms.
  1050.  
  1051.             // We split the second stage into 4 regexp operations in order to work around
  1052.             // crippling inefficiencies in IE's and Safari's regexp engines. First we
  1053.             // replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
  1054.             // replace all simple value tokens with ']' characters. Third, we delete all
  1055.             // open brackets that follow a colon or comma or that begin the text. Finally,
  1056.             // we look to see that the remaining characters are only whitespace or ']' or
  1057.             // ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
  1058.  
  1059.             if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, '')))
  1060.             {
  1061.  
  1062.                 // In the third stage we use the eval function to compile the text into a
  1063.                 // JavaScript structure. The '{' operator is subject to a syntactic ambiguity
  1064.                 // in JavaScript: it can begin a block or an object literal. We wrap the text
  1065.                 // in parens to eliminate the ambiguity.
  1066.  
  1067.                 j = eval('(' + text + ')');
  1068.  
  1069.                 // In the optional fourth stage, we recursively walk the new structure, passing
  1070.                 // each name/value pair to a reviver function for possible transformation.
  1071.  
  1072.                 return typeof reviver === 'function' ? walk(
  1073.                 {
  1074.                     '' : j
  1075.                 }, '') : j;
  1076.             }
  1077.  
  1078.             // If the text is not JSON parseable, then a SyntaxError is thrown.
  1079.  
  1080.             throw new SyntaxError('JSON.parse');
  1081.         };
  1082.  
  1083.     })('undefined' != typeof io ? io : module.exports, typeof JSON !== 'undefined' ? JSON : undefined);
  1084.  
  1085.     /**
  1086.      * socket.io
  1087.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  1088.      * MIT Licensed
  1089.      */
  1090.  
  1091.     (function(exports, io)
  1092.     {
  1093.  
  1094.         /**
  1095.          * Parser namespace.
  1096.          *
  1097.          * @namespace
  1098.          */
  1099.  
  1100.         var parser = exports.parser =
  1101.         {
  1102.         };
  1103.  
  1104.         /**
  1105.          * Packet types.
  1106.          */
  1107.  
  1108.         var packets = parser.packets = ['disconnect', 'connect', 'heartbeat', 'message', 'json', 'event', 'ack', 'error', 'noop'];
  1109.  
  1110.         /**
  1111.          * Errors reasons.
  1112.          */
  1113.  
  1114.         var reasons = parser.reasons = ['transport not supported', 'client not handshaken', 'unauthorized'];
  1115.  
  1116.         /**
  1117.          * Errors advice.
  1118.          */
  1119.  
  1120.         var advice = parser.advice = ['reconnect'];
  1121.  
  1122.         /**
  1123.          * Shortcuts.
  1124.          */
  1125.  
  1126.         var JSON = io.JSON, indexOf = io.util.indexOf;
  1127.  
  1128.         /**
  1129.          * Encodes a packet.
  1130.          *
  1131.          * @api private
  1132.          */
  1133.  
  1134.         parser.encodePacket = function(packet)
  1135.         {
  1136.             var type = indexOf(packets, packet.type), id = packet.id || '', endpoint = packet.endpoint || '', ack = packet.ack, data = null;
  1137.  
  1138.             switch (packet.type)
  1139.             {
  1140.                 case 'error':
  1141.                     var reason = packet.reason ? indexOf(reasons, packet.reason) : '', adv = packet.advice ? indexOf(advice, packet.advice) : '';
  1142.  
  1143.                     if (reason !== '' || adv !== '')
  1144.                         data = reason + (adv !== '' ? ('+' + adv) : '');
  1145.  
  1146.                     break;
  1147.  
  1148.                 case 'message':
  1149.                     if (packet.data !== '')
  1150.                         data = packet.data;
  1151.                     break;
  1152.  
  1153.                 case 'event':
  1154.                     var ev =
  1155.                     {
  1156.                         name : packet.name
  1157.                     };
  1158.  
  1159.                     if (packet.args && packet.args.length)
  1160.                     {
  1161.                         ev.args = packet.args;
  1162.                     }
  1163.  
  1164.                     data = JSON.stringify(ev);
  1165.                     break;
  1166.  
  1167.                 case 'json':
  1168.                     data = JSON.stringify(packet.data);
  1169.                     break;
  1170.  
  1171.                 case 'connect':
  1172.                     if (packet.qs)
  1173.                         data = packet.qs;
  1174.                     break;
  1175.  
  1176.                 case 'ack':
  1177.                     data = packet.ackId + (packet.args && packet.args.length ? '+' + JSON.stringify(packet.args) : '');
  1178.                     break;
  1179.             }
  1180.  
  1181.             // construct packet with required fragments
  1182.             var encoded = [type, id + (ack == 'data' ? '+' : ''), endpoint];
  1183.  
  1184.             // data fragment is optional
  1185.             if (data !== null && data !== undefined)
  1186.                 encoded.push(data);
  1187.  
  1188.             return encoded.join(':');
  1189.         };
  1190.  
  1191.         /**
  1192.          * Encodes multiple messages (payload).
  1193.          *
  1194.          * @param {Array} messages
  1195.          * @api private
  1196.          */
  1197.  
  1198.         parser.encodePayload = function(packets)
  1199.         {
  1200.             var decoded = '';
  1201.  
  1202.             if (packets.length == 1)
  1203.                 return packets[0];
  1204.  
  1205.             for (var i = 0, l = packets.length; i < l; i++)
  1206.             {
  1207.                 var packet = packets[i];
  1208.                 decoded += '\ufffd' + packet.length + '\ufffd' + packets[i];
  1209.             }
  1210.  
  1211.             return decoded;
  1212.         };
  1213.  
  1214.         /**
  1215.          * Decodes a packet
  1216.          *
  1217.          * @api private
  1218.          */
  1219.  
  1220.         var regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/;
  1221.  
  1222.         parser.decodePacket = function(data)
  1223.         {
  1224.             var pieces = data.match(regexp);
  1225.  
  1226.             if (!pieces)
  1227.                 return
  1228.                 {
  1229.                 };
  1230.  
  1231.             var id = pieces[2] || '', data = pieces[5] || '', packet =
  1232.             {
  1233.                 type : packets[pieces[1]],
  1234.                 endpoint : pieces[4] || ''
  1235.             };
  1236.  
  1237.             // whether we need to acknowledge the packet
  1238.             if (id)
  1239.             {
  1240.                 packet.id = id;
  1241.                 if (pieces[3])
  1242.                     packet.ack = 'data';
  1243.                 else
  1244.                     packet.ack = true;
  1245.             }
  1246.  
  1247.             // handle different packet types
  1248.             switch (packet.type)
  1249.             {
  1250.                 case 'error':
  1251.                     var pieces = data.split('+');
  1252.                     packet.reason = reasons[pieces[0]] || '';
  1253.                     packet.advice = advice[pieces[1]] || '';
  1254.                     break;
  1255.  
  1256.                 case 'message':
  1257.                     packet.data = data || '';
  1258.                     break;
  1259.  
  1260.                 case 'event':
  1261.                     try
  1262.                     {
  1263.                         var opts = JSON.parse(data);
  1264.                         packet.name = opts.name;
  1265.                         packet.args = opts.args;
  1266.                     }
  1267.                     catch (e)
  1268.                     {
  1269.                     }
  1270.  
  1271.                     packet.args = packet.args || [];
  1272.                     break;
  1273.  
  1274.                 case 'json':
  1275.                     try
  1276.                     {
  1277.                         packet.data = JSON.parse(data);
  1278.                     }
  1279.                     catch (e)
  1280.                     {
  1281.                     }
  1282.                     break;
  1283.  
  1284.                 case 'connect':
  1285.                     packet.qs = data || '';
  1286.                     break;
  1287.  
  1288.                 case 'ack':
  1289.                     var pieces = data.match(/^([0-9]+)(\+)?(.*)/);
  1290.                     if (pieces)
  1291.                     {
  1292.                         packet.ackId = pieces[1];
  1293.                         packet.args = [];
  1294.  
  1295.                         if (pieces[3])
  1296.                         {
  1297.                             try
  1298.                             {
  1299.                                 packet.args = pieces[3] ? JSON.parse(pieces[3]) : [];
  1300.                             }
  1301.                             catch (e)
  1302.                             {
  1303.                             }
  1304.                         }
  1305.                     }
  1306.                     break;
  1307.  
  1308.                 case 'disconnect':
  1309.                 case 'heartbeat':
  1310.                     break;
  1311.             };
  1312.  
  1313.             return packet;
  1314.         };
  1315.  
  1316.         /**
  1317.          * Decodes data payload. Detects multiple messages
  1318.          *
  1319.          * @return {Array} messages
  1320.          * @api public
  1321.          */
  1322.  
  1323.         parser.decodePayload = function(data)
  1324.         {
  1325.             // IE doesn't like data[i] for unicode chars, charAt works fine
  1326.             if (data.charAt(0) == '\ufffd')
  1327.             {
  1328.                 var ret = [];
  1329.  
  1330.                 for (var i = 1, length = ''; i < data.length; i++)
  1331.                 {
  1332.                     if (data.charAt(i) == '\ufffd')
  1333.                     {
  1334.                         ret.push(parser.decodePacket(data.substr(i + 1).substr(0, length)));
  1335.                         i += Number(length) + 1;
  1336.                         length = '';
  1337.                     }
  1338.                     else
  1339.                     {
  1340.                         length += data.charAt(i);
  1341.                     }
  1342.                 }
  1343.  
  1344.                 return ret;
  1345.             }
  1346.             else
  1347.             {
  1348.                 return [parser.decodePacket(data)];
  1349.             }
  1350.         };
  1351.  
  1352.     })('undefined' != typeof io ? io : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  1353.     /**
  1354.      * socket.io
  1355.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  1356.      * MIT Licensed
  1357.      */
  1358.  
  1359.     (function(exports, io)
  1360.     {
  1361.  
  1362.         /**
  1363.          * Expose constructor.
  1364.          */
  1365.  
  1366.         exports.Transport = Transport;
  1367.  
  1368.         /**
  1369.          * This is the transport template for all supported transport methods.
  1370.          *
  1371.          * @constructor
  1372.          * @api public
  1373.          */
  1374.  
  1375.         function Transport(socket, sessid)
  1376.         {
  1377.             this.socket = socket;
  1378.             this.sessid = sessid;
  1379.         };
  1380.  
  1381.         /**
  1382.          * Apply EventEmitter mixin.
  1383.          */
  1384.  
  1385.         io.util.mixin(Transport, io.EventEmitter);
  1386.  
  1387.         /**
  1388.          * Indicates whether heartbeats is enabled for this transport
  1389.          *
  1390.          * @api private
  1391.          */
  1392.  
  1393.         Transport.prototype.heartbeats = function()
  1394.         {
  1395.             return true;
  1396.         };
  1397.  
  1398.         /**
  1399.          * Handles the response from the server. When a new response is received
  1400.          * it will automatically update the timeout, decode the message and
  1401.          * forwards the response to the onMessage function for further processing.
  1402.          *
  1403.          * @param {String} data Response from the server.
  1404.          * @api private
  1405.          */
  1406.  
  1407.         Transport.prototype.onData = function(data)
  1408.         {
  1409.             this.clearCloseTimeout();
  1410.  
  1411.             // If the connection in currently open (or in a reopening state) reset the close
  1412.             // timeout since we have just received data. This check is necessary so
  1413.             // that we don't reset the timeout on an explicitly disconnected connection.
  1414.             if (this.socket.connected || this.socket.connecting || this.socket.reconnecting)
  1415.             {
  1416.                 this.setCloseTimeout();
  1417.             }
  1418.  
  1419.             if (data !== '')
  1420.             {
  1421.                 // todo: we should only do decodePayload for xhr transports
  1422.                 var msgs = io.parser.decodePayload(data);
  1423.  
  1424.                 if (msgs && msgs.length)
  1425.                 {
  1426.                     for (var i = 0, l = msgs.length; i < l; i++)
  1427.                     {
  1428.                         this.onPacket(msgs[i]);
  1429.                     }
  1430.                 }
  1431.             }
  1432.  
  1433.             return this;
  1434.         };
  1435.  
  1436.         /**
  1437.          * Handles packets.
  1438.          *
  1439.          * @api private
  1440.          */
  1441.  
  1442.         Transport.prototype.onPacket = function(packet)
  1443.         {
  1444.             this.socket.setHeartbeatTimeout();
  1445.  
  1446.             if (packet.type == 'heartbeat')
  1447.             {
  1448.                 return this.onHeartbeat();
  1449.             }
  1450.  
  1451.             if (packet.type == 'connect' && packet.endpoint == '')
  1452.             {
  1453.                 this.onConnect();
  1454.             }
  1455.  
  1456.             if (packet.type == 'error' && packet.advice == 'reconnect')
  1457.             {
  1458.                 this.isOpen = false;
  1459.             }
  1460.  
  1461.             this.socket.onPacket(packet);
  1462.  
  1463.             return this;
  1464.         };
  1465.  
  1466.         /**
  1467.          * Sets close timeout
  1468.          *
  1469.          * @api private
  1470.          */
  1471.  
  1472.         Transport.prototype.setCloseTimeout = function()
  1473.         {
  1474.             if (!this.closeTimeout)
  1475.             {
  1476.                 var self = this;
  1477.  
  1478.                 this.closeTimeout = setTimeout(function()
  1479.                 {
  1480.                     self.onDisconnect();
  1481.                 }, this.socket.closeTimeout);
  1482.             }
  1483.         };
  1484.  
  1485.         /**
  1486.          * Called when transport disconnects.
  1487.          *
  1488.          * @api private
  1489.          */
  1490.  
  1491.         Transport.prototype.onDisconnect = function()
  1492.         {
  1493.             if (this.isOpen)
  1494.                 this.close();
  1495.             this.clearTimeouts();
  1496.             this.socket.onDisconnect();
  1497.             return this;
  1498.         };
  1499.  
  1500.         /**
  1501.          * Called when transport connects
  1502.          *
  1503.          * @api private
  1504.          */
  1505.  
  1506.         Transport.prototype.onConnect = function()
  1507.         {
  1508.             this.socket.onConnect();
  1509.             return this;
  1510.         };
  1511.  
  1512.         /**
  1513.          * Clears close timeout
  1514.          *
  1515.          * @api private
  1516.          */
  1517.  
  1518.         Transport.prototype.clearCloseTimeout = function()
  1519.         {
  1520.             if (this.closeTimeout)
  1521.             {
  1522.                 clearTimeout(this.closeTimeout);
  1523.                 this.closeTimeout = null;
  1524.             }
  1525.         };
  1526.  
  1527.         /**
  1528.          * Clear timeouts
  1529.          *
  1530.          * @api private
  1531.          */
  1532.  
  1533.         Transport.prototype.clearTimeouts = function()
  1534.         {
  1535.             this.clearCloseTimeout();
  1536.  
  1537.             if (this.reopenTimeout)
  1538.             {
  1539.                 clearTimeout(this.reopenTimeout);
  1540.             }
  1541.         };
  1542.  
  1543.         /**
  1544.          * Sends a packet
  1545.          *
  1546.          * @param {Object} packet object.
  1547.          * @api private
  1548.          */
  1549.  
  1550.         Transport.prototype.packet = function(packet)
  1551.         {
  1552.             this.send(io.parser.encodePacket(packet));
  1553.         };
  1554.  
  1555.         /**
  1556.          * Send the received heartbeat message back to server. So the server
  1557.          * knows we are still connected.
  1558.          *
  1559.          * @param {String} heartbeat Heartbeat response from the server.
  1560.          * @api private
  1561.          */
  1562.  
  1563.         Transport.prototype.onHeartbeat = function(heartbeat)
  1564.         {
  1565.             this.packet(
  1566.             {
  1567.                 type : 'heartbeat'
  1568.             });
  1569.         };
  1570.  
  1571.         /**
  1572.          * Called when the transport opens.
  1573.          *
  1574.          * @api private
  1575.          */
  1576.  
  1577.         Transport.prototype.onOpen = function()
  1578.         {
  1579.             this.isOpen = true;
  1580.             this.clearCloseTimeout();
  1581.             this.socket.onOpen();
  1582.         };
  1583.  
  1584.         /**
  1585.          * Notifies the base when the connection with the Socket.IO server
  1586.          * has been disconnected.
  1587.          *
  1588.          * @api private
  1589.          */
  1590.  
  1591.         Transport.prototype.onClose = function()
  1592.         {
  1593.             var self = this;
  1594.  
  1595.             /* FIXME: reopen delay causing a infinit loop
  1596.              this.reopenTimeout = setTimeout(function () {
  1597.              self.open();
  1598.              }, this.socket.options['reopen delay']);*/
  1599.  
  1600.             this.isOpen = false;
  1601.             this.socket.onClose();
  1602.             this.onDisconnect();
  1603.         };
  1604.  
  1605.         /**
  1606.          * Generates a connection url based on the Socket.IO URL Protocol.
  1607.          * See <https://github.com/learnboost/socket.io-node/> for more details.
  1608.          *
  1609.          * @returns {String} Connection url
  1610.          * @api private
  1611.          */
  1612.  
  1613.         Transport.prototype.prepareUrl = function()
  1614.         {
  1615.             var options = this.socket.options;
  1616.  
  1617.             return this.scheme() + '://' + options.host + ':' + options.port + '/' + options.resource + '/' + io.protocol + '/' + this.name + '/' + this.sessid;
  1618.         };
  1619.  
  1620.         /**
  1621.          * Checks if the transport is ready to start a connection.
  1622.          *
  1623.          * @param {Socket} socket The socket instance that needs a transport
  1624.          * @param {Function} fn The callback
  1625.          * @api private
  1626.          */
  1627.  
  1628.         Transport.prototype.ready = function(socket, fn)
  1629.         {
  1630.             fn.call(this);
  1631.         };
  1632.     })('undefined' != typeof io ? io : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  1633.     /**
  1634.      * socket.io
  1635.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  1636.      * MIT Licensed
  1637.      */
  1638.  
  1639.     (function(exports, io, global)
  1640.     {
  1641.  
  1642.         /**
  1643.          * Expose constructor.
  1644.          */
  1645.  
  1646.         exports.Socket = Socket;
  1647.  
  1648.         /**
  1649.          * Create a new `Socket.IO client` which can establish a persistent
  1650.          * connection with a Socket.IO enabled server.
  1651.          *
  1652.          * @api public
  1653.          */
  1654.  
  1655.         function Socket(options)
  1656.         {
  1657.             this.options =
  1658.             {
  1659.                 port : 80,
  1660.                 secure : false,
  1661.                 document : 'document' in global ? document : false,
  1662.                 resource : 'socket.io',
  1663.                 transports : io.transports,
  1664.                 'connect timeout' : 10000,
  1665.                 'try multiple transports' : true,
  1666.                 'reconnect' : true,
  1667.                 'reconnection delay' : 500,
  1668.                 'reconnection limit' : Infinity,
  1669.                 'reopen delay' : 3000,
  1670.                 'max reconnection attempts' : 10,
  1671.                 'sync disconnect on unload' : false,
  1672.                 'auto connect' : true,
  1673.                 'flash policy port' : 10843,
  1674.                 'manualFlush' : false
  1675.             };
  1676.  
  1677.             io.util.merge(this.options, options);
  1678.  
  1679.             this.connected = false;
  1680.             this.open = false;
  1681.             this.connecting = false;
  1682.             this.reconnecting = false;
  1683.             this.namespaces =
  1684.             {
  1685.             };
  1686.             this.buffer = [];
  1687.             this.doBuffer = false;
  1688.  
  1689.             if (this.options['sync disconnect on unload'] && (!this.isXDomain() || io.util.ua.hasCORS))
  1690.             {
  1691.                 var self = this;
  1692.                 io.util.on(global, 'beforeunload', function()
  1693.                 {
  1694.                     self.disconnectSync();
  1695.                 }, false);
  1696.             }
  1697.  
  1698.             if (this.options['auto connect'])
  1699.             {
  1700.                 this.connect();
  1701.             }
  1702.         };
  1703.  
  1704.         /**
  1705.          * Apply EventEmitter mixin.
  1706.          */
  1707.  
  1708.         io.util.mixin(Socket, io.EventEmitter);
  1709.  
  1710.         /**
  1711.          * Returns a namespace listener/emitter for this socket
  1712.          *
  1713.          * @api public
  1714.          */
  1715.  
  1716.         Socket.prototype.of = function(name)
  1717.         {
  1718.             if (!this.namespaces[name])
  1719.             {
  1720.                 this.namespaces[name] = new io.SocketNamespace(this, name);
  1721.  
  1722.                 if (name !== '')
  1723.                 {
  1724.                     this.namespaces[name].packet(
  1725.                     {
  1726.                         type : 'connect'
  1727.                     });
  1728.                 }
  1729.             }
  1730.  
  1731.             return this.namespaces[name];
  1732.         };
  1733.  
  1734.         /**
  1735.          * Emits the given event to the Socket and all namespaces
  1736.          *
  1737.          * @api private
  1738.          */
  1739.  
  1740.         Socket.prototype.publish = function()
  1741.         {
  1742.             this.emit.apply(this, arguments);
  1743.  
  1744.             var nsp;
  1745.  
  1746.             for (var i in this.namespaces)
  1747.             {
  1748.                 if (this.namespaces.hasOwnProperty(i))
  1749.                 {
  1750.                     nsp = this.of(i);
  1751.                     nsp.$emit.apply(nsp, arguments);
  1752.                 }
  1753.             }
  1754.         };
  1755.  
  1756.         /**
  1757.          * Performs the handshake
  1758.          *
  1759.          * @api private
  1760.          */
  1761.  
  1762.         function empty()
  1763.         {
  1764.         };
  1765.  
  1766.         Socket.prototype.handshake = function(fn)
  1767.         {
  1768.             var self = this, options = this.options;
  1769.  
  1770.             function complete(data)
  1771.             {
  1772.                 if ( data instanceof Error)
  1773.                 {
  1774.                     self.connecting = false;
  1775.                     self.onError(data.message);
  1776.                 }
  1777.                 else
  1778.                 {
  1779.                     fn.apply(null, data.split(':'));
  1780.                 }
  1781.             };
  1782.  
  1783.             var url = ['http' + (options.secure ? 's' : '') + ':/', options.host + ':' + options.port, options.resource, io.protocol, io.util.query(this.options.query, 't=' + +new Date)].join('/');
  1784.  
  1785.             if (this.isXDomain() && !io.util.ua.hasCORS)
  1786.             {
  1787.                 var insertAt = document.getElementsByTagName('script')[0], script = document.createElement('script');
  1788.  
  1789.                 script.src = url + '&jsonp=' + io.j.length;
  1790.                 insertAt.parentNode.insertBefore(script, insertAt);
  1791.  
  1792.                 io.j.push(function(data)
  1793.                 {
  1794.                     complete(data);
  1795.                     script.parentNode.removeChild(script);
  1796.                 });
  1797.             }
  1798.             else
  1799.             {
  1800.                 var xhr = io.util.request();
  1801.  
  1802.                 xhr.open('GET', url, true);
  1803.                 if (this.isXDomain())
  1804.                 {
  1805.                     xhr.withCredentials = true;
  1806.                 }
  1807.                 xhr.onreadystatechange = function()
  1808.                 {
  1809.                     if (xhr.readyState == 4)
  1810.                     {
  1811.                         xhr.onreadystatechange = empty;
  1812.  
  1813.                         if (xhr.status == 200)
  1814.                         {
  1815.                             complete(xhr.responseText);
  1816.                         }
  1817.                         else if (xhr.status == 403)
  1818.                         {
  1819.                             self.onError(xhr.responseText);
  1820.                         }
  1821.                         else
  1822.                         {
  1823.                             self.connecting = false;
  1824.                             !self.reconnecting && self.onError(xhr.responseText);
  1825.                         }
  1826.                     }
  1827.                 };
  1828.                 xhr.send(null);
  1829.             }
  1830.         };
  1831.  
  1832.         /**
  1833.          * Find an available transport based on the options supplied in the constructor.
  1834.          *
  1835.          * @api private
  1836.          */
  1837.  
  1838.         Socket.prototype.getTransport = function(override)
  1839.         {
  1840.             var transports = override || this.transports, match;
  1841.  
  1842.             for (var i = 0, transport; transport = transports[i]; i++)
  1843.             {
  1844.                 if (io.Transport[transport] && io.Transport[transport].check(this) && (!this.isXDomain() || io.Transport[transport].xdomainCheck(this)))
  1845.                 {
  1846.                     return new io.Transport[transport](this, this.sessionid);
  1847.                 }
  1848.             }
  1849.  
  1850.             return null;
  1851.         };
  1852.  
  1853.         /**
  1854.          * Connects to the server.
  1855.          *
  1856.          * @param {Function} [fn] Callback.
  1857.          * @returns {io.Socket}
  1858.          * @api public
  1859.          */
  1860.  
  1861.         Socket.prototype.connect = function(fn)
  1862.         {
  1863.             if (this.connecting)
  1864.             {
  1865.                 return this;
  1866.             }
  1867.  
  1868.             var self = this;
  1869.             self.connecting = true;
  1870.  
  1871.             this.handshake(function(sid, heartbeat, close, transports)
  1872.             {
  1873.                 self.sessionid = sid;
  1874.                 self.closeTimeout = close * 1000;
  1875.                 self.heartbeatTimeout = heartbeat * 1000;
  1876.                 if (!self.transports)
  1877.                     self.transports = self.origTransports = ( transports ? io.util.intersect(transports.split(','), self.options.transports) : self.options.transports);
  1878.  
  1879.                 self.setHeartbeatTimeout();
  1880.  
  1881.                 function connect(transports)
  1882.                 {
  1883.                     if (self.transport)
  1884.                         self.transport.clearTimeouts();
  1885.  
  1886.                     self.transport = self.getTransport(transports);
  1887.                     if (!self.transport)
  1888.                         return self.publish('connect_failed');
  1889.  
  1890.                     // once the transport is ready
  1891.                     self.transport.ready(self, function()
  1892.                     {
  1893.                         self.connecting = true;
  1894.                         self.publish('connecting', self.transport.name);
  1895.                         self.transport.open();
  1896.  
  1897.                         if (self.options['connect timeout'])
  1898.                         {
  1899.                             self.connectTimeoutTimer = setTimeout(function()
  1900.                             {
  1901.                                 if (!self.connected)
  1902.                                 {
  1903.                                     self.connecting = false;
  1904.  
  1905.                                     if (self.options['try multiple transports'])
  1906.                                     {
  1907.                                         var remaining = self.transports;
  1908.  
  1909.                                         while (remaining.length > 0 && remaining.splice(0,1)[0] != self.transport.name)
  1910.                                         {
  1911.                                         }
  1912.  
  1913.                                         if (remaining.length)
  1914.                                         {
  1915.                                             connect(remaining);
  1916.                                         }
  1917.                                         else
  1918.                                         {
  1919.                                             self.publish('connect_failed');
  1920.                                         }
  1921.                                     }
  1922.                                 }
  1923.                             }, self.options['connect timeout']);
  1924.                         }
  1925.                     });
  1926.                 }
  1927.  
  1928.                 connect(self.transports);
  1929.  
  1930.                 self.once('connect', function()
  1931.                 {
  1932.                     clearTimeout(self.connectTimeoutTimer);
  1933.  
  1934.                     fn && typeof fn == 'function' && fn();
  1935.                 });
  1936.             });
  1937.  
  1938.             return this;
  1939.         };
  1940.  
  1941.         /**
  1942.          * Clears and sets a new heartbeat timeout using the value given by the
  1943.          * server during the handshake.
  1944.          *
  1945.          * @api private
  1946.          */
  1947.  
  1948.         Socket.prototype.setHeartbeatTimeout = function()
  1949.         {
  1950.             clearTimeout(this.heartbeatTimeoutTimer);
  1951.             if (this.transport && !this.transport.heartbeats())
  1952.                 return;
  1953.  
  1954.             var self = this;
  1955.             this.heartbeatTimeoutTimer = setTimeout(function()
  1956.             {
  1957.                 self.transport.onClose();
  1958.             }, this.heartbeatTimeout);
  1959.         };
  1960.  
  1961.         /**
  1962.          * Sends a message.
  1963.          *
  1964.          * @param {Object} data packet.
  1965.          * @returns {io.Socket}
  1966.          * @api public
  1967.          */
  1968.  
  1969.         Socket.prototype.packet = function(data)
  1970.         {
  1971.             if (this.connected && !this.doBuffer)
  1972.             {
  1973.                 this.transport.packet(data);
  1974.             }
  1975.             else
  1976.             {
  1977.                 this.buffer.push(data);
  1978.             }
  1979.  
  1980.             return this;
  1981.         };
  1982.  
  1983.         /**
  1984.          * Sets buffer state
  1985.          *
  1986.          * @api private
  1987.          */
  1988.  
  1989.         Socket.prototype.setBuffer = function(v)
  1990.         {
  1991.             this.doBuffer = v;
  1992.  
  1993.             if (!v && this.connected && this.buffer.length)
  1994.             {
  1995.                 if (!this.options['manualFlush'])
  1996.                 {
  1997.                     this.flushBuffer();
  1998.                 }
  1999.             }
  2000.         };
  2001.  
  2002.         /**
  2003.          * Flushes the buffer data over the wire.
  2004.          * To be invoked manually when 'manualFlush' is set to true.
  2005.          *
  2006.          * @api public
  2007.          */
  2008.  
  2009.         Socket.prototype.flushBuffer = function()
  2010.         {
  2011.             this.transport.payload(this.buffer);
  2012.             this.buffer = [];
  2013.         };
  2014.  
  2015.         /**
  2016.          * Disconnect the established connect.
  2017.          *
  2018.          * @returns {io.Socket}
  2019.          * @api public
  2020.          */
  2021.  
  2022.         Socket.prototype.disconnect = function()
  2023.         {
  2024.             if (this.connected || this.connecting)
  2025.             {
  2026.                 if (this.open)
  2027.                 {
  2028.                     this.of('').packet(
  2029.                     {
  2030.                         type : 'disconnect'
  2031.                     });
  2032.                 }
  2033.  
  2034.                 // handle disconnection immediately
  2035.                 this.onDisconnect('booted');
  2036.             }
  2037.  
  2038.             return this;
  2039.         };
  2040.  
  2041.         /**
  2042.          * Disconnects the socket with a sync XHR.
  2043.          *
  2044.          * @api private
  2045.          */
  2046.  
  2047.         Socket.prototype.disconnectSync = function()
  2048.         {
  2049.             // ensure disconnection
  2050.             var xhr = io.util.request();
  2051.             var uri = ['http' + (this.options.secure ? 's' : '') + ':/', this.options.host + ':' + this.options.port, this.options.resource, io.protocol, '', this.sessionid].join('/') + '/?disconnect=1';
  2052.  
  2053.             xhr.open('GET', uri, false);
  2054.             xhr.send(null);
  2055.  
  2056.             // handle disconnection immediately
  2057.             this.onDisconnect('booted');
  2058.         };
  2059.  
  2060.         /**
  2061.          * Check if we need to use cross domain enabled transports. Cross domain would
  2062.          * be a different port or different domain name.
  2063.          *
  2064.          * @returns {Boolean}
  2065.          * @api private
  2066.          */
  2067.  
  2068.         Socket.prototype.isXDomain = function()
  2069.         {
  2070.  
  2071.             var port = global.location.port || ('https:' == global.location.protocol ? 443 : 80);
  2072.  
  2073.             return this.options.host !== global.location.hostname || this.options.port != port;
  2074.         };
  2075.  
  2076.         /**
  2077.          * Called upon handshake.
  2078.          *
  2079.          * @api private
  2080.          */
  2081.  
  2082.         Socket.prototype.onConnect = function()
  2083.         {
  2084.             if (!this.connected)
  2085.             {
  2086.                 this.connected = true;
  2087.                 this.connecting = false;
  2088.                 if (!this.doBuffer)
  2089.                 {
  2090.                     // make sure to flush the buffer
  2091.                     this.setBuffer(false);
  2092.                 }
  2093.                 this.emit('connect');
  2094.             }
  2095.         };
  2096.  
  2097.         /**
  2098.          * Called when the transport opens
  2099.          *
  2100.          * @api private
  2101.          */
  2102.  
  2103.         Socket.prototype.onOpen = function()
  2104.         {
  2105.             this.open = true;
  2106.         };
  2107.  
  2108.         /**
  2109.          * Called when the transport closes.
  2110.          *
  2111.          * @api private
  2112.          */
  2113.  
  2114.         Socket.prototype.onClose = function()
  2115.         {
  2116.             this.open = false;
  2117.             clearTimeout(this.heartbeatTimeoutTimer);
  2118.         };
  2119.  
  2120.         /**
  2121.          * Called when the transport first opens a connection
  2122.          *
  2123.          * @param text
  2124.          */
  2125.  
  2126.         Socket.prototype.onPacket = function(packet)
  2127.         {
  2128.             this.of(packet.endpoint).onPacket(packet);
  2129.         };
  2130.  
  2131.         /**
  2132.          * Handles an error.
  2133.          *
  2134.          * @api private
  2135.          */
  2136.  
  2137.         Socket.prototype.onError = function(err)
  2138.         {
  2139.             if (err && err.advice)
  2140.             {
  2141.                 if (err.advice === 'reconnect' && (this.connected || this.connecting))
  2142.                 {
  2143.                     this.disconnect();
  2144.                     if (this.options.reconnect)
  2145.                     {
  2146.                         this.reconnect();
  2147.                     }
  2148.                 }
  2149.             }
  2150.  
  2151.             this.publish('error', err && err.reason ? err.reason : err);
  2152.         };
  2153.  
  2154.         /**
  2155.          * Called when the transport disconnects.
  2156.          *
  2157.          * @api private
  2158.          */
  2159.  
  2160.         Socket.prototype.onDisconnect = function(reason)
  2161.         {
  2162.             var wasConnected = this.connected, wasConnecting = this.connecting;
  2163.  
  2164.             this.connected = false;
  2165.             this.connecting = false;
  2166.             this.open = false;
  2167.  
  2168.             if (wasConnected || wasConnecting)
  2169.             {
  2170.                 this.transport.close();
  2171.                 this.transport.clearTimeouts();
  2172.                 if (wasConnected)
  2173.                 {
  2174.                     this.publish('disconnect', reason);
  2175.  
  2176.                     if ('booted' != reason && this.options.reconnect && !this.reconnecting)
  2177.                     {
  2178.                         this.reconnect();
  2179.                     }
  2180.                 }
  2181.             }
  2182.         };
  2183.  
  2184.         /**
  2185.          * Called upon reconnection.
  2186.          *
  2187.          * @api private
  2188.          */
  2189.  
  2190.         Socket.prototype.reconnect = function()
  2191.         {
  2192.             this.reconnecting = true;
  2193.             this.reconnectionAttempts = 0;
  2194.             this.reconnectionDelay = this.options['reconnection delay'];
  2195.  
  2196.             var self = this, maxAttempts = this.options['max reconnection attempts'], tryMultiple = this.options['try multiple transports'], limit = this.options['reconnection limit'];
  2197.  
  2198.             function reset()
  2199.             {
  2200.                 if (self.connected)
  2201.                 {
  2202.                     for (var i in self.namespaces)
  2203.                     {
  2204.                         if (self.namespaces.hasOwnProperty(i) && '' !== i)
  2205.                         {
  2206.                             self.namespaces[i].packet(
  2207.                             {
  2208.                                 type : 'connect'
  2209.                             });
  2210.                         }
  2211.                     }
  2212.                     self.publish('reconnect', self.transport.name, self.reconnectionAttempts);
  2213.                 }
  2214.  
  2215.                 clearTimeout(self.reconnectionTimer);
  2216.  
  2217.                 self.removeListener('connect_failed', maybeReconnect);
  2218.                 self.removeListener('connect', maybeReconnect);
  2219.  
  2220.                 self.reconnecting = false;
  2221.                 delete self.reconnectionAttempts;
  2222.                 delete self.reconnectionDelay;
  2223.                 delete self.reconnectionTimer;
  2224.                 delete self.redoTransports;
  2225.  
  2226.                 self.options['try multiple transports'] = tryMultiple;
  2227.             };
  2228.  
  2229.             function maybeReconnect()
  2230.             {
  2231.                 if (!self.reconnecting)
  2232.                 {
  2233.                     return;
  2234.                 }
  2235.  
  2236.                 if (self.connected)
  2237.                 {
  2238.                     return reset();
  2239.                 };
  2240.  
  2241.                 if (self.connecting && self.reconnecting)
  2242.                 {
  2243.                     return self.reconnectionTimer = setTimeout(maybeReconnect, 1000);
  2244.                 }
  2245.  
  2246.                 if (self.reconnectionAttempts++ >= maxAttempts)
  2247.                 {
  2248.                     if (!self.redoTransports)
  2249.                     {
  2250.                         self.on('connect_failed', maybeReconnect);
  2251.                         self.options['try multiple transports'] = true;
  2252.                         self.transports = self.origTransports;
  2253.                         self.transport = self.getTransport();
  2254.                         self.redoTransports = true;
  2255.                         self.connect();
  2256.                     }
  2257.                     else
  2258.                     {
  2259.                         self.publish('reconnect_failed');
  2260.                         reset();
  2261.                     }
  2262.                 }
  2263.                 else
  2264.                 {
  2265.                     if (self.reconnectionDelay < limit)
  2266.                     {
  2267.                         self.reconnectionDelay *= 2;
  2268.                         // exponential back off
  2269.                     }
  2270.  
  2271.                     self.connect();
  2272.                     self.publish('reconnecting', self.reconnectionDelay, self.reconnectionAttempts);
  2273.                     self.reconnectionTimer = setTimeout(maybeReconnect, self.reconnectionDelay);
  2274.                 }
  2275.             };
  2276.  
  2277.             this.options['try multiple transports'] = false;
  2278.             this.reconnectionTimer = setTimeout(maybeReconnect, this.reconnectionDelay);
  2279.  
  2280.             this.on('connect', maybeReconnect);
  2281.         };
  2282.  
  2283.     })('undefined' != typeof io ? io : module.exports, 'undefined' != typeof io ? io : module.parent.exports, this);
  2284.     /**
  2285.      * socket.io
  2286.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  2287.      * MIT Licensed
  2288.      */
  2289.  
  2290.     (function(exports, io)
  2291.     {
  2292.  
  2293.         /**
  2294.          * Expose constructor.
  2295.          */
  2296.  
  2297.         exports.SocketNamespace = SocketNamespace;
  2298.  
  2299.         /**
  2300.          * Socket namespace constructor.
  2301.          *
  2302.          * @constructor
  2303.          * @api public
  2304.          */
  2305.  
  2306.         function SocketNamespace(socket, name)
  2307.         {
  2308.             this.socket = socket;
  2309.             this.name = name || '';
  2310.             this.flags =
  2311.             {
  2312.             };
  2313.             this.json = new Flag(this, 'json');
  2314.             this.ackPackets = 0;
  2315.             this.acks =
  2316.             {
  2317.             };
  2318.         };
  2319.  
  2320.         /**
  2321.          * Apply EventEmitter mixin.
  2322.          */
  2323.  
  2324.         io.util.mixin(SocketNamespace, io.EventEmitter);
  2325.  
  2326.         /**
  2327.          * Copies emit since we override it
  2328.          *
  2329.          * @api private
  2330.          */
  2331.  
  2332.         SocketNamespace.prototype.$emit = io.EventEmitter.prototype.emit;
  2333.  
  2334.         /**
  2335.          * Creates a new namespace, by proxying the request to the socket. This
  2336.          * allows us to use the synax as we do on the server.
  2337.          *
  2338.          * @api public
  2339.          */
  2340.  
  2341.         SocketNamespace.prototype.of = function()
  2342.         {
  2343.             return this.socket.of.apply(this.socket, arguments);
  2344.         };
  2345.  
  2346.         /**
  2347.          * Sends a packet.
  2348.          *
  2349.          * @api private
  2350.          */
  2351.  
  2352.         SocketNamespace.prototype.packet = function(packet)
  2353.         {
  2354.             packet.endpoint = this.name;
  2355.             this.socket.packet(packet);
  2356.             this.flags =
  2357.             {
  2358.             };
  2359.             return this;
  2360.         };
  2361.  
  2362.         /**
  2363.          * Sends a message
  2364.          *
  2365.          * @api public
  2366.          */
  2367.  
  2368.         SocketNamespace.prototype.send = function(data, fn)
  2369.         {
  2370.             var packet =
  2371.             {
  2372.                 type : this.flags.json ? 'json' : 'message',
  2373.                 data : data
  2374.             };
  2375.  
  2376.             if ('function' == typeof fn)
  2377.             {
  2378.                 packet.id = ++this.ackPackets;
  2379.                 packet.ack = true;
  2380.                 this.acks[packet.id] = fn;
  2381.             }
  2382.  
  2383.             return this.packet(packet);
  2384.         };
  2385.  
  2386.         /**
  2387.          * Emits an event
  2388.          *
  2389.          * @api public
  2390.          */
  2391.  
  2392.         SocketNamespace.prototype.emit = function(name)
  2393.         {
  2394.             var args = Array.prototype.slice.call(arguments, 1), lastArg = args[args.length - 1], packet =
  2395.             {
  2396.                 type : 'event',
  2397.                 name : name
  2398.             };
  2399.  
  2400.             if ('function' == typeof lastArg)
  2401.             {
  2402.                 packet.id = ++this.ackPackets;
  2403.                 packet.ack = 'data';
  2404.                 this.acks[packet.id] = lastArg;
  2405.                 args = args.slice(0, args.length - 1);
  2406.             }
  2407.  
  2408.             packet.args = args;
  2409.  
  2410.             return this.packet(packet);
  2411.         };
  2412.  
  2413.         /**
  2414.          * Disconnects the namespace
  2415.          *
  2416.          * @api private
  2417.          */
  2418.  
  2419.         SocketNamespace.prototype.disconnect = function()
  2420.         {
  2421.             if (this.name === '')
  2422.             {
  2423.                 this.socket.disconnect();
  2424.             }
  2425.             else
  2426.             {
  2427.                 this.packet(
  2428.                 {
  2429.                     type : 'disconnect'
  2430.                 });
  2431.                 this.$emit('disconnect');
  2432.             }
  2433.  
  2434.             return this;
  2435.         };
  2436.  
  2437.         /**
  2438.          * Handles a packet
  2439.          *
  2440.          * @api private
  2441.          */
  2442.  
  2443.         SocketNamespace.prototype.onPacket = function(packet)
  2444.         {
  2445.             var self = this;
  2446.  
  2447.             function ack()
  2448.             {
  2449.                 self.packet(
  2450.                 {
  2451.                     type : 'ack',
  2452.                     args : io.util.toArray(arguments),
  2453.                     ackId : packet.id
  2454.                 });
  2455.             };
  2456.  
  2457.             switch (packet.type)
  2458.             {
  2459.                 case 'connect':
  2460.                     this.$emit('connect');
  2461.                     break;
  2462.  
  2463.                 case 'disconnect':
  2464.                     if (this.name === '')
  2465.                     {
  2466.                         this.socket.onDisconnect(packet.reason || 'booted');
  2467.                     }
  2468.                     else
  2469.                     {
  2470.                         this.$emit('disconnect', packet.reason);
  2471.                     }
  2472.                     break;
  2473.  
  2474.                 case 'message':
  2475.                 case 'json':
  2476.                     var params = ['message', packet.data];
  2477.  
  2478.                     if (packet.ack == 'data')
  2479.                     {
  2480.                         params.push(ack);
  2481.                     }
  2482.                     else if (packet.ack)
  2483.                     {
  2484.                         this.packet(
  2485.                         {
  2486.                             type : 'ack',
  2487.                             ackId : packet.id
  2488.                         });
  2489.                     }
  2490.  
  2491.                     this.$emit.apply(this, params);
  2492.                     break;
  2493.  
  2494.                 case 'event':
  2495.                     var params = [packet.name].concat(packet.args);
  2496.  
  2497.                     if (packet.ack == 'data')
  2498.                         params.push(ack);
  2499.  
  2500.                     this.$emit.apply(this, params);
  2501.                     break;
  2502.  
  2503.                 case 'ack':
  2504.                     if (this.acks[packet.ackId])
  2505.                     {
  2506.                         this.acks[packet.ackId].apply(this, packet.args);
  2507.                         delete this.acks[packet.ackId];
  2508.                     }
  2509.                     break;
  2510.  
  2511.                 case 'error':
  2512.                     if (packet.advice)
  2513.                     {
  2514.                         this.socket.onError(packet);
  2515.                     }
  2516.                     else
  2517.                     {
  2518.                         if (packet.reason == 'unauthorized')
  2519.                         {
  2520.                             this.$emit('connect_failed', packet.reason);
  2521.                         }
  2522.                         else
  2523.                         {
  2524.                             this.$emit('error', packet.reason);
  2525.                         }
  2526.                     }
  2527.                     break;
  2528.             }
  2529.         };
  2530.  
  2531.         /**
  2532.          * Flag interface.
  2533.          *
  2534.          * @api private
  2535.          */
  2536.  
  2537.         function Flag(nsp, name)
  2538.         {
  2539.             this.namespace = nsp;
  2540.             this.name = name;
  2541.         };
  2542.  
  2543.         /**
  2544.          * Send a message
  2545.          *
  2546.          * @api public
  2547.          */
  2548.  
  2549.         Flag.prototype.send = function()
  2550.         {
  2551.             this.namespace.flags[this.name] = true;
  2552.             this.namespace.send.apply(this.namespace, arguments);
  2553.         };
  2554.  
  2555.         /**
  2556.          * Emit an event
  2557.          *
  2558.          * @api public
  2559.          */
  2560.  
  2561.         Flag.prototype.emit = function()
  2562.         {
  2563.             this.namespace.flags[this.name] = true;
  2564.             this.namespace.emit.apply(this.namespace, arguments);
  2565.         };
  2566.  
  2567.     })('undefined' != typeof io ? io : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  2568.  
  2569.     /**
  2570.      * socket.io
  2571.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  2572.      * MIT Licensed
  2573.      */
  2574.  
  2575.     (function(exports, io, global)
  2576.     {
  2577.  
  2578.         /**
  2579.          * Expose constructor.
  2580.          */
  2581.  
  2582.         exports.websocket = WS;
  2583.  
  2584.         /**
  2585.          * The WebSocket transport uses the HTML5 WebSocket API to establish an
  2586.          * persistent connection with the Socket.IO server. This transport will also
  2587.          * be inherited by the FlashSocket fallback as it provides a API compatible
  2588.          * polyfill for the WebSockets.
  2589.          *
  2590.          * @constructor
  2591.          * @extends {io.Transport}
  2592.          * @api public
  2593.          */
  2594.  
  2595.         function WS(socket)
  2596.         {
  2597.             io.Transport.apply(this, arguments);
  2598.         };
  2599.  
  2600.         /**
  2601.          * Inherits from Transport.
  2602.          */
  2603.  
  2604.         io.util.inherit(WS, io.Transport);
  2605.  
  2606.         /**
  2607.          * Transport name
  2608.          *
  2609.          * @api public
  2610.          */
  2611.  
  2612.         WS.prototype.name = 'websocket';
  2613.  
  2614.         /**
  2615.          * Initializes a new `WebSocket` connection with the Socket.IO server. We attach
  2616.          * all the appropriate listeners to handle the responses from the server.
  2617.          *
  2618.          * @returns {Transport}
  2619.          * @api public
  2620.          */
  2621.  
  2622.         WS.prototype.open = function()
  2623.         {
  2624.             var query = io.util.query(this.socket.options.query), self = this, Socket;
  2625.  
  2626.             if (!Socket)
  2627.             {
  2628.                 Socket = global.MozWebSocket || global.WebSocket;
  2629.             }
  2630.  
  2631.             this.websocket = new Socket(this.prepareUrl() + query);
  2632.  
  2633.             this.websocket.onopen = function()
  2634.             {
  2635.                 self.onOpen();
  2636.                 self.socket.setBuffer(false);
  2637.             };
  2638.             this.websocket.onmessage = function(ev)
  2639.             {
  2640.                 self.onData(ev.data);
  2641.             };
  2642.             this.websocket.onclose = function()
  2643.             {
  2644.                 self.onClose();
  2645.                 self.socket.setBuffer(true);
  2646.             };
  2647.             this.websocket.onerror = function(e)
  2648.             {
  2649.                 self.onError(e);
  2650.             };
  2651.  
  2652.             return this;
  2653.         };
  2654.  
  2655.         /**
  2656.          * Send a message to the Socket.IO server. The message will automatically be
  2657.          * encoded in the correct message format.
  2658.          *
  2659.          * @returns {Transport}
  2660.          * @api public
  2661.          */
  2662.  
  2663.         // Do to a bug in the current IDevices browser, we need to wrap the send in a
  2664.         // setTimeout, when they resume from sleeping the browser will crash if
  2665.         // we don't allow the browser time to detect the socket has been closed
  2666.         if (io.util.ua.iDevice)
  2667.         {
  2668.             WS.prototype.send = function(data)
  2669.             {
  2670.                 var self = this;
  2671.                 setTimeout(function()
  2672.                 {
  2673.                     self.websocket.send(data);
  2674.                 }, 0);
  2675.                 return this;
  2676.             };
  2677.         }
  2678.         else
  2679.         {
  2680.             WS.prototype.send = function(data)
  2681.             {
  2682.                 this.websocket.send(data);
  2683.                 return this;
  2684.             };
  2685.         }
  2686.  
  2687.         /**
  2688.          * Payload
  2689.          *
  2690.          * @api private
  2691.          */
  2692.  
  2693.         WS.prototype.payload = function(arr)
  2694.         {
  2695.             for (var i = 0, l = arr.length; i < l; i++)
  2696.             {
  2697.                 this.packet(arr[i]);
  2698.             }
  2699.             return this;
  2700.         };
  2701.  
  2702.         /**
  2703.          * Disconnect the established `WebSocket` connection.
  2704.          *
  2705.          * @returns {Transport}
  2706.          * @api public
  2707.          */
  2708.  
  2709.         WS.prototype.close = function()
  2710.         {
  2711.             this.websocket.close();
  2712.             return this;
  2713.         };
  2714.  
  2715.         /**
  2716.          * Handle the errors that `WebSocket` might be giving when we
  2717.          * are attempting to connect or send messages.
  2718.          *
  2719.          * @param {Error} e The error.
  2720.          * @api private
  2721.          */
  2722.  
  2723.         WS.prototype.onError = function(e)
  2724.         {
  2725.             this.socket.onError(e);
  2726.         };
  2727.  
  2728.         /**
  2729.          * Returns the appropriate scheme for the URI generation.
  2730.          *
  2731.          * @api private
  2732.          */
  2733.         WS.prototype.scheme = function()
  2734.         {
  2735.             return this.socket.options.secure ? 'wss' : 'ws';
  2736.         };
  2737.  
  2738.         /**
  2739.          * Checks if the browser has support for native `WebSockets` and that
  2740.          * it's not the polyfill created for the FlashSocket transport.
  2741.          *
  2742.          * @return {Boolean}
  2743.          * @api public
  2744.          */
  2745.  
  2746.         WS.check = function()
  2747.         {
  2748.             return ('WebSocket' in global && !('__addTask' in WebSocket)) || 'MozWebSocket' in global;
  2749.         };
  2750.  
  2751.         /**
  2752.          * Check if the `WebSocket` transport support cross domain communications.
  2753.          *
  2754.          * @returns {Boolean}
  2755.          * @api public
  2756.          */
  2757.  
  2758.         WS.xdomainCheck = function()
  2759.         {
  2760.             return true;
  2761.         };
  2762.  
  2763.         /**
  2764.          * Add the transport to your public io.transports array.
  2765.          *
  2766.          * @api private
  2767.          */
  2768.  
  2769.         io.transports.push('websocket');
  2770.  
  2771.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports, this);
  2772.  
  2773.     /**
  2774.      * socket.io
  2775.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  2776.      * MIT Licensed
  2777.      */
  2778.  
  2779.     (function(exports, io)
  2780.     {
  2781.  
  2782.         /**
  2783.          * Expose constructor.
  2784.          */
  2785.  
  2786.         exports.flashsocket = Flashsocket;
  2787.  
  2788.         /**
  2789.          * The FlashSocket transport. This is a API wrapper for the HTML5 WebSocket
  2790.          * specification. It uses a .swf file to communicate with the server. If you want
  2791.          * to serve the .swf file from a other server than where the Socket.IO script is
  2792.          * coming from you need to use the insecure version of the .swf. More information
  2793.          * about this can be found on the github page.
  2794.          *
  2795.          * @constructor
  2796.          * @extends {io.Transport.websocket}
  2797.          * @api public
  2798.          */
  2799.  
  2800.         function Flashsocket()
  2801.         {
  2802.             io.Transport.websocket.apply(this, arguments);
  2803.         };
  2804.  
  2805.         /**
  2806.          * Inherits from Transport.
  2807.          */
  2808.  
  2809.         io.util.inherit(Flashsocket, io.Transport.websocket);
  2810.  
  2811.         /**
  2812.          * Transport name
  2813.          *
  2814.          * @api public
  2815.          */
  2816.  
  2817.         Flashsocket.prototype.name = 'flashsocket';
  2818.  
  2819.         /**
  2820.          * Disconnect the established `FlashSocket` connection. This is done by adding a
  2821.          * new task to the FlashSocket. The rest will be handled off by the `WebSocket`
  2822.          * transport.
  2823.          *
  2824.          * @returns {Transport}
  2825.          * @api public
  2826.          */
  2827.  
  2828.         Flashsocket.prototype.open = function()
  2829.         {
  2830.             var self = this, args = arguments;
  2831.  
  2832.             WebSocket.__addTask(function()
  2833.             {
  2834.                 io.Transport.websocket.prototype.open.apply(self, args);
  2835.             });
  2836.             return this;
  2837.         };
  2838.  
  2839.         /**
  2840.          * Sends a message to the Socket.IO server. This is done by adding a new
  2841.          * task to the FlashSocket. The rest will be handled off by the `WebSocket`
  2842.          * transport.
  2843.          *
  2844.          * @returns {Transport}
  2845.          * @api public
  2846.          */
  2847.  
  2848.         Flashsocket.prototype.send = function()
  2849.         {
  2850.             var self = this, args = arguments;
  2851.             WebSocket.__addTask(function()
  2852.             {
  2853.                 io.Transport.websocket.prototype.send.apply(self, args);
  2854.             });
  2855.             return this;
  2856.         };
  2857.  
  2858.         /**
  2859.          * Disconnects the established `FlashSocket` connection.
  2860.          *
  2861.          * @returns {Transport}
  2862.          * @api public
  2863.          */
  2864.  
  2865.         Flashsocket.prototype.close = function()
  2866.         {
  2867.             WebSocket.__tasks.length = 0;
  2868.             io.Transport.websocket.prototype.close.call(this);
  2869.             return this;
  2870.         };
  2871.  
  2872.         /**
  2873.          * The WebSocket fall back needs to append the flash container to the body
  2874.          * element, so we need to make sure we have access to it. Or defer the call
  2875.          * until we are sure there is a body element.
  2876.          *
  2877.          * @param {Socket} socket The socket instance that needs a transport
  2878.          * @param {Function} fn The callback
  2879.          * @api private
  2880.          */
  2881.  
  2882.         Flashsocket.prototype.ready = function(socket, fn)
  2883.         {
  2884.             function init()
  2885.             {
  2886.                 var options = socket.options, port = options['flash policy port'], path = ['http' + (options.secure ? 's' : '') + ':/', options.host + ':' + options.port, options.resource, 'static/flashsocket', 'WebSocketMain' + (socket.isXDomain() ? 'Insecure' : '') + '.swf'];
  2887.  
  2888.                 // Only start downloading the swf file when the checked that this browser
  2889.                 // actually supports it
  2890.                 if (!Flashsocket.loaded)
  2891.                 {
  2892.                     if ( typeof WEB_SOCKET_SWF_LOCATION === 'undefined')
  2893.                     {
  2894.                         // Set the correct file based on the XDomain settings
  2895.                         WEB_SOCKET_SWF_LOCATION = path.join('/');
  2896.                     }
  2897.  
  2898.                     if (port !== 843)
  2899.                     {
  2900.                         WebSocket.loadFlashPolicyFile('xmlsocket://' + options.host + ':' + port);
  2901.                     }
  2902.  
  2903.                     WebSocket.__initialize();
  2904.                     Flashsocket.loaded = true;
  2905.                 }
  2906.  
  2907.                 fn.call(self);
  2908.             }
  2909.  
  2910.             var self = this;
  2911.             if (document.body)
  2912.                 return init();
  2913.  
  2914.             io.util.load(init);
  2915.         };
  2916.  
  2917.         /**
  2918.          * Check if the FlashSocket transport is supported as it requires that the Adobe
  2919.          * Flash Player plug-in version `10.0.0` or greater is installed. And also check if
  2920.          * the polyfill is correctly loaded.
  2921.          *
  2922.          * @returns {Boolean}
  2923.          * @api public
  2924.          */
  2925.  
  2926.         Flashsocket.check = function()
  2927.         {
  2928.             if ( typeof WebSocket == 'undefined' || !('__initialize' in WebSocket) || !swfobject)
  2929.                 return false;
  2930.  
  2931.             return swfobject.getFlashPlayerVersion().major >= 10;
  2932.         };
  2933.  
  2934.         /**
  2935.          * Check if the FlashSocket transport can be used as cross domain / cross origin
  2936.          * transport. Because we can't see which type (secure or insecure) of .swf is used
  2937.          * we will just return true.
  2938.          *
  2939.          * @returns {Boolean}
  2940.          * @api public
  2941.          */
  2942.  
  2943.         Flashsocket.xdomainCheck = function()
  2944.         {
  2945.             return true;
  2946.         };
  2947.  
  2948.         /**
  2949.          * Disable AUTO_INITIALIZATION
  2950.          */
  2951.  
  2952.         if ( typeof window != 'undefined')
  2953.         {
  2954.             WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
  2955.         }
  2956.  
  2957.         /**
  2958.          * Add the transport to your public io.transports array.
  2959.          *
  2960.          * @api private
  2961.          */
  2962.  
  2963.         io.transports.push('flashsocket');
  2964.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  2965.     /*  SWFObject v2.2 <http://code.google.com/p/swfobject/>
  2966.      is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
  2967.      */
  2968.     if ('undefined' != typeof window)
  2969.     {
  2970.         var swfobject = function()
  2971.         {
  2972.             var D = "undefined", r = "object", S = "Shockwave Flash", W = "ShockwaveFlash.ShockwaveFlash", q = "application/x-shockwave-flash", R = "SWFObjectExprInst", x = "onreadystatechange", O = window, j = document, t = navigator, T = false, U = [h], o = [], N = [], I = [], l, Q, E, B, J = false, a = false, n, G, m = true, M = function()
  2973.             {
  2974.                 var aa = typeof j.getElementById != D && typeof j.getElementsByTagName != D && typeof j.createElement != D, ah = t.userAgent.toLowerCase(), Y = t.platform.toLowerCase(), ae = Y ? /win/.test(Y) : /win/.test(ah), ac = Y ? /mac/.test(Y) : /mac/.test(ah), af = /webkit/.test(ah) ? parseFloat(ah.replace(/^.*webkit\/(\d+(\.\d+)?).*$/, "$1")) : false, X = !+"\v1", ag = [0, 0, 0], ab = null;
  2975.                 if ( typeof t.plugins != D && typeof t.plugins[S] == r)
  2976.                 {
  2977.                     ab = t.plugins[S].description;
  2978.                     if (ab && !( typeof t.mimeTypes != D && t.mimeTypes[q] && !t.mimeTypes[q].enabledPlugin))
  2979.                     {
  2980.                         T = true;
  2981.                         X = false;
  2982.                         ab = ab.replace(/^.*\s+(\S+\s+\S+$)/, "$1");
  2983.                         ag[0] = parseInt(ab.replace(/^(.*)\..*$/, "$1"), 10);
  2984.                         ag[1] = parseInt(ab.replace(/^.*\.(.*)\s.*$/, "$1"), 10);
  2985.                         ag[2] = /[a-zA-Z]/.test(ab) ? parseInt(ab.replace(/^.*[a-zA-Z]+(.*)$/, "$1"), 10) : 0;
  2986.                     }
  2987.                 }
  2988.                 else
  2989.                 {
  2990.                     if ( typeof O[(['Active'].concat('Object').join('X'))] != D)
  2991.                     {
  2992.                         try
  2993.                         {
  2994.                             var ad = new window[(['Active'].concat('Object').join('X'))](W);
  2995.                             if (ad)
  2996.                             {
  2997.                                 ab = ad.GetVariable("$version");
  2998.                                 if (ab)
  2999.                                 {
  3000.                                     X = true;
  3001.                                     ab = ab.split(" ")[1].split(",");
  3002.                                     ag = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)];
  3003.                                 }
  3004.                             }
  3005.                         }
  3006.                         catch(Z)
  3007.                         {
  3008.                         }
  3009.                     }
  3010.                 }
  3011.                 return {
  3012.                     w3 : aa,
  3013.                     pv : ag,
  3014.                     wk : af,
  3015.                     ie : X,
  3016.                     win : ae,
  3017.                     mac : ac
  3018.                 };
  3019.             }(), k = function()
  3020.             {
  3021.                 if (!M.w3)
  3022.                 {
  3023.                     return;
  3024.                 }
  3025.                 if (( typeof j.readyState != D && j.readyState == "complete") || ( typeof j.readyState == D && (j.getElementsByTagName("body")[0] || j.body)))
  3026.                 {
  3027.                     f();
  3028.                 }
  3029.                 if (!J)
  3030.                 {
  3031.                     if ( typeof j.addEventListener != D)
  3032.                     {
  3033.                         j.addEventListener("DOMContentLoaded", f, false);
  3034.                     }
  3035.                     if (M.ie && M.win)
  3036.                     {
  3037.                         j.attachEvent(x, function()
  3038.                         {
  3039.                             if (j.readyState == "complete")
  3040.                             {
  3041.                                 j.detachEvent(x, arguments.callee);
  3042.                                 f();
  3043.                             }
  3044.                         });
  3045.                         if (O == top)
  3046.                         {
  3047.                             (function()
  3048.                             {
  3049.                                 if (J)
  3050.                                 {
  3051.                                     return;
  3052.                                 }
  3053.                                 try
  3054.                                 {
  3055.                                     j.documentElement.doScroll("left");
  3056.                                 }
  3057.                                 catch(X)
  3058.                                 {
  3059.                                     setTimeout(arguments.callee, 0);
  3060.                                     return;
  3061.                                 }
  3062.                                 f();
  3063.                             })();
  3064.                         }
  3065.                     }
  3066.                     if (M.wk)
  3067.                     {
  3068.                         (function()
  3069.                         {
  3070.                             if (J)
  3071.                             {
  3072.                                 return;
  3073.                             }
  3074.                             if (!/loaded|complete/.test(j.readyState))
  3075.                             {
  3076.                                 setTimeout(arguments.callee, 0);
  3077.                                 return;
  3078.                             }
  3079.                             f();
  3080.                         })();
  3081.                     }
  3082.                     s(f);
  3083.                 }
  3084.             }();
  3085.             function f()
  3086.             {
  3087.                 if (J)
  3088.                 {
  3089.                     return;
  3090.                 }
  3091.                 try
  3092.                 {
  3093.                     var Z = j.getElementsByTagName("body")[0].appendChild(C("span"));
  3094.                     Z.parentNode.removeChild(Z);
  3095.                 }
  3096.                 catch(aa)
  3097.                 {
  3098.                     return;
  3099.                 }
  3100.                 J = true;
  3101.                 var X = U.length;
  3102.                 for (var Y = 0; Y < X; Y++)
  3103.                 {
  3104.                     U[Y]();
  3105.                 }
  3106.             }
  3107.  
  3108.             function K(X)
  3109.             {
  3110.                 if (J)
  3111.                 {
  3112.                     X();
  3113.                 }
  3114.                 else
  3115.                 {
  3116.                     U[U.length] = X;
  3117.                 }
  3118.             }
  3119.  
  3120.             function s(Y)
  3121.             {
  3122.                 if ( typeof O.addEventListener != D)
  3123.                 {
  3124.                     O.addEventListener("load", Y, false);
  3125.                 }
  3126.                 else
  3127.                 {
  3128.                     if ( typeof j.addEventListener != D)
  3129.                     {
  3130.                         j.addEventListener("load", Y, false);
  3131.                     }
  3132.                     else
  3133.                     {
  3134.                         if ( typeof O.attachEvent != D)
  3135.                         {
  3136.                             i(O, "onload", Y);
  3137.                         }
  3138.                         else
  3139.                         {
  3140.                             if ( typeof O.onload == "function")
  3141.                             {
  3142.                                 var X = O.onload;
  3143.                                 O.onload = function()
  3144.                                 {
  3145.                                     X();
  3146.                                     Y();
  3147.                                 };
  3148.                             }
  3149.                             else
  3150.                             {
  3151.                                 O.onload = Y;
  3152.                             }
  3153.                         }
  3154.                     }
  3155.                 }
  3156.             }
  3157.  
  3158.             function h()
  3159.             {
  3160.                 if (T)
  3161.                 {
  3162.                     V();
  3163.                 }
  3164.                 else
  3165.                 {
  3166.                     H();
  3167.                 }
  3168.             }
  3169.  
  3170.             function V()
  3171.             {
  3172.                 var X = j.getElementsByTagName("body")[0];
  3173.                 var aa = C(r);
  3174.                 aa.setAttribute("type", q);
  3175.                 var Z = X.appendChild(aa);
  3176.                 if (Z)
  3177.                 {
  3178.                     var Y = 0;
  3179.                     (function()
  3180.                     {
  3181.                         if ( typeof Z.GetVariable != D)
  3182.                         {
  3183.                             var ab = Z.GetVariable("$version");
  3184.                             if (ab)
  3185.                             {
  3186.                                 ab = ab.split(" ")[1].split(",");
  3187.                                 M.pv = [parseInt(ab[0], 10), parseInt(ab[1], 10), parseInt(ab[2], 10)];
  3188.                             }
  3189.                         }
  3190.                         else
  3191.                         {
  3192.                             if (Y < 10)
  3193.                             {
  3194.                                 Y++;
  3195.                                 setTimeout(arguments.callee, 10);
  3196.                                 return;
  3197.                             }
  3198.                         }
  3199.                         X.removeChild(aa);
  3200.                         Z = null;
  3201.                         H();
  3202.                     })();
  3203.                 }
  3204.                 else
  3205.                 {
  3206.                     H();
  3207.                 }
  3208.             }
  3209.  
  3210.             function H()
  3211.             {
  3212.                 var ag = o.length;
  3213.                 if (ag > 0)
  3214.                 {
  3215.                     for (var af = 0; af < ag; af++)
  3216.                     {
  3217.                         var Y = o[af].id;
  3218.                         var ab = o[af].callbackFn;
  3219.                         var aa =
  3220.                         {
  3221.                             success : false,
  3222.                             id : Y
  3223.                         };
  3224.                         if (M.pv[0] > 0)
  3225.                         {
  3226.                             var ae = c(Y);
  3227.                             if (ae)
  3228.                             {
  3229.                                 if (F(o[af].swfVersion) && !(M.wk && M.wk < 312))
  3230.                                 {
  3231.                                     w(Y, true);
  3232.                                     if (ab)
  3233.                                     {
  3234.                                         aa.success = true;
  3235.                                         aa.ref = z(Y);
  3236.                                         ab(aa);
  3237.                                     }
  3238.                                 }
  3239.                                 else
  3240.                                 {
  3241.                                     if (o[af].expressInstall && A())
  3242.                                     {
  3243.                                         var ai =
  3244.                                         {
  3245.                                         };
  3246.                                         ai.data = o[af].expressInstall;
  3247.                                         ai.width = ae.getAttribute("width") || "0";
  3248.                                         ai.height = ae.getAttribute("height") || "0";
  3249.                                         if (ae.getAttribute("class"))
  3250.                                         {
  3251.                                             ai.styleclass = ae.getAttribute("class");
  3252.                                         }
  3253.                                         if (ae.getAttribute("align"))
  3254.                                         {
  3255.                                             ai.align = ae.getAttribute("align");
  3256.                                         }
  3257.                                         var ah =
  3258.                                         {
  3259.                                         };
  3260.                                         var X = ae.getElementsByTagName("param");
  3261.                                         var ac = X.length;
  3262.                                         for (var ad = 0; ad < ac; ad++)
  3263.                                         {
  3264.                                             if (X[ad].getAttribute("name").toLowerCase() != "movie")
  3265.                                             {
  3266.                                                 ah[X[ad].getAttribute("name")] = X[ad].getAttribute("value");
  3267.                                             }
  3268.                                         }
  3269.                                         P(ai, ah, Y, ab);
  3270.                                     }
  3271.                                     else
  3272.                                     {
  3273.                                         p(ae);
  3274.                                         if (ab)
  3275.                                         {
  3276.                                             ab(aa);
  3277.                                         }
  3278.                                     }
  3279.                                 }
  3280.                             }
  3281.                         }
  3282.                         else
  3283.                         {
  3284.                             w(Y, true);
  3285.                             if (ab)
  3286.                             {
  3287.                                 var Z = z(Y);
  3288.                                 if (Z && typeof Z.SetVariable != D)
  3289.                                 {
  3290.                                     aa.success = true;
  3291.                                     aa.ref = Z;
  3292.                                 }
  3293.                                 ab(aa);
  3294.                             }
  3295.                         }
  3296.                     }
  3297.                 }
  3298.             }
  3299.  
  3300.             function z(aa)
  3301.             {
  3302.                 var X = null;
  3303.                 var Y = c(aa);
  3304.                 if (Y && Y.nodeName == "OBJECT")
  3305.                 {
  3306.                     if ( typeof Y.SetVariable != D)
  3307.                     {
  3308.                         X = Y;
  3309.                     }
  3310.                     else
  3311.                     {
  3312.                         var Z = Y.getElementsByTagName(r)[0];
  3313.                         if (Z)
  3314.                         {
  3315.                             X = Z;
  3316.                         }
  3317.                     }
  3318.                 }
  3319.                 return X;
  3320.             }
  3321.  
  3322.             function A()
  3323.             {
  3324.                 return !a && F("6.0.65") && (M.win || M.mac) && !(M.wk && M.wk < 312);
  3325.             }
  3326.  
  3327.             function P(aa, ab, X, Z)
  3328.             {
  3329.                 a = true;
  3330.                 E = Z || null;
  3331.                 B =
  3332.                 {
  3333.                     success : false,
  3334.                     id : X
  3335.                 };
  3336.                 var ae = c(X);
  3337.                 if (ae)
  3338.                 {
  3339.                     if (ae.nodeName == "OBJECT")
  3340.                     {
  3341.                         l = g(ae);
  3342.                         Q = null;
  3343.                     }
  3344.                     else
  3345.                     {
  3346.                         l = ae;
  3347.                         Q = X;
  3348.                     }
  3349.                     aa.id = R;
  3350.                     if ( typeof aa.width == D || (!/%$/.test(aa.width) && parseInt(aa.width, 10) < 310))
  3351.                     {
  3352.                         aa.width = "310";
  3353.                     }
  3354.                     if ( typeof aa.height == D || (!/%$/.test(aa.height) && parseInt(aa.height, 10) < 137))
  3355.                     {
  3356.                         aa.height = "137";
  3357.                     }
  3358.                     j.title = j.title.slice(0, 47) + " - Flash Player Installation";
  3359.                     var ad = M.ie && M.win ? (['Active'].concat('').join('X')) : "PlugIn", ac = "MMredirectURL=" + O.location.toString().replace(/&/g, "%26") + "&MMplayerType=" + ad + "&MMdoctitle=" + j.title;
  3360.                     if ( typeof ab.flashvars != D)
  3361.                     {
  3362.                         ab.flashvars += "&" + ac;
  3363.                     }
  3364.                     else
  3365.                     {
  3366.                         ab.flashvars = ac;
  3367.                     }
  3368.                     if (M.ie && M.win && ae.readyState != 4)
  3369.                     {
  3370.                         var Y = C("div");
  3371.                         X += "SWFObjectNew";
  3372.                         Y.setAttribute("id", X);
  3373.                         ae.parentNode.insertBefore(Y, ae);
  3374.                         ae.style.display = "none";
  3375.                         (function()
  3376.                         {
  3377.                             if (ae.readyState == 4)
  3378.                             {
  3379.                                 ae.parentNode.removeChild(ae);
  3380.                             }
  3381.                             else
  3382.                             {
  3383.                                 setTimeout(arguments.callee, 10);
  3384.                             }
  3385.                         })();
  3386.                     }
  3387.                     u(aa, ab, X);
  3388.                 }
  3389.             }
  3390.  
  3391.             function p(Y)
  3392.             {
  3393.                 if (M.ie && M.win && Y.readyState != 4)
  3394.                 {
  3395.                     var X = C("div");
  3396.                     Y.parentNode.insertBefore(X, Y);
  3397.                     X.parentNode.replaceChild(g(Y), X);
  3398.                     Y.style.display = "none";
  3399.                     (function()
  3400.                     {
  3401.                         if (Y.readyState == 4)
  3402.                         {
  3403.                             Y.parentNode.removeChild(Y);
  3404.                         }
  3405.                         else
  3406.                         {
  3407.                             setTimeout(arguments.callee, 10);
  3408.                         }
  3409.                     })();
  3410.                 }
  3411.                 else
  3412.                 {
  3413.                     Y.parentNode.replaceChild(g(Y), Y);
  3414.                 }
  3415.             }
  3416.  
  3417.             function g(ab)
  3418.             {
  3419.                 var aa = C("div");
  3420.                 if (M.win && M.ie)
  3421.                 {
  3422.                     aa.innerHTML = ab.innerHTML;
  3423.                 }
  3424.                 else
  3425.                 {
  3426.                     var Y = ab.getElementsByTagName(r)[0];
  3427.                     if (Y)
  3428.                     {
  3429.                         var ad = Y.childNodes;
  3430.                         if (ad)
  3431.                         {
  3432.                             var X = ad.length;
  3433.                             for (var Z = 0; Z < X; Z++)
  3434.                             {
  3435.                                 if (!(ad[Z].nodeType == 1 && ad[Z].nodeName == "PARAM") && !(ad[Z].nodeType == 8))
  3436.                                 {
  3437.                                     aa.appendChild(ad[Z].cloneNode(true));
  3438.                                 }
  3439.                             }
  3440.                         }
  3441.                     }
  3442.                 }
  3443.                 return aa;
  3444.             }
  3445.  
  3446.             function u(ai, ag, Y)
  3447.             {
  3448.                 var X, aa = c(Y);
  3449.                 if (M.wk && M.wk < 312)
  3450.                 {
  3451.                     return X;
  3452.                 }
  3453.                 if (aa)
  3454.                 {
  3455.                     if ( typeof ai.id == D)
  3456.                     {
  3457.                         ai.id = Y;
  3458.                     }
  3459.                     if (M.ie && M.win)
  3460.                     {
  3461.                         var ah = "";
  3462.                         for (var ae in ai)
  3463.                         {
  3464.                             if (ai[ae] != Object.prototype[ae])
  3465.                             {
  3466.                                 if (ae.toLowerCase() == "data")
  3467.                                 {
  3468.                                     ag.movie = ai[ae];
  3469.                                 }
  3470.                                 else
  3471.                                 {
  3472.                                     if (ae.toLowerCase() == "styleclass")
  3473.                                     {
  3474.                                         ah += ' class="' + ai[ae] + '"';
  3475.                                     }
  3476.                                     else
  3477.                                     {
  3478.                                         if (ae.toLowerCase() != "classid")
  3479.                                         {
  3480.                                             ah += " " + ae + '="' + ai[ae] + '"';
  3481.                                         }
  3482.                                     }
  3483.                                 }
  3484.                             }
  3485.                         }
  3486.                         var af = "";
  3487.                         for (var ad in ag)
  3488.                         {
  3489.                             if (ag[ad] != Object.prototype[ad])
  3490.                             {
  3491.                                 af += '<param name="' + ad + '" value="' + ag[ad] + '" />';
  3492.                             }
  3493.                         }
  3494.                         aa.outerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + ah + ">" + af + "</object>";
  3495.                         N[N.length] = ai.id;
  3496.                         X = c(ai.id);
  3497.                     }
  3498.                     else
  3499.                     {
  3500.                         var Z = C(r);
  3501.                         Z.setAttribute("type", q);
  3502.                         for (var ac in ai)
  3503.                         {
  3504.                             if (ai[ac] != Object.prototype[ac])
  3505.                             {
  3506.                                 if (ac.toLowerCase() == "styleclass")
  3507.                                 {
  3508.                                     Z.setAttribute("class", ai[ac]);
  3509.                                 }
  3510.                                 else
  3511.                                 {
  3512.                                     if (ac.toLowerCase() != "classid")
  3513.                                     {
  3514.                                         Z.setAttribute(ac, ai[ac]);
  3515.                                     }
  3516.                                 }
  3517.                             }
  3518.                         }
  3519.                         for (var ab in ag)
  3520.                         {
  3521.                             if (ag[ab] != Object.prototype[ab] && ab.toLowerCase() != "movie")
  3522.                             {
  3523.                                 e(Z, ab, ag[ab]);
  3524.                             }
  3525.                         }
  3526.                         aa.parentNode.replaceChild(Z, aa);
  3527.                         X = Z;
  3528.                     }
  3529.                 }
  3530.                 return X;
  3531.             }
  3532.  
  3533.             function e(Z, X, Y)
  3534.             {
  3535.                 var aa = C("param");
  3536.                 aa.setAttribute("name", X);
  3537.                 aa.setAttribute("value", Y);
  3538.                 Z.appendChild(aa);
  3539.             }
  3540.  
  3541.             function y(Y)
  3542.             {
  3543.                 var X = c(Y);
  3544.                 if (X && X.nodeName == "OBJECT")
  3545.                 {
  3546.                     if (M.ie && M.win)
  3547.                     {
  3548.                         X.style.display = "none";
  3549.                         (function()
  3550.                         {
  3551.                             if (X.readyState == 4)
  3552.                             {
  3553.                                 b(Y);
  3554.                             }
  3555.                             else
  3556.                             {
  3557.                                 setTimeout(arguments.callee, 10);
  3558.                             }
  3559.                         })();
  3560.                     }
  3561.                     else
  3562.                     {
  3563.                         X.parentNode.removeChild(X);
  3564.                     }
  3565.                 }
  3566.             }
  3567.  
  3568.             function b(Z)
  3569.             {
  3570.                 var Y = c(Z);
  3571.                 if (Y)
  3572.                 {
  3573.                     for (var X in Y)
  3574.                     {
  3575.                         if ( typeof Y[X] == "function")
  3576.                         {
  3577.                             Y[X] = null;
  3578.                         }
  3579.                     }
  3580.                     Y.parentNode.removeChild(Y);
  3581.                 }
  3582.             }
  3583.  
  3584.             function c(Z)
  3585.             {
  3586.                 var X = null;
  3587.                 try
  3588.                 {
  3589.                     X = j.getElementById(Z);
  3590.                 }
  3591.                 catch(Y)
  3592.                 {
  3593.                 }
  3594.                 return X;
  3595.             }
  3596.  
  3597.             function C(X)
  3598.             {
  3599.                 return j.createElement(X);
  3600.             }
  3601.  
  3602.             function i(Z, X, Y)
  3603.             {
  3604.                 Z.attachEvent(X, Y);
  3605.                 I[I.length] = [Z, X, Y];
  3606.             }
  3607.  
  3608.             function F(Z)
  3609.             {
  3610.                 var Y = M.pv, X = Z.split(".");
  3611.                 X[0] = parseInt(X[0], 10);
  3612.                 X[1] = parseInt(X[1], 10) || 0;
  3613.                 X[2] = parseInt(X[2], 10) || 0;
  3614.                 return (Y[0] > X[0] || (Y[0] == X[0] && Y[1] > X[1]) || (Y[0] == X[0] && Y[1] == X[1] && Y[2] >= X[2])) ? true : false;
  3615.             }
  3616.  
  3617.             function v(ac, Y, ad, ab)
  3618.             {
  3619.                 if (M.ie && M.mac)
  3620.                 {
  3621.                     return;
  3622.                 }
  3623.                 var aa = j.getElementsByTagName("head")[0];
  3624.                 if (!aa)
  3625.                 {
  3626.                     return;
  3627.                 }
  3628.                 var X = (ad && typeof ad == "string") ? ad : "screen";
  3629.                 if (ab)
  3630.                 {
  3631.                     n = null;
  3632.                     G = null;
  3633.                 }
  3634.                 if (!n || G != X)
  3635.                 {
  3636.                     var Z = C("style");
  3637.                     Z.setAttribute("type", "text/css");
  3638.                     Z.setAttribute("media", X);
  3639.                     n = aa.appendChild(Z);
  3640.                     if (M.ie && M.win && typeof j.styleSheets != D && j.styleSheets.length > 0)
  3641.                     {
  3642.                         n = j.styleSheets[j.styleSheets.length - 1];
  3643.                     }
  3644.                     G = X;
  3645.                 }
  3646.                 if (M.ie && M.win)
  3647.                 {
  3648.                     if (n && typeof n.addRule == r)
  3649.                     {
  3650.                         n.addRule(ac, Y);
  3651.                     }
  3652.                 }
  3653.                 else
  3654.                 {
  3655.                     if (n && typeof j.createTextNode != D)
  3656.                     {
  3657.                         n.appendChild(j.createTextNode(ac + " {" + Y + "}"));
  3658.                     }
  3659.                 }
  3660.             }
  3661.  
  3662.             function w(Z, X)
  3663.             {
  3664.                 if (!m)
  3665.                 {
  3666.                     return;
  3667.                 }
  3668.                 var Y = X ? "visible" : "hidden";
  3669.                 if (J && c(Z))
  3670.                 {
  3671.                     c(Z).style.visibility = Y;
  3672.                 }
  3673.                 else
  3674.                 {
  3675.                     v("#" + Z, "visibility:" + Y);
  3676.                 }
  3677.             }
  3678.  
  3679.             function L(Y)
  3680.             {
  3681.                 var Z = /[\\\"<>\.;]/;
  3682.                 var X = Z.exec(Y) != null;
  3683.                 return X && typeof encodeURIComponent != D ? encodeURIComponent(Y) : Y;
  3684.             }
  3685.  
  3686.             var d = function()
  3687.             {
  3688.                 if (M.ie && M.win)
  3689.                 {
  3690.                     window.attachEvent("onunload", function()
  3691.                     {
  3692.                         var ac = I.length;
  3693.                         for (var ab = 0; ab < ac; ab++)
  3694.                         {
  3695.                             I[ab][0].detachEvent(I[ab][1], I[ab][2]);
  3696.                         }
  3697.                         var Z = N.length;
  3698.                         for (var aa = 0; aa < Z; aa++)
  3699.                         {
  3700.                             y(N[aa]);
  3701.                         }
  3702.                         for (var Y in M)
  3703.                         {
  3704.                             M[Y] = null;
  3705.                         }
  3706.                         M = null;
  3707.                         for (var X in swfobject)
  3708.                         {
  3709.                             swfobject[X] = null;
  3710.                         }
  3711.                         swfobject = null;
  3712.                     });
  3713.                 }
  3714.             }();
  3715.             return {
  3716.                 registerObject : function(ab, X, aa, Z)
  3717.                 {
  3718.                     if (M.w3 && ab && X)
  3719.                     {
  3720.                         var Y =
  3721.                         {
  3722.                         };
  3723.                         Y.id = ab;
  3724.                         Y.swfVersion = X;
  3725.                         Y.expressInstall = aa;
  3726.                         Y.callbackFn = Z;
  3727.                         o[o.length] = Y;
  3728.                         w(ab, false);
  3729.                     }
  3730.                     else
  3731.                     {
  3732.                         if (Z)
  3733.                         {
  3734.                             Z(
  3735.                             {
  3736.                                 success : false,
  3737.                                 id : ab
  3738.                             });
  3739.                         }
  3740.                     }
  3741.                 },
  3742.                 getObjectById : function(X)
  3743.                 {
  3744.                     if (M.w3)
  3745.                     {
  3746.                         return z(X);
  3747.                     }
  3748.                 },
  3749.                 embedSWF : function(ab, ah, ae, ag, Y, aa, Z, ad, af, ac)
  3750.                 {
  3751.                     var X =
  3752.                     {
  3753.                         success : false,
  3754.                         id : ah
  3755.                     };
  3756.                     if (M.w3 && !(M.wk && M.wk < 312) && ab && ah && ae && ag && Y)
  3757.                     {
  3758.                         w(ah, false);
  3759.                         K(function()
  3760.                         {
  3761.                             ae += "";
  3762.                             ag += "";
  3763.                             var aj =
  3764.                             {
  3765.                             };
  3766.                             if (af && typeof af === r)
  3767.                             {
  3768.                                 for (var al in af)
  3769.                                 {
  3770.                                     aj[al] = af[al];
  3771.                                 }
  3772.                             }
  3773.                             aj.data = ab;
  3774.                             aj.width = ae;
  3775.                             aj.height = ag;
  3776.                             var am =
  3777.                             {
  3778.                             };
  3779.                             if (ad && typeof ad === r)
  3780.                             {
  3781.                                 for (var ak in ad)
  3782.                                 {
  3783.                                     am[ak] = ad[ak];
  3784.                                 }
  3785.                             }
  3786.                             if (Z && typeof Z === r)
  3787.                             {
  3788.                                 for (var ai in Z)
  3789.                                 {
  3790.                                     if ( typeof am.flashvars != D)
  3791.                                     {
  3792.                                         am.flashvars += "&" + ai + "=" + Z[ai];
  3793.                                     }
  3794.                                     else
  3795.                                     {
  3796.                                         am.flashvars = ai + "=" + Z[ai];
  3797.                                     }
  3798.                                 }
  3799.                             }
  3800.                             if (F(Y))
  3801.                             {
  3802.                                 var an = u(aj, am, ah);
  3803.                                 if (aj.id == ah)
  3804.                                 {
  3805.                                     w(ah, true);
  3806.                                 }
  3807.                                 X.success = true;
  3808.                                 X.ref = an;
  3809.                             }
  3810.                             else
  3811.                             {
  3812.                                 if (aa && A())
  3813.                                 {
  3814.                                     aj.data = aa;
  3815.                                     P(aj, am, ah, ac);
  3816.                                     return;
  3817.                                 }
  3818.                                 else
  3819.                                 {
  3820.                                     w(ah, true);
  3821.                                 }
  3822.                             }
  3823.                             if (ac)
  3824.                             {
  3825.                                 ac(X);
  3826.                             }
  3827.                         });
  3828.                     }
  3829.                     else
  3830.                     {
  3831.                         if (ac)
  3832.                         {
  3833.                             ac(X);
  3834.                         }
  3835.                     }
  3836.                 },
  3837.                 switchOffAutoHideShow : function()
  3838.                 {
  3839.                     m = false;
  3840.                 },
  3841.                 ua : M,
  3842.                 getFlashPlayerVersion : function()
  3843.                 {
  3844.                     return {
  3845.                         major : M.pv[0],
  3846.                         minor : M.pv[1],
  3847.                         release : M.pv[2]
  3848.                     };
  3849.                 },
  3850.                 hasFlashPlayerVersion : F,
  3851.                 createSWF : function(Z, Y, X)
  3852.                 {
  3853.                     if (M.w3)
  3854.                     {
  3855.                         return u(Z, Y, X);
  3856.                     }
  3857.                     else
  3858.                     {
  3859.                         return undefined;
  3860.                     }
  3861.                 },
  3862.                 showExpressInstall : function(Z, aa, X, Y)
  3863.                 {
  3864.                     if (M.w3 && A())
  3865.                     {
  3866.                         P(Z, aa, X, Y);
  3867.                     }
  3868.                 },
  3869.                 removeSWF : function(X)
  3870.                 {
  3871.                     if (M.w3)
  3872.                     {
  3873.                         y(X);
  3874.                     }
  3875.                 },
  3876.                 createCSS : function(aa, Z, Y, X)
  3877.                 {
  3878.                     if (M.w3)
  3879.                     {
  3880.                         v(aa, Z, Y, X);
  3881.                     }
  3882.                 },
  3883.                 addDomLoadEvent : K,
  3884.                 addLoadEvent : s,
  3885.                 getQueryParamValue : function(aa)
  3886.                 {
  3887.                     var Z = j.location.search || j.location.hash;
  3888.                     if (Z)
  3889.                     {
  3890.                         if (/\?/.test(Z))
  3891.                         {
  3892.                             Z = Z.split("?")[1];
  3893.                         }
  3894.                         if (aa == null)
  3895.                         {
  3896.                             return L(Z);
  3897.                         }
  3898.                         var Y = Z.split("&");
  3899.                         for (var X = 0; X < Y.length; X++)
  3900.                         {
  3901.                             if (Y[X].substring(0, Y[X].indexOf("=")) == aa)
  3902.                             {
  3903.                                 return L(Y[X].substring((Y[X].indexOf("=") + 1)));
  3904.                             }
  3905.                         }
  3906.                     }
  3907.                     return "";
  3908.                 },
  3909.                 expressInstallCallback : function()
  3910.                 {
  3911.                     if (a)
  3912.                     {
  3913.                         var X = c(R);
  3914.                         if (X && l)
  3915.                         {
  3916.                             X.parentNode.replaceChild(l, X);
  3917.                             if (Q)
  3918.                             {
  3919.                                 w(Q, true);
  3920.                                 if (M.ie && M.win)
  3921.                                 {
  3922.                                     l.style.display = "block";
  3923.                                 }
  3924.                             }
  3925.                             if (E)
  3926.                             {
  3927.                                 E(B);
  3928.                             }
  3929.                         }
  3930.                         a = false;
  3931.                     }
  3932.                 }
  3933.             };
  3934.         }();
  3935.     }
  3936.     // Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
  3937.     // License: New BSD License
  3938.     // Reference: http://dev.w3.org/html5/websockets/
  3939.     // Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol
  3940.  
  3941.     (function()
  3942.     {
  3943.  
  3944.         if ('undefined' == typeof window || window.WebSocket)
  3945.             return;
  3946.  
  3947.         var console = window.console;
  3948.         if (!console || !console.log || !console.error)
  3949.         {
  3950.             console =
  3951.             {
  3952.                 log : function()
  3953.                 {
  3954.                 },
  3955.                 error : function()
  3956.                 {
  3957.                 }
  3958.             };
  3959.         }
  3960.  
  3961.         if (!swfobject.hasFlashPlayerVersion("10.0.0"))
  3962.         {
  3963.             console.error("Flash Player >= 10.0.0 is required.");
  3964.             return;
  3965.         }
  3966.         if (location.protocol == "file:")
  3967.         {
  3968.             console.error("WARNING: web-socket-js doesn't work in file:///... URL " + "unless you set Flash Security Settings properly. " + "Open the page via Web server i.e. http://...");
  3969.         }
  3970.  
  3971.         /**
  3972.          * This class represents a faux web socket.
  3973.          * @param {string} url
  3974.          * @param {array or string} protocols
  3975.          * @param {string} proxyHost
  3976.          * @param {int} proxyPort
  3977.          * @param {string} headers
  3978.          */
  3979.         WebSocket = function(url, protocols, proxyHost, proxyPort, headers)
  3980.         {
  3981.             var self = this;
  3982.             self.__id = WebSocket.__nextId++;
  3983.             WebSocket.__instances[self.__id] = self;
  3984.             self.readyState = WebSocket.CONNECTING;
  3985.             self.bufferedAmount = 0;
  3986.             self.__events =
  3987.             {
  3988.             };
  3989.             if (!protocols)
  3990.             {
  3991.                 protocols = [];
  3992.             }
  3993.             else if ( typeof protocols == "string")
  3994.             {
  3995.                 protocols = [protocols];
  3996.             }
  3997.             // Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
  3998.             // Otherwise, when onopen fires immediately, onopen is called before it is set.
  3999.             setTimeout(function()
  4000.             {
  4001.                 WebSocket.__addTask(function()
  4002.                 {
  4003.                     WebSocket.__flash.create(self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
  4004.                 });
  4005.             }, 0);
  4006.         };
  4007.  
  4008.         /**
  4009.          * Send data to the web socket.
  4010.          * @param {string} data  The data to send to the socket.
  4011.          * @return {boolean}  True for success, false for failure.
  4012.          */
  4013.         WebSocket.prototype.send = function(data)
  4014.         {
  4015.             if (this.readyState == WebSocket.CONNECTING)
  4016.             {
  4017.                 throw "INVALID_STATE_ERR: Web Socket connection has not been established";
  4018.             }
  4019.             // We use encodeURIComponent() here, because FABridge doesn't work if
  4020.             // the argument includes some characters. We don't use escape() here
  4021.             // because of this:
  4022.             // https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
  4023.             // But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
  4024.             // preserve all Unicode characters either e.g. "\uffff" in Firefox.
  4025.             // Note by wtritch: Hopefully this will not be necessary using ExternalInterface.  Will require
  4026.             // additional testing.
  4027.             var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
  4028.             if (result < 0)
  4029.             {
  4030.                 // success
  4031.                 return true;
  4032.             }
  4033.             else
  4034.             {
  4035.                 this.bufferedAmount += result;
  4036.                 return false;
  4037.             }
  4038.         };
  4039.  
  4040.         /**
  4041.          * Close this web socket gracefully.
  4042.          */
  4043.         WebSocket.prototype.close = function()
  4044.         {
  4045.             if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING)
  4046.             {
  4047.                 return;
  4048.             }
  4049.             this.readyState = WebSocket.CLOSING;
  4050.             WebSocket.__flash.close(this.__id);
  4051.         };
  4052.  
  4053.         /**
  4054.          * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
  4055.          *
  4056.          * @param {string} type
  4057.          * @param {function} listener
  4058.          * @param {boolean} useCapture
  4059.          * @return void
  4060.          */
  4061.         WebSocket.prototype.addEventListener = function(type, listener, useCapture)
  4062.         {
  4063.             if (!( type in this.__events))
  4064.             {
  4065.                 this.__events[type] = [];
  4066.             }
  4067.             this.__events[type].push(listener);
  4068.         };
  4069.  
  4070.         /**
  4071.          * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
  4072.          *
  4073.          * @param {string} type
  4074.          * @param {function} listener
  4075.          * @param {boolean} useCapture
  4076.          * @return void
  4077.          */
  4078.         WebSocket.prototype.removeEventListener = function(type, listener, useCapture)
  4079.         {
  4080.             if (!( type in this.__events))
  4081.                 return;
  4082.             var events = this.__events[type];
  4083.             for (var i = events.length - 1; i >= 0; --i)
  4084.             {
  4085.                 if (events[i] === listener)
  4086.                 {
  4087.                     events.splice(i, 1);
  4088.                     break;
  4089.                 }
  4090.             }
  4091.         };
  4092.  
  4093.         /**
  4094.          * Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
  4095.          *
  4096.          * @param {Event} event
  4097.          * @return void
  4098.          */
  4099.         WebSocket.prototype.dispatchEvent = function(event)
  4100.         {
  4101.             var events = this.__events[event.type] || [];
  4102.             for (var i = 0; i < events.length; ++i)
  4103.             {
  4104.                 events[i](event);
  4105.             }
  4106.             var handler = this["on" + event.type];
  4107.             if (handler)
  4108.                 handler(event);
  4109.         };
  4110.  
  4111.         /**
  4112.          * Handles an event from Flash.
  4113.          * @param {Object} flashEvent
  4114.          */
  4115.         WebSocket.prototype.__handleEvent = function(flashEvent)
  4116.         {
  4117.             if ("readyState" in flashEvent)
  4118.             {
  4119.                 this.readyState = flashEvent.readyState;
  4120.             }
  4121.             if ("protocol" in flashEvent)
  4122.             {
  4123.                 this.protocol = flashEvent.protocol;
  4124.             }
  4125.  
  4126.             var jsEvent;
  4127.             if (flashEvent.type == "open" || flashEvent.type == "error")
  4128.             {
  4129.                 jsEvent = this.__createSimpleEvent(flashEvent.type);
  4130.             }
  4131.             else if (flashEvent.type == "close")
  4132.             {
  4133.                 // TODO implement jsEvent.wasClean
  4134.                 jsEvent = this.__createSimpleEvent("close");
  4135.             }
  4136.             else if (flashEvent.type == "message")
  4137.             {
  4138.                 var data = decodeURIComponent(flashEvent.message);
  4139.                 jsEvent = this.__createMessageEvent("message", data);
  4140.             }
  4141.             else
  4142.             {
  4143.                 throw "unknown event type: " + flashEvent.type;
  4144.             }
  4145.  
  4146.             this.dispatchEvent(jsEvent);
  4147.         };
  4148.  
  4149.         WebSocket.prototype.__createSimpleEvent = function(type)
  4150.         {
  4151.             if (document.createEvent && window.Event)
  4152.             {
  4153.                 var event = document.createEvent("Event");
  4154.                 event.initEvent(type, false, false);
  4155.                 return event;
  4156.             }
  4157.             else
  4158.             {
  4159.                 return
  4160.                 {
  4161.                     type : type,
  4162.                     bubbles : false,
  4163.                     cancelable : false
  4164.                 };
  4165.             }
  4166.         };
  4167.  
  4168.         WebSocket.prototype.__createMessageEvent = function(type, data)
  4169.         {
  4170.             if (document.createEvent && window.MessageEvent && !window.opera)
  4171.             {
  4172.                 var event = document.createEvent("MessageEvent");
  4173.                 event.initMessageEvent("message", false, false, data, null, null, window, null);
  4174.                 return event;
  4175.             }
  4176.             else
  4177.             {
  4178.                 // IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
  4179.                 return
  4180.                 {
  4181.                     type : type,
  4182.                     data : data,
  4183.                     bubbles : false,
  4184.                     cancelable : false
  4185.                 };
  4186.             }
  4187.         };
  4188.  
  4189.         /**
  4190.          * Define the WebSocket readyState enumeration.
  4191.          */
  4192.         WebSocket.CONNECTING = 0;
  4193.         WebSocket.OPEN = 1;
  4194.         WebSocket.CLOSING = 2;
  4195.         WebSocket.CLOSED = 3;
  4196.  
  4197.         WebSocket.__flash = null;
  4198.         WebSocket.__instances =
  4199.         {
  4200.         };
  4201.         WebSocket.__tasks = [];
  4202.         WebSocket.__nextId = 0;
  4203.  
  4204.         /**
  4205.          * Load a new flash security policy file.
  4206.          * @param {string} url
  4207.          */
  4208.         WebSocket.loadFlashPolicyFile = function(url)
  4209.         {
  4210.             WebSocket.__addTask(function()
  4211.             {
  4212.                 WebSocket.__flash.loadManualPolicyFile(url);
  4213.             });
  4214.         };
  4215.  
  4216.         /**
  4217.          * Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
  4218.          */
  4219.         WebSocket.__initialize = function()
  4220.         {
  4221.             if (WebSocket.__flash)
  4222.                 return;
  4223.  
  4224.             if (WebSocket.__swfLocation)
  4225.             {
  4226.                 // For backword compatibility.
  4227.                 window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
  4228.             }
  4229.             if (!window.WEB_SOCKET_SWF_LOCATION)
  4230.             {
  4231.                 console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
  4232.                 return;
  4233.             }
  4234.             var container = document.createElement("div");
  4235.             container.id = "webSocketContainer";
  4236.             // Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
  4237.             // Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
  4238.             // But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
  4239.             // Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
  4240.             // the best we can do as far as we know now.
  4241.             container.style.position = "absolute";
  4242.             if (WebSocket.__isFlashLite())
  4243.             {
  4244.                 container.style.left = "0px";
  4245.                 container.style.top = "0px";
  4246.             }
  4247.             else
  4248.             {
  4249.                 container.style.left = "-100px";
  4250.                 container.style.top = "-100px";
  4251.             }
  4252.             var holder = document.createElement("div");
  4253.             holder.id = "webSocketFlash";
  4254.             container.appendChild(holder);
  4255.             document.body.appendChild(container);
  4256.             // See this article for hasPriority:
  4257.             // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
  4258.             swfobject.embedSWF(WEB_SOCKET_SWF_LOCATION, "webSocketFlash", "1"/* width */, "1"/* height */, "10.0.0"/* SWF version */, null, null,
  4259.             {
  4260.                 hasPriority : true,
  4261.                 swliveconnect : true,
  4262.                 allowScriptAccess : "always"
  4263.             }, null, function(e)
  4264.             {
  4265.                 if (!e.success)
  4266.                 {
  4267.                     console.error("[WebSocket] swfobject.embedSWF failed");
  4268.                 }
  4269.             });
  4270.         };
  4271.  
  4272.         /**
  4273.          * Called by Flash to notify JS that it's fully loaded and ready
  4274.          * for communication.
  4275.          */
  4276.         WebSocket.__onFlashInitialized = function()
  4277.         {
  4278.             // We need to set a timeout here to avoid round-trip calls
  4279.             // to flash during the initialization process.
  4280.             setTimeout(function()
  4281.             {
  4282.                 WebSocket.__flash = document.getElementById("webSocketFlash");
  4283.                 WebSocket.__flash.setCallerUrl(location.href);
  4284.                 WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
  4285.                 for (var i = 0; i < WebSocket.__tasks.length; ++i)
  4286.                 {
  4287.                     WebSocket.__tasks[i]();
  4288.                 }
  4289.                 WebSocket.__tasks = [];
  4290.             }, 0);
  4291.         };
  4292.  
  4293.         /**
  4294.          * Called by Flash to notify WebSockets events are fired.
  4295.          */
  4296.         WebSocket.__onFlashEvent = function()
  4297.         {
  4298.             setTimeout(function()
  4299.             {
  4300.                 try
  4301.                 {
  4302.                     // Gets events using receiveEvents() instead of getting it from event object
  4303.                     // of Flash event. This is to make sure to keep message order.
  4304.                     // It seems sometimes Flash events don't arrive in the same order as they are sent.
  4305.                     var events = WebSocket.__flash.receiveEvents();
  4306.                     for (var i = 0; i < events.length; ++i)
  4307.                     {
  4308.                         WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
  4309.                     }
  4310.                 }
  4311.                 catch (e)
  4312.                 {
  4313.                     console.error(e);
  4314.                 }
  4315.             }, 0);
  4316.             return true;
  4317.         };
  4318.  
  4319.         // Called by Flash.
  4320.         WebSocket.__log = function(message)
  4321.         {
  4322.             console.log(decodeURIComponent(message));
  4323.         };
  4324.  
  4325.         // Called by Flash.
  4326.         WebSocket.__error = function(message)
  4327.         {
  4328.             console.error(decodeURIComponent(message));
  4329.         };
  4330.  
  4331.         WebSocket.__addTask = function(task)
  4332.         {
  4333.             if (WebSocket.__flash)
  4334.             {
  4335.                 task();
  4336.             }
  4337.             else
  4338.             {
  4339.                 WebSocket.__tasks.push(task);
  4340.             }
  4341.         };
  4342.  
  4343.         /**
  4344.          * Test if the browser is running flash lite.
  4345.          * @return {boolean} True if flash lite is running, false otherwise.
  4346.          */
  4347.         WebSocket.__isFlashLite = function()
  4348.         {
  4349.             if (!window.navigator || !window.navigator.mimeTypes)
  4350.             {
  4351.                 return false;
  4352.             }
  4353.             var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
  4354.             if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename)
  4355.             {
  4356.                 return false;
  4357.             }
  4358.             return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
  4359.         };
  4360.  
  4361.         if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION)
  4362.         {
  4363.             if (window.addEventListener)
  4364.             {
  4365.                 window.addEventListener("load", function()
  4366.                 {
  4367.                     WebSocket.__initialize();
  4368.                 }, false);
  4369.             }
  4370.             else
  4371.             {
  4372.                 window.attachEvent("onload", function()
  4373.                 {
  4374.                     WebSocket.__initialize();
  4375.                 });
  4376.             }
  4377.         }
  4378.  
  4379.     })();
  4380.  
  4381.     /**
  4382.      * socket.io
  4383.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  4384.      * MIT Licensed
  4385.      */
  4386.  
  4387.     (function(exports, io, global)
  4388.     {
  4389.  
  4390.         /**
  4391.          * Expose constructor.
  4392.          *
  4393.          * @api public
  4394.          */
  4395.  
  4396.         exports.XHR = XHR;
  4397.  
  4398.         /**
  4399.          * XHR constructor
  4400.          *
  4401.          * @costructor
  4402.          * @api public
  4403.          */
  4404.  
  4405.         function XHR(socket)
  4406.         {
  4407.             if (!socket)
  4408.                 return;
  4409.  
  4410.             io.Transport.apply(this, arguments);
  4411.             this.sendBuffer = [];
  4412.         };
  4413.  
  4414.         /**
  4415.          * Inherits from Transport.
  4416.          */
  4417.  
  4418.         io.util.inherit(XHR, io.Transport);
  4419.  
  4420.         /**
  4421.          * Establish a connection
  4422.          *
  4423.          * @returns {Transport}
  4424.          * @api public
  4425.          */
  4426.  
  4427.         XHR.prototype.open = function()
  4428.         {
  4429.             this.socket.setBuffer(false);
  4430.             this.onOpen();
  4431.             this.get();
  4432.  
  4433.             // we need to make sure the request succeeds since we have no indication
  4434.             // whether the request opened or not until it succeeded.
  4435.             this.setCloseTimeout();
  4436.  
  4437.             return this;
  4438.         };
  4439.  
  4440.         /**
  4441.          * Check if we need to send data to the Socket.IO server, if we have data in our
  4442.          * buffer we encode it and forward it to the `post` method.
  4443.          *
  4444.          * @api private
  4445.          */
  4446.  
  4447.         XHR.prototype.payload = function(payload)
  4448.         {
  4449.             var msgs = [];
  4450.  
  4451.             for (var i = 0, l = payload.length; i < l; i++)
  4452.             {
  4453.                 msgs.push(io.parser.encodePacket(payload[i]));
  4454.             }
  4455.  
  4456.             this.send(io.parser.encodePayload(msgs));
  4457.         };
  4458.  
  4459.         /**
  4460.          * Send data to the Socket.IO server.
  4461.          *
  4462.          * @param data The message
  4463.          * @returns {Transport}
  4464.          * @api public
  4465.          */
  4466.  
  4467.         XHR.prototype.send = function(data)
  4468.         {
  4469.             this.post(data);
  4470.             return this;
  4471.         };
  4472.  
  4473.         /**
  4474.          * Posts a encoded message to the Socket.IO server.
  4475.          *
  4476.          * @param {String} data A encoded message.
  4477.          * @api private
  4478.          */
  4479.  
  4480.         function empty()
  4481.         {
  4482.         };
  4483.  
  4484.         XHR.prototype.post = function(data)
  4485.         {
  4486.             var self = this;
  4487.             this.socket.setBuffer(true);
  4488.  
  4489.             function stateChange()
  4490.             {
  4491.                 if (this.readyState == 4)
  4492.                 {
  4493.                     this.onreadystatechange = empty;
  4494.                     self.posting = false;
  4495.  
  4496.                     if (this.status == 200)
  4497.                     {
  4498.                         self.socket.setBuffer(false);
  4499.                     }
  4500.                     else
  4501.                     {
  4502.                         self.onClose();
  4503.                     }
  4504.                 }
  4505.             }
  4506.  
  4507.             function onload()
  4508.             {
  4509.                 this.onload = empty;
  4510.                 self.socket.setBuffer(false);
  4511.             };
  4512.  
  4513.             this.sendXHR = this.request('POST');
  4514.  
  4515.             if (global.XDomainRequest && this.sendXHR instanceof XDomainRequest)
  4516.             {
  4517.                 this.sendXHR.onload = this.sendXHR.onerror = onload;
  4518.             }
  4519.             else
  4520.             {
  4521.                 this.sendXHR.onreadystatechange = stateChange;
  4522.             }
  4523.  
  4524.             this.sendXHR.send(data);
  4525.         };
  4526.  
  4527.         /**
  4528.          * Disconnects the established `XHR` connection.
  4529.          *
  4530.          * @returns {Transport}
  4531.          * @api public
  4532.          */
  4533.  
  4534.         XHR.prototype.close = function()
  4535.         {
  4536.             this.onClose();
  4537.             return this;
  4538.         };
  4539.  
  4540.         /**
  4541.          * Generates a configured XHR request
  4542.          *
  4543.          * @param {String} url The url that needs to be requested.
  4544.          * @param {String} method The method the request should use.
  4545.          * @returns {XMLHttpRequest}
  4546.          * @api private
  4547.          */
  4548.  
  4549.         XHR.prototype.request = function(method)
  4550.         {
  4551.             var req = io.util.request(this.socket.isXDomain()), query = io.util.query(this.socket.options.query, 't=' + +new Date);
  4552.  
  4553.             req.open(method || 'GET', this.prepareUrl() + query, true);
  4554.  
  4555.             if (method == 'POST')
  4556.             {
  4557.                 try
  4558.                 {
  4559.                     if (req.setRequestHeader)
  4560.                     {
  4561.                         req.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
  4562.                     }
  4563.                     else
  4564.                     {
  4565.                         // XDomainRequest
  4566.                         req.contentType = 'text/plain';
  4567.                     }
  4568.                 }
  4569.                 catch (e)
  4570.                 {
  4571.                 }
  4572.             }
  4573.  
  4574.             return req;
  4575.         };
  4576.  
  4577.         /**
  4578.          * Returns the scheme to use for the transport URLs.
  4579.          *
  4580.          * @api private
  4581.          */
  4582.  
  4583.         XHR.prototype.scheme = function()
  4584.         {
  4585.             return this.socket.options.secure ? 'https' : 'http';
  4586.         };
  4587.  
  4588.         /**
  4589.          * Check if the XHR transports are supported
  4590.          *
  4591.          * @param {Boolean} xdomain Check if we support cross domain requests.
  4592.          * @returns {Boolean}
  4593.          * @api public
  4594.          */
  4595.  
  4596.         XHR.check = function(socket, xdomain)
  4597.         {
  4598.             try
  4599.             {
  4600.                 var request = io.util.request(xdomain), usesXDomReq = (global.XDomainRequest && request instanceof XDomainRequest), socketProtocol = (socket && socket.options && socket.options.secure ? 'https:' : 'http:'), isXProtocol = (global.location && socketProtocol != global.location.protocol);
  4601.                 if (request && !(usesXDomReq && isXProtocol))
  4602.                 {
  4603.                     return true;
  4604.                 }
  4605.             }
  4606.             catch(e)
  4607.             {
  4608.             }
  4609.  
  4610.             return false;
  4611.         };
  4612.  
  4613.         /**
  4614.          * Check if the XHR transport supports cross domain requests.
  4615.          *
  4616.          * @returns {Boolean}
  4617.          * @api public
  4618.          */
  4619.  
  4620.         XHR.xdomainCheck = function(socket)
  4621.         {
  4622.             return XHR.check(socket, true);
  4623.         };
  4624.  
  4625.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports, this);
  4626.     /**
  4627.      * socket.io
  4628.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  4629.      * MIT Licensed
  4630.      */
  4631.  
  4632.     (function(exports, io)
  4633.     {
  4634.  
  4635.         /**
  4636.          * Expose constructor.
  4637.          */
  4638.  
  4639.         exports.htmlfile = HTMLFile;
  4640.  
  4641.         /**
  4642.          * The HTMLFile transport creates a `forever iframe` based transport
  4643.          * for Internet Explorer. Regular forever iframe implementations will
  4644.          * continuously trigger the browsers buzy indicators. If the forever iframe
  4645.          * is created inside a `htmlfile` these indicators will not be trigged.
  4646.          *
  4647.          * @constructor
  4648.          * @extends {io.Transport.XHR}
  4649.          * @api public
  4650.          */
  4651.  
  4652.         function HTMLFile(socket)
  4653.         {
  4654.             io.Transport.XHR.apply(this, arguments);
  4655.         };
  4656.  
  4657.         /**
  4658.          * Inherits from XHR transport.
  4659.          */
  4660.  
  4661.         io.util.inherit(HTMLFile, io.Transport.XHR);
  4662.  
  4663.         /**
  4664.          * Transport name
  4665.          *
  4666.          * @api public
  4667.          */
  4668.  
  4669.         HTMLFile.prototype.name = 'htmlfile';
  4670.  
  4671.         /**
  4672.          * Creates a new Ac...eX `htmlfile` with a forever loading iframe
  4673.          * that can be used to listen to messages. Inside the generated
  4674.          * `htmlfile` a reference will be made to the HTMLFile transport.
  4675.          *
  4676.          * @api private
  4677.          */
  4678.  
  4679.         HTMLFile.prototype.get = function()
  4680.         {
  4681.             this.doc = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
  4682.             this.doc.open();
  4683.             this.doc.write('<html></html>');
  4684.             this.doc.close();
  4685.             this.doc.parentWindow.s = this;
  4686.  
  4687.             var iframeC = this.doc.createElement('div');
  4688.             iframeC.className = 'socketio';
  4689.  
  4690.             this.doc.body.appendChild(iframeC);
  4691.             this.iframe = this.doc.createElement('iframe');
  4692.  
  4693.             iframeC.appendChild(this.iframe);
  4694.  
  4695.             var self = this, query = io.util.query(this.socket.options.query, 't=' + +new Date);
  4696.  
  4697.             this.iframe.src = this.prepareUrl() + query;
  4698.  
  4699.             io.util.on(window, 'unload', function()
  4700.             {
  4701.                 self.destroy();
  4702.             });
  4703.         };
  4704.  
  4705.         /**
  4706.          * The Socket.IO server will write script tags inside the forever
  4707.          * iframe, this function will be used as callback for the incoming
  4708.          * information.
  4709.          *
  4710.          * @param {String} data The message
  4711.          * @param {document} doc Reference to the context
  4712.          * @api private
  4713.          */
  4714.  
  4715.         HTMLFile.prototype._ = function(data, doc)
  4716.         {
  4717.             this.onData(data);
  4718.             try
  4719.             {
  4720.                 var script = doc.getElementsByTagName('script')[0];
  4721.                 script.parentNode.removeChild(script);
  4722.             }
  4723.             catch (e)
  4724.             {
  4725.             }
  4726.         };
  4727.  
  4728.         /**
  4729.          * Destroy the established connection, iframe and `htmlfile`.
  4730.          * And calls the `CollectGarbage` function of Internet Explorer
  4731.          * to release the memory.
  4732.          *
  4733.          * @api private
  4734.          */
  4735.  
  4736.         HTMLFile.prototype.destroy = function()
  4737.         {
  4738.             if (this.iframe)
  4739.             {
  4740.                 try
  4741.                 {
  4742.                     this.iframe.src = 'about:blank';
  4743.                 }
  4744.                 catch(e)
  4745.                 {
  4746.                 }
  4747.  
  4748.                 this.doc = null;
  4749.                 this.iframe.parentNode.removeChild(this.iframe);
  4750.                 this.iframe = null;
  4751.  
  4752.                 CollectGarbage();
  4753.             }
  4754.         };
  4755.  
  4756.         /**
  4757.          * Disconnects the established connection.
  4758.          *
  4759.          * @returns {Transport} Chaining.
  4760.          * @api public
  4761.          */
  4762.  
  4763.         HTMLFile.prototype.close = function()
  4764.         {
  4765.             this.destroy();
  4766.             return io.Transport.XHR.prototype.close.call(this);
  4767.         };
  4768.  
  4769.         /**
  4770.          * Checks if the browser supports this transport. The browser
  4771.          * must have an `Ac...eXObject` implementation.
  4772.          *
  4773.          * @return {Boolean}
  4774.          * @api public
  4775.          */
  4776.  
  4777.         HTMLFile.check = function(socket)
  4778.         {
  4779.             if ( typeof window != "undefined" && (['Active'].concat('Object').join('X')) in window)
  4780.             {
  4781.                 try
  4782.                 {
  4783.                     var a = new window[(['Active'].concat('Object').join('X'))]('htmlfile');
  4784.                     return a && io.Transport.XHR.check(socket);
  4785.                 }
  4786.                 catch(e)
  4787.                 {
  4788.                 }
  4789.             }
  4790.             return false;
  4791.         };
  4792.  
  4793.         /**
  4794.          * Check if cross domain requests are supported.
  4795.          *
  4796.          * @returns {Boolean}
  4797.          * @api public
  4798.          */
  4799.  
  4800.         HTMLFile.xdomainCheck = function()
  4801.         {
  4802.             // we can probably do handling for sub-domains, we should
  4803.             // test that it's cross domain but a subdomain here
  4804.             return false;
  4805.         };
  4806.  
  4807.         /**
  4808.          * Add the transport to your public io.transports array.
  4809.          *
  4810.          * @api private
  4811.          */
  4812.  
  4813.         io.transports.push('htmlfile');
  4814.  
  4815.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports);
  4816.  
  4817.     /**
  4818.      * socket.io
  4819.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  4820.      * MIT Licensed
  4821.      */
  4822.  
  4823.     (function(exports, io, global)
  4824.     {
  4825.  
  4826.         /**
  4827.          * Expose constructor.
  4828.          */
  4829.  
  4830.         exports['xhr-polling'] = XHRPolling;
  4831.  
  4832.         /**
  4833.          * The XHR-polling transport uses long polling XHR requests to create a
  4834.          * "persistent" connection with the server.
  4835.          *
  4836.          * @constructor
  4837.          * @api public
  4838.          */
  4839.  
  4840.         function XHRPolling()
  4841.         {
  4842.             io.Transport.XHR.apply(this, arguments);
  4843.         };
  4844.  
  4845.         /**
  4846.          * Inherits from XHR transport.
  4847.          */
  4848.  
  4849.         io.util.inherit(XHRPolling, io.Transport.XHR);
  4850.  
  4851.         /**
  4852.          * Merge the properties from XHR transport
  4853.          */
  4854.  
  4855.         io.util.merge(XHRPolling, io.Transport.XHR);
  4856.  
  4857.         /**
  4858.          * Transport name
  4859.          *
  4860.          * @api public
  4861.          */
  4862.  
  4863.         XHRPolling.prototype.name = 'xhr-polling';
  4864.  
  4865.         /**
  4866.          * Indicates whether heartbeats is enabled for this transport
  4867.          *
  4868.          * @api private
  4869.          */
  4870.  
  4871.         XHRPolling.prototype.heartbeats = function()
  4872.         {
  4873.             return false;
  4874.         };
  4875.  
  4876.         /**
  4877.          * Establish a connection, for iPhone and Android this will be done once the page
  4878.          * is loaded.
  4879.          *
  4880.          * @returns {Transport} Chaining.
  4881.          * @api public
  4882.          */
  4883.  
  4884.         XHRPolling.prototype.open = function()
  4885.         {
  4886.             var self = this;
  4887.  
  4888.             io.Transport.XHR.prototype.open.call(self);
  4889.             return false;
  4890.         };
  4891.  
  4892.         /**
  4893.          * Starts a XHR request to wait for incoming messages.
  4894.          *
  4895.          * @api private
  4896.          */
  4897.  
  4898.         function empty()
  4899.         {
  4900.         };
  4901.  
  4902.         XHRPolling.prototype.get = function()
  4903.         {
  4904.             if (!this.isOpen)
  4905.                 return;
  4906.  
  4907.             var self = this;
  4908.  
  4909.             function stateChange()
  4910.             {
  4911.                 if (this.readyState == 4)
  4912.                 {
  4913.                     this.onreadystatechange = empty;
  4914.  
  4915.                     if (this.status == 200)
  4916.                     {
  4917.                         self.onData(this.responseText);
  4918.                         self.get();
  4919.                     }
  4920.                     else
  4921.                     {
  4922.                         self.onClose();
  4923.                     }
  4924.                 }
  4925.             };
  4926.  
  4927.             function onload()
  4928.             {
  4929.                 this.onload = empty;
  4930.                 this.onerror = empty;
  4931.                 self.retryCounter = 1;
  4932.                 self.onData(this.responseText);
  4933.                 self.get();
  4934.             };
  4935.  
  4936.             function onerror()
  4937.             {
  4938.                 self.retryCounter++;
  4939.                 if (!self.retryCounter || self.retryCounter > 3)
  4940.                 {
  4941.                     self.onClose();
  4942.                 }
  4943.                 else
  4944.                 {
  4945.                     self.get();
  4946.                 }
  4947.             };
  4948.  
  4949.             this.xhr = this.request();
  4950.  
  4951.             if (global.XDomainRequest && this.xhr instanceof XDomainRequest)
  4952.             {
  4953.                 this.xhr.onload = onload;
  4954.                 this.xhr.onerror = onerror;
  4955.             }
  4956.             else
  4957.             {
  4958.                 this.xhr.onreadystatechange = stateChange;
  4959.             }
  4960.  
  4961.             this.xhr.send(null);
  4962.         };
  4963.  
  4964.         /**
  4965.          * Handle the unclean close behavior.
  4966.          *
  4967.          * @api private
  4968.          */
  4969.  
  4970.         XHRPolling.prototype.onClose = function()
  4971.         {
  4972.             io.Transport.XHR.prototype.onClose.call(this);
  4973.  
  4974.             if (this.xhr)
  4975.             {
  4976.                 this.xhr.onreadystatechange = this.xhr.onload = this.xhr.onerror = empty;
  4977.                 try
  4978.                 {
  4979.                     this.xhr.abort();
  4980.                 }
  4981.                 catch(e)
  4982.                 {
  4983.                 }
  4984.                 this.xhr = null;
  4985.             }
  4986.         };
  4987.  
  4988.         /**
  4989.          * Webkit based browsers show a infinit spinner when you start a XHR request
  4990.          * before the browsers onload event is called so we need to defer opening of
  4991.          * the transport until the onload event is called. Wrapping the cb in our
  4992.          * defer method solve this.
  4993.          *
  4994.          * @param {Socket} socket The socket instance that needs a transport
  4995.          * @param {Function} fn The callback
  4996.          * @api private
  4997.          */
  4998.  
  4999.         XHRPolling.prototype.ready = function(socket, fn)
  5000.         {
  5001.             var self = this;
  5002.  
  5003.             io.util.defer(function()
  5004.             {
  5005.                 fn.call(self);
  5006.             });
  5007.         };
  5008.  
  5009.         /**
  5010.          * Add the transport to your public io.transports array.
  5011.          *
  5012.          * @api private
  5013.          */
  5014.  
  5015.         io.transports.push('xhr-polling');
  5016.  
  5017.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports, this);
  5018.  
  5019.     /**
  5020.      * socket.io
  5021.      * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
  5022.      * MIT Licensed
  5023.      */
  5024.  
  5025.     (function(exports, io, global)
  5026.     {
  5027.         /**
  5028.          * There is a way to hide the loading indicator in Firefox. If you create and
  5029.          * remove a iframe it will stop showing the current loading indicator.
  5030.          * Unfortunately we can't feature detect that and UA sniffing is evil.
  5031.          *
  5032.          * @api private
  5033.          */
  5034.  
  5035.         var indicator = global.document && "MozAppearance" in global.document.documentElement.style;
  5036.  
  5037.         /**
  5038.          * Expose constructor.
  5039.          */
  5040.  
  5041.         exports['jsonp-polling'] = JSONPPolling;
  5042.  
  5043.         /**
  5044.          * The JSONP transport creates an persistent connection by dynamically
  5045.          * inserting a script tag in the page. This script tag will receive the
  5046.          * information of the Socket.IO server. When new information is received
  5047.          * it creates a new script tag for the new data stream.
  5048.          *
  5049.          * @constructor
  5050.          * @extends {io.Transport.xhr-polling}
  5051.          * @api public
  5052.          */
  5053.  
  5054.         function JSONPPolling(socket)
  5055.         {
  5056.             io.Transport['xhr-polling'].apply(this, arguments);
  5057.  
  5058.             this.index = io.j.length;
  5059.  
  5060.             var self = this;
  5061.  
  5062.             io.j.push(function(msg)
  5063.             {
  5064.                 self._(msg);
  5065.             });
  5066.         };
  5067.  
  5068.         /**
  5069.          * Inherits from XHR polling transport.
  5070.          */
  5071.  
  5072.         io.util.inherit(JSONPPolling, io.Transport['xhr-polling']);
  5073.  
  5074.         /**
  5075.          * Transport name
  5076.          *
  5077.          * @api public
  5078.          */
  5079.  
  5080.         JSONPPolling.prototype.name = 'jsonp-polling';
  5081.  
  5082.         /**
  5083.          * Posts a encoded message to the Socket.IO server using an iframe.
  5084.          * The iframe is used because script tags can create POST based requests.
  5085.          * The iframe is positioned outside of the view so the user does not
  5086.          * notice it's existence.
  5087.          *
  5088.          * @param {String} data A encoded message.
  5089.          * @api private
  5090.          */
  5091.  
  5092.         JSONPPolling.prototype.post = function(data)
  5093.         {
  5094.             var self = this, query = io.util.query(this.socket.options.query, 't=' + (+new Date) + '&i=' + this.index);
  5095.  
  5096.             if (!this.form)
  5097.             {
  5098.                 var form = document.createElement('form'), area = document.createElement('textarea'), id = this.iframeId = 'socketio_iframe_' + this.index, iframe;
  5099.  
  5100.                 form.className = 'socketio';
  5101.                 form.style.position = 'absolute';
  5102.                 form.style.top = '0px';
  5103.                 form.style.left = '0px';
  5104.                 form.style.display = 'none';
  5105.                 form.target = id;
  5106.                 form.method = 'POST';
  5107.                 form.setAttribute('accept-charset', 'utf-8');
  5108.                 area.name = 'd';
  5109.                 form.appendChild(area);
  5110.                 document.body.appendChild(form);
  5111.  
  5112.                 this.form = form;
  5113.                 this.area = area;
  5114.             }
  5115.  
  5116.             this.form.action = this.prepareUrl() + query;
  5117.  
  5118.             function complete()
  5119.             {
  5120.                 initIframe();
  5121.                 self.socket.setBuffer(false);
  5122.             };
  5123.  
  5124.             function initIframe()
  5125.             {
  5126.                 if (self.iframe)
  5127.                 {
  5128.                     self.form.removeChild(self.iframe);
  5129.                 }
  5130.  
  5131.                 try
  5132.                 {
  5133.                     // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  5134.                     iframe = document.createElement('<iframe name="' + self.iframeId + '">');
  5135.                 }
  5136.                 catch (e)
  5137.                 {
  5138.                     iframe = document.createElement('iframe');
  5139.                     iframe.name = self.iframeId;
  5140.                 }
  5141.  
  5142.                 iframe.id = self.iframeId;
  5143.  
  5144.                 self.form.appendChild(iframe);
  5145.                 self.iframe = iframe;
  5146.             };
  5147.  
  5148.             initIframe();
  5149.  
  5150.             // we temporarily stringify until we figure out how to prevent
  5151.             // browsers from turning `\n` into `\r\n` in form inputs
  5152.             this.area.value = io.JSON.stringify(data);
  5153.  
  5154.             try
  5155.             {
  5156.                 this.form.submit();
  5157.             }
  5158.             catch(e)
  5159.             {
  5160.             }
  5161.  
  5162.             if (this.iframe.attachEvent)
  5163.             {
  5164.                 iframe.onreadystatechange = function()
  5165.                 {
  5166.                     if (self.iframe.readyState == 'complete')
  5167.                     {
  5168.                         complete();
  5169.                     }
  5170.                 };
  5171.             }
  5172.             else
  5173.             {
  5174.                 this.iframe.onload = complete;
  5175.             }
  5176.  
  5177.             this.socket.setBuffer(true);
  5178.         };
  5179.  
  5180.         /**
  5181.          * Creates a new JSONP poll that can be used to listen
  5182.          * for messages from the Socket.IO server.
  5183.          *
  5184.          * @api private
  5185.          */
  5186.  
  5187.         JSONPPolling.prototype.get = function()
  5188.         {
  5189.             var self = this, script = document.createElement('script'), query = io.util.query(this.socket.options.query, 't=' + (+new Date) + '&i=' + this.index);
  5190.  
  5191.             if (this.script)
  5192.             {
  5193.                 this.script.parentNode.removeChild(this.script);
  5194.                 this.script = null;
  5195.             }
  5196.  
  5197.             script.async = true;
  5198.             script.src = this.prepareUrl() + query;
  5199.             script.onerror = function()
  5200.             {
  5201.                 self.onClose();
  5202.             };
  5203.  
  5204.             var insertAt = document.getElementsByTagName('script')[0];
  5205.             insertAt.parentNode.insertBefore(script, insertAt);
  5206.             this.script = script;
  5207.  
  5208.             if (indicator)
  5209.             {
  5210.                 setTimeout(function()
  5211.                 {
  5212.                     var iframe = document.createElement('iframe');
  5213.                     document.body.appendChild(iframe);
  5214.                     document.body.removeChild(iframe);
  5215.                 }, 100);
  5216.             }
  5217.         };
  5218.  
  5219.         /**
  5220.          * Callback function for the incoming message stream from the Socket.IO server.
  5221.          *
  5222.          * @param {String} data The message
  5223.          * @api private
  5224.          */
  5225.  
  5226.         JSONPPolling.prototype._ = function(msg)
  5227.         {
  5228.             this.onData(msg);
  5229.             if (this.isOpen)
  5230.             {
  5231.                 this.get();
  5232.             }
  5233.             return this;
  5234.         };
  5235.  
  5236.         /**
  5237.          * The indicator hack only works after onload
  5238.          *
  5239.          * @param {Socket} socket The socket instance that needs a transport
  5240.          * @param {Function} fn The callback
  5241.          * @api private
  5242.          */
  5243.  
  5244.         JSONPPolling.prototype.ready = function(socket, fn)
  5245.         {
  5246.             var self = this;
  5247.             if (!indicator)
  5248.                 return fn.call(this);
  5249.  
  5250.             io.util.load(function()
  5251.             {
  5252.                 fn.call(self);
  5253.             });
  5254.         };
  5255.  
  5256.         /**
  5257.          * Checks if browser supports this transport.
  5258.          *
  5259.          * @return {Boolean}
  5260.          * @api public
  5261.          */
  5262.  
  5263.         JSONPPolling.check = function()
  5264.         {
  5265.             return 'document' in global;
  5266.         };
  5267.  
  5268.         /**
  5269.          * Check if cross domain requests are supported
  5270.          *
  5271.          * @returns {Boolean}
  5272.          * @api public
  5273.          */
  5274.  
  5275.         JSONPPolling.xdomainCheck = function()
  5276.         {
  5277.             return true;
  5278.         };
  5279.  
  5280.         /**
  5281.          * Add the transport to your public io.transports array.
  5282.          *
  5283.          * @api private
  5284.          */
  5285.  
  5286.         io.transports.push('jsonp-polling');
  5287.  
  5288.     })('undefined' != typeof io ? io.Transport : module.exports, 'undefined' != typeof io ? io : module.parent.exports, this);
  5289.  
  5290.     if ( typeof define === "function" && define.amd)
  5291.     {
  5292.         define([], function()
  5293.         {
  5294.             return io;
  5295.         });
  5296.     }
  5297. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement