Advertisement
Guest User

Untitled

a guest
Apr 4th, 2014
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. this.org = this.org || {};
  2. org.cometd = {};
  3. org.cometd.JSON = {};
  4. org.cometd.JSON.toJSON = org.cometd.JSON.fromJSON = function (e) {
  5.     throw "Abstract"
  6. };
  7. org.cometd.Utils = {};
  8. org.cometd.Utils.isString = function (e) {
  9.     if (e === undefined || e === null) {
  10.         return false
  11.     }
  12.     return typeof e === "string" || e instanceof String
  13. };
  14. org.cometd.Utils.isArray = function (e) {
  15.     if (e === undefined || e === null) {
  16.         return false
  17.     }
  18.     return e instanceof Array
  19. };
  20. org.cometd.Utils.inArray = function (e, t) {
  21.     for (var n = 0; n < t.length; ++n) {
  22.         if (e === t[n]) {
  23.             return n
  24.         }
  25.     }
  26.     return -1
  27. };
  28. org.cometd.Utils.setTimeout = function (e, t, n) {
  29.     return window.setTimeout(function () {
  30.         try {
  31.             t()
  32.         } catch (n) {
  33.             e._debug("Exception invoking timed function", t, n)
  34.         }
  35.     }, n)
  36. };
  37. org.cometd.Utils.clearTimeout = function (e) {
  38.     window.clearTimeout(e)
  39. };
  40. org.cometd.TransportRegistry = function () {
  41.     var e = [];
  42.     var t = {};
  43.     this.getTransportTypes = function () {
  44.         return e.slice(0)
  45.     };
  46.     this.findTransportTypes = function (n, r, i) {
  47.         var s = [];
  48.         for (var o = 0; o < e.length; ++o) {
  49.             var u = e[o];
  50.             if (t[u].accept(n, r, i) === true) {
  51.                 s.push(u)
  52.             }
  53.         }
  54.         return s
  55.     };
  56.     this.negotiateTransport = function (n, r, i, s) {
  57.         for (var o = 0; o < e.length; ++o) {
  58.             var u = e[o];
  59.             for (var a = 0; a < n.length; ++a) {
  60.                 if (u === n[a]) {
  61.                     var f = t[u];
  62.                     if (f.accept(r, i, s) === true) {
  63.                         return f
  64.                     }
  65.                 }
  66.             }
  67.         }
  68.         return null
  69.     };
  70.     this.add = function (n, r, i) {
  71.         var s = false;
  72.         for (var o = 0; o < e.length; ++o) {
  73.             if (e[o] === n) {
  74.                 s = true;
  75.                 break
  76.             }
  77.         }
  78.         if (!s) {
  79.             if (typeof i !== "number") {
  80.                 e.push(n)
  81.             } else {
  82.                 e.splice(i, 0, n)
  83.             }
  84.             t[n] = r
  85.         }
  86.         return !s
  87.     };
  88.     this.find = function (n) {
  89.         for (var r = 0; r < e.length; ++r) {
  90.             if (e[r] === n) {
  91.                 return t[n]
  92.             }
  93.         }
  94.         return null
  95.     };
  96.     this.remove = function (n) {
  97.         for (var r = 0; r < e.length; ++r) {
  98.             if (e[r] === n) {
  99.                 e.splice(r, 1);
  100.                 var i = t[n];
  101.                 delete t[n];
  102.                 return i
  103.             }
  104.         }
  105.         return null
  106.     };
  107.     this.clear = function () {
  108.         e = [];
  109.         t = {}
  110.     };
  111.     this.reset = function () {
  112.         for (var n = 0; n < e.length; ++n) {
  113.             t[e[n]].reset()
  114.         }
  115.     }
  116. };
  117. org.cometd.Transport = function () {
  118.     var e;
  119.     var t;
  120.     this.registered = function (n, r) {
  121.         e = n;
  122.         t = r
  123.     };
  124.     this.unregistered = function () {
  125.         e = null;
  126.         t = null
  127.     };
  128.     this._debug = function () {
  129.         t._debug.apply(t, arguments)
  130.     };
  131.     this._mixin = function () {
  132.         return t._mixin.apply(t, arguments)
  133.     };
  134.     this.getConfiguration = function () {
  135.         return t.getConfiguration()
  136.     };
  137.     this.getAdvice = function () {
  138.         return t.getAdvice()
  139.     };
  140.     this.setTimeout = function (e, n) {
  141.         return org.cometd.Utils.setTimeout(t, e, n)
  142.     };
  143.     this.clearTimeout = function (e) {
  144.         org.cometd.Utils.clearTimeout(e)
  145.     };
  146.     this.convertToMessages = function (e) {
  147.         if (org.cometd.Utils.isString(e)) {
  148.             try {
  149.                 return org.cometd.JSON.fromJSON(e)
  150.             } catch (t) {
  151.                 this._debug("Could not convert to JSON the following string", '"' + e + '"');
  152.                 throw t
  153.             }
  154.         }
  155.         if (org.cometd.Utils.isArray(e)) {
  156.             return e
  157.         }
  158.         if (e === undefined || e === null) {
  159.             return []
  160.         }
  161.         if (e instanceof Object) {
  162.             return [e]
  163.         }
  164.         throw "Conversion Error " + e + ", typeof " + typeof e
  165.     };
  166.     this.accept = function (e, t, n) {
  167.         throw "Abstract"
  168.     };
  169.     this.getType = function () {
  170.         return e
  171.     };
  172.     this.send = function (e, t) {
  173.         throw "Abstract"
  174.     };
  175.     this.reset = function () {
  176.         this._debug("Transport", e, "reset")
  177.     };
  178.     this.abort = function () {
  179.         this._debug("Transport", e, "aborted")
  180.     };
  181.     this.toString = function () {
  182.         return this.getType()
  183.     }
  184. };
  185. org.cometd.Transport.derive = function (e) {
  186.     function t() {}
  187.     t.prototype = e;
  188.     return new t
  189. };
  190. org.cometd.RequestTransport = function () {
  191.     function o(e) {
  192.         while (s.length > 0) {
  193.             var t = s[0];
  194.             var n = t[0];
  195.             var r = t[1];
  196.             if (n.url === e.url && n.sync === e.sync) {
  197.                 s.shift();
  198.                 e.messages = e.messages.concat(n.messages);
  199.                 this._debug("Coalesced", n.messages.length, "messages from request", r.id);
  200.                 continue
  201.             }
  202.             break
  203.         }
  204.     }
  205.     function u(e, t) {
  206.         this.transportSend(e, t);
  207.         t.expired = false;
  208.         if (!e.sync) {
  209.             var n = this.getConfiguration().maxNetworkDelay;
  210.             var r = n;
  211.             if (t.metaConnect === true) {
  212.                 r += this.getAdvice().timeout
  213.             }
  214.             this._debug("Transport", this.getType(), "waiting at most", r, "ms for the response, maxNetworkDelay", n);
  215.             var i = this;
  216.             t.timeout = this.setTimeout(function () {
  217.                 t.expired = true;
  218.                 var n = "Request " + t.id + " of transport " + i.getType() + " exceeded " + r + " ms max network delay";
  219.                 var s = {
  220.                     reason: n
  221.                 };
  222.                 var o = t.xhr;
  223.                 s.httpCode = i.xhrStatus(o);
  224.                 i.abortXHR(o);
  225.                 i._debug(n);
  226.                 i.complete(t, false, t.metaConnect);
  227.                 e.onFailure(o, e.messages, s)
  228.             }, r)
  229.         }
  230.     }
  231.     function a(e) {
  232.         var t = ++n;
  233.         var r = {
  234.             id: t,
  235.             metaConnect: false
  236.         };
  237.         if (i.length < this.getConfiguration().maxConnections - 1) {
  238.             i.push(r);
  239.             u.call(this, e, r)
  240.         } else {
  241.             this._debug("Transport", this.getType(), "queueing request", t, "envelope", e);
  242.             s.push([e, r])
  243.         }
  244.     }
  245.     function f(e) {
  246.         var t = e.id;
  247.         this._debug("Transport", this.getType(), "metaConnect complete, request", t);
  248.         if (r !== null && r.id !== t) {
  249.             throw "Longpoll request mismatch, completing request " + t
  250.         }
  251.         r = null
  252.     }
  253.     function l(e, t) {
  254.         var n = org.cometd.Utils.inArray(e, i);
  255.         if (n >= 0) {
  256.             i.splice(n, 1)
  257.         }
  258.         if (s.length > 0) {
  259.             var r = s.shift();
  260.             var u = r[0];
  261.             var f = r[1];
  262.             this._debug("Transport dequeued request", f.id);
  263.             if (t) {
  264.                 if (this.getConfiguration().autoBatch) {
  265.                     o.call(this, u)
  266.                 }
  267.                 a.call(this, u);
  268.                 this._debug("Transport completed request", e.id, u)
  269.             } else {
  270.                 var l = this;
  271.                 this.setTimeout(function () {
  272.                     l.complete(f, false, f.metaConnect);
  273.                     var e = {
  274.                         reason: "Previous request failed"
  275.                     };
  276.                     var t = f.xhr;
  277.                     e.httpCode = l.xhrStatus(t);
  278.                     u.onFailure(t, u.messages, e)
  279.                 }, 0)
  280.             }
  281.         }
  282.     }
  283.     function c(e) {
  284.         if (r !== null) {
  285.             throw "Concurrent metaConnect requests not allowed, request id=" + r.id + " not yet completed"
  286.         }
  287.         var t = ++n;
  288.         this._debug("Transport", this.getType(), "metaConnect send, request", t, "envelope", e);
  289.         var i = {
  290.             id: t,
  291.             metaConnect: true
  292.         };
  293.         u.call(this, e, i);
  294.         r = i
  295.     }
  296.     var e = new org.cometd.Transport;
  297.     var t = org.cometd.Transport.derive(e);
  298.     var n = 0;
  299.     var r = null;
  300.     var i = [];
  301.     var s = [];
  302.     t.complete = function (e, t, n) {
  303.         if (n) {
  304.             f.call(this, e)
  305.         } else {
  306.             l.call(this, e, t)
  307.         }
  308.     };
  309.     t.transportSend = function (e, t) {
  310.         throw "Abstract"
  311.     };
  312.     t.transportSuccess = function (e, t, n) {
  313.         if (!t.expired) {
  314.             this.clearTimeout(t.timeout);
  315.             this.complete(t, true, t.metaConnect);
  316.             if (n && n.length > 0) {
  317.                 e.onSuccess(n)
  318.             } else {
  319.                 e.onFailure(t.xhr, e.messages, {
  320.                     httpCode: 204
  321.                 })
  322.             }
  323.         }
  324.     };
  325.     t.transportFailure = function (e, t, n) {
  326.         if (!t.expired) {
  327.             this.clearTimeout(t.timeout);
  328.             this.complete(t, false, t.metaConnect);
  329.             e.onFailure(t.xhr, e.messages, n)
  330.         }
  331.     };
  332.     t.send = function (e, t) {
  333.         if (t) {
  334.             c.call(this, e)
  335.         } else {
  336.             a.call(this, e)
  337.         }
  338.     };
  339.     t.abort = function () {
  340.         e.abort();
  341.         for (var t = 0; t < i.length; ++t) {
  342.             var n = i[t];
  343.             this._debug("Aborting request", n);
  344.             this.abortXHR(n.xhr)
  345.         }
  346.         if (r) {
  347.             this._debug("Aborting metaConnect request", r);
  348.             this.abortXHR(r.xhr)
  349.         }
  350.         this.reset()
  351.     };
  352.     t.reset = function () {
  353.         e.reset();
  354.         r = null;
  355.         i = [];
  356.         s = []
  357.     };
  358.     t.abortXHR = function (e) {
  359.         if (e) {
  360.             try {
  361.                 e.abort()
  362.             } catch (t) {
  363.                 this._debug(t)
  364.             }
  365.         }
  366.     };
  367.     t.xhrStatus = function (e) {
  368.         if (e) {
  369.             try {
  370.                 return e.status
  371.             } catch (t) {
  372.                 this._debug(t)
  373.             }
  374.         }
  375.         return -1
  376.     };
  377.     return t
  378. };
  379. org.cometd.LongPollingTransport = function () {
  380.     var e = new org.cometd.RequestTransport;
  381.     var t = org.cometd.Transport.derive(e);
  382.     var n = true;
  383.     t.accept = function (e, t, r) {
  384.         return n || !t
  385.     };
  386.     t.xhrSend = function (e) {
  387.         throw "Abstract"
  388.     };
  389.     t.transportSend = function (e, t) {
  390.         this._debug("Transport", this.getType(), "sending request", t.id, "envelope", e);
  391.         var r = this;
  392.         try {
  393.             var i = true;
  394.             t.xhr = this.xhrSend({
  395.                 transport: this,
  396.                 url: e.url,
  397.                 sync: e.sync,
  398.                 headers: this.getConfiguration().requestHeaders,
  399.                 body: org.cometd.JSON.toJSON(e.messages),
  400.                 onSuccess: function (i) {
  401.                     r._debug("Transport", r.getType(), "received response", i);
  402.                     var s = false;
  403.                     try {
  404.                         var o = r.convertToMessages(i);
  405.                         if (o.length === 0) {
  406.                             n = false;
  407.                             r.transportFailure(e, t, {
  408.                                 httpCode: 204
  409.                             })
  410.                         } else {
  411.                             s = true;
  412.                             r.transportSuccess(e, t, o)
  413.                         }
  414.                     } catch (u) {
  415.                         r._debug(u);
  416.                         if (!s) {
  417.                             n = false;
  418.                             var a = {
  419.                                 exception: u
  420.                             };
  421.                             a.httpCode = r.xhrStatus(t.xhr);
  422.                             r.transportFailure(e, t, a)
  423.                         }
  424.                     }
  425.                 },
  426.                 onError: function (s, o) {
  427.                     n = false;
  428.                     var u = {
  429.                         reason: s,
  430.                         exception: o
  431.                     };
  432.                     u.httpCode = r.xhrStatus(t.xhr);
  433.                     if (i) {
  434.                         r.setTimeout(function () {
  435.                             r.transportFailure(e, t, u)
  436.                         }, 0)
  437.                     } else {
  438.                         r.transportFailure(e, t, u)
  439.                     }
  440.                 }
  441.             });
  442.             i = false
  443.         } catch (s) {
  444.             n = false;
  445.             this.setTimeout(function () {
  446.                 r.transportFailure(e, t, {
  447.                     exception: s
  448.                 })
  449.             }, 0)
  450.         }
  451.     };
  452.     t.reset = function () {
  453.         e.reset();
  454.         n = true
  455.     };
  456.     return t
  457. };
  458. org.cometd.CallbackPollingTransport = function () {
  459.     var e = new org.cometd.RequestTransport;
  460.     var t = org.cometd.Transport.derive(e);
  461.     var n = 2e3;
  462.     t.accept = function (e, t, n) {
  463.         return true
  464.     };
  465.     t.jsonpSend = function (e) {
  466.         throw "Abstract"
  467.     };
  468.     t.transportSend = function (e, t) {
  469.         var r = this;
  470.         var i = 0;
  471.         var s = e.messages.length;
  472.         var o = [];
  473.         while (s > 0) {
  474.             var u = org.cometd.JSON.toJSON(e.messages.slice(i, i + s));
  475.             var a = e.url.length + encodeURI(u).length;
  476.             if (a > n) {
  477.                 if (s === 1) {
  478.                     this.setTimeout(function () {
  479.                         r.transportFailure(e, t, {
  480.                             reason: "Bayeux message too big, max is " + n
  481.                         })
  482.                     }, 0);
  483.                     return
  484.                 }--s;
  485.                 continue
  486.             }
  487.             o.push(s);
  488.             i += s;
  489.             s = e.messages.length - i
  490.         }
  491.         var f = e;
  492.         if (o.length > 1) {
  493.             var l = 0;
  494.             var c = o[0];
  495.             this._debug("Transport", this.getType(), "split", e.messages.length, "messages into", o.join(" + "));
  496.             f = this._mixin(false, {}, e);
  497.             f.messages = e.messages.slice(l, c);
  498.             f.onSuccess = e.onSuccess;
  499.             f.onFailure = e.onFailure;
  500.             for (var h = 1; h < o.length; ++h) {
  501.                 var p = this._mixin(false, {}, e);
  502.                 l = c;
  503.                 c += o[h];
  504.                 p.messages = e.messages.slice(l, c);
  505.                 p.onSuccess = e.onSuccess;
  506.                 p.onFailure = e.onFailure;
  507.                 this.send(p, t.metaConnect)
  508.             }
  509.         }
  510.         this._debug("Transport", this.getType(), "sending request", t.id, "envelope", f);
  511.         try {
  512.             var d = true;
  513.             this.jsonpSend({
  514.                 transport: this,
  515.                 url: f.url,
  516.                 sync: f.sync,
  517.                 headers: this.getConfiguration().requestHeaders,
  518.                 body: org.cometd.JSON.toJSON(f.messages),
  519.                 onSuccess: function (e) {
  520.                     var n = false;
  521.                     try {
  522.                         var i = r.convertToMessages(e);
  523.                         if (i.length === 0) {
  524.                             r.transportFailure(f, t, {
  525.                                 httpCode: 204
  526.                             })
  527.                         } else {
  528.                             n = true;
  529.                             r.transportSuccess(f, t, i)
  530.                         }
  531.                     } catch (s) {
  532.                         r._debug(s);
  533.                         if (!n) {
  534.                             r.transportFailure(f, t, {
  535.                                 exception: s
  536.                             })
  537.                         }
  538.                     }
  539.                 },
  540.                 onError: function (e, n) {
  541.                     var i = {
  542.                         reason: e,
  543.                         exception: n
  544.                     };
  545.                     if (d) {
  546.                         r.setTimeout(function () {
  547.                             r.transportFailure(f, t, i)
  548.                         }, 0)
  549.                     } else {
  550.                         r.transportFailure(f, t, i)
  551.                     }
  552.                 }
  553.             });
  554.             d = false
  555.         } catch (v) {
  556.             this.setTimeout(function () {
  557.                 r.transportFailure(f, t, {
  558.                     exception: v
  559.                 })
  560.             }, 0)
  561.         }
  562.     };
  563.     return t
  564. };
  565. org.cometd.WebSocketTransport = function () {
  566.     function h() {
  567.         if (a) {
  568.             return
  569.         }
  570.         a = true;
  571.         var e = n.getURL().replace(/^http/, "ws");
  572.         this._debug("Transport", this.getType(), "connecting to URL", e);
  573.         try {
  574.             var t = n.getConfiguration().protocol;
  575.             var i = t ? new org.cometd.WebSocket(e, t) : new org.cometd.WebSocket(e)
  576.         } catch (o) {
  577.             r = false;
  578.             this._debug("Exception while creating WebSocket object", o);
  579.             throw o
  580.         }
  581.         s = n.getConfiguration().stickyReconnect !== false;
  582.         var u = this;
  583.         var l = null;
  584.         var c = n.getConfiguration().connectTimeout;
  585.         if (c > 0) {
  586.             l = this.setTimeout(function () {
  587.                 l = null;
  588.                 u._debug("Transport", u.getType(), "timed out while connecting to URL", e, ":", c, "ms");
  589.                 var t = {
  590.                     code: 1e3,
  591.                     reason: "Connect Timeout"
  592.                 };
  593.                 u.webSocketClose(i, t.code, t.reason);
  594.                 u.onClose(i, t)
  595.             }, c)
  596.         }
  597.         var h = function () {
  598.                 u._debug("WebSocket opened", i);
  599.                 a = false;
  600.                 if (l) {
  601.                     u.clearTimeout(l);
  602.                     l = null
  603.                 }
  604.                 if (f) {
  605.                     n._warn("Closing Extra WebSocket Connections", i, f);
  606.                     u.webSocketClose(i, 1e3, "Extra Connection")
  607.                 } else {
  608.                     u.onOpen(i)
  609.                 }
  610.             };
  611.         var p = function (e) {
  612.                 e = e || {
  613.                     code: 1e3
  614.                 };
  615.                 u._debug("WebSocket closing", i, e);
  616.                 a = false;
  617.                 if (l) {
  618.                     u.clearTimeout(l);
  619.                     l = null
  620.                 }
  621.                 if (f !== null && i !== f) {
  622.                     u._debug("Closed Extra WebSocket Connection", i)
  623.                 } else {
  624.                     u.onClose(i, e)
  625.                 }
  626.             };
  627.         var d = function (e) {
  628.                 u._debug("WebSocket message", e, i);
  629.                 if (i !== f) {
  630.                     n._warn("Extra WebSocket Connections", i, f)
  631.                 }
  632.                 u.onMessage(i, e)
  633.             };
  634.         i.onopen = h;
  635.         i.onclose = p;
  636.         i.onerror = function () {
  637.             p({
  638.                 code: 1002,
  639.                 reason: "Error"
  640.             })
  641.         };
  642.         i.onmessage = d;
  643.         this._debug("Transport", this.getType(), "configured callbacks on", i)
  644.     }
  645.     function p(e, t, n) {
  646.         var r = org.cometd.JSON.toJSON(t.messages);
  647.         e.send(r);
  648.         this._debug("Transport", this.getType(), "sent", t, "metaConnect =", n);
  649.         var i = this.getConfiguration().maxNetworkDelay;
  650.         var s = i;
  651.         if (n) {
  652.             s += this.getAdvice().timeout;
  653.             l = true
  654.         }
  655.         var o = this;
  656.         var a = [];
  657.         for (var f = 0; f < t.messages.length; ++f) {
  658.             (function () {
  659.                 var n = t.messages[f];
  660.                 if (n.id) {
  661.                     a.push(n.id);
  662.                     u[n.id] = this.setTimeout(function () {
  663.                         o._debug("Transport", o.getType(), "timing out message", n.id, "after", s, "on", e);
  664.                         var t = {
  665.                             code: 1e3,
  666.                             reason: "Message Timeout"
  667.                         };
  668.                         o.webSocketClose(e, t.code, t.reason);
  669.                         o.onClose(e, t)
  670.                     }, s)
  671.                 }
  672.             })()
  673.         }
  674.         this._debug("Transport", this.getType(), "waiting at most", s, "ms for messages", a, "maxNetworkDelay", i, ", timeouts:", u)
  675.     }
  676.     function d(e, t, n) {
  677.         try {
  678.             if (e === null) {
  679.                 h.call(this)
  680.             } else {
  681.                 p.call(this, e, t, n)
  682.             }
  683.         } catch (r) {
  684.             this.setTimeout(function () {
  685.                 t.onFailure(e, t.messages, {
  686.                     exception: r
  687.                 })
  688.             }, 0)
  689.         }
  690.     }
  691.     var e = new org.cometd.Transport;
  692.     var t = org.cometd.Transport.derive(e);
  693.     var n;
  694.     var r = true;
  695.     var i = false;
  696.     var s = true;
  697.     var o = {};
  698.     var u = {};
  699.     var a = false;
  700.     var f = null;
  701.     var l = false;
  702.     var c = null;
  703.     t.reset = function () {
  704.         e.reset();
  705.         r = true;
  706.         i = false;
  707.         s = true;
  708.         o = {};
  709.         u = {};
  710.         a = false;
  711.         f = null;
  712.         l = false;
  713.         c = null
  714.     };
  715.     t.onOpen = function (e) {
  716.         this._debug("Transport", this.getType(), "opened", e);
  717.         f = e;
  718.         i = true;
  719.         this._debug("Sending pending messages", o);
  720.         for (var t in o) {
  721.             var n = o[t];
  722.             var r = n[0];
  723.             var s = n[1];
  724.             c = r.onSuccess;
  725.             p.call(this, e, r, s)
  726.         }
  727.     };
  728.     t.onMessage = function (e, t) {
  729.         this._debug("Transport", this.getType(), "received websocket message", t, e);
  730.         var n = false;
  731.         var r = this.convertToMessages(t.data);
  732.         var i = [];
  733.         for (var s = 0; s < r.length; ++s) {
  734.             var a = r[s];
  735.             if (/^\/meta\//.test(a.channel) || a.successful !== undefined) {
  736.                 if (a.id) {
  737.                     i.push(a.id);
  738.                     var f = u[a.id];
  739.                     if (f) {
  740.                         this.clearTimeout(f);
  741.                         delete u[a.id];
  742.                         this._debug("Transport", this.getType(), "removed timeout for message", a.id, ", timeouts", u)
  743.                     }
  744.                 }
  745.             }
  746.             if ("/meta/connect" === a.channel) {
  747.                 l = false
  748.             }
  749.             if ("/meta/disconnect" === a.channel && !l) {
  750.                 n = true
  751.             }
  752.         }
  753.         var h = false;
  754.         for (var p = 0; p < i.length; ++p) {
  755.             var d = i[p];
  756.             for (var v in o) {
  757.                 var m = v.split(",");
  758.                 var g = org.cometd.Utils.inArray(d, m);
  759.                 if (g >= 0) {
  760.                     h = true;
  761.                     m.splice(g, 1);
  762.                     var y = o[v][0];
  763.                     var b = o[v][1];
  764.                     delete o[v];
  765.                     if (m.length > 0) {
  766.                         o[m.join(",")] = [y, b]
  767.                     }
  768.                     break
  769.                 }
  770.             }
  771.         }
  772.         if (h) {
  773.             this._debug("Transport", this.getType(), "removed envelope, envelopes", o)
  774.         }
  775.         c.call(this, r);
  776.         if (n) {
  777.             this.webSocketClose(e, 1e3, "Disconnect")
  778.         }
  779.     };
  780.     t.onClose = function (e, t) {
  781.         this._debug("Transport", this.getType(), "closed", e, t);
  782.         r = s && i;
  783.         for (var n in u) {
  784.             this.clearTimeout(u[n])
  785.         }
  786.         u = {};
  787.         for (var a in o) {
  788.             var c = o[a][0];
  789.             var h = o[a][1];
  790.             if (h) {
  791.                 l = false
  792.             }
  793.             c.onFailure(e, c.messages, {
  794.                 websocketCode: t.code,
  795.                 reason: t.reason
  796.             })
  797.         }
  798.         o = {};
  799.         f = null
  800.     };
  801.     t.registered = function (t, r) {
  802.         e.registered(t, r);
  803.         n = r
  804.     };
  805.     t.accept = function (e, t, i) {
  806.         return r && !! org.cometd.WebSocket && n.websocketEnabled !== false
  807.     };
  808.     t.send = function (e, t) {
  809.         this._debug("Transport", this.getType(), "sending", e, "metaConnect =", t);
  810.         var n = [];
  811.         for (var r = 0; r < e.messages.length; ++r) {
  812.             var i = e.messages[r];
  813.             if (i.id) {
  814.                 n.push(i.id)
  815.             }
  816.         }
  817.         o[n.join(",")] = [e, t];
  818.         this._debug("Transport", this.getType(), "stored envelope, envelopes", o);
  819.         d.call(this, f, e, t)
  820.     };
  821.     t.webSocketClose = function (e, t, n) {
  822.         try {
  823.             e.close(t, n)
  824.         } catch (r) {
  825.             this._debug(r)
  826.         }
  827.     };
  828.     t.abort = function () {
  829.         e.abort();
  830.         if (f) {
  831.             var t = {
  832.                 code: 1001,
  833.                 reason: "Abort"
  834.             };
  835.             this.webSocketClose(f, t.code, t.reason);
  836.             this.onClose(f, t)
  837.         }
  838.         this.reset()
  839.     };
  840.     return t
  841. };
  842. org.cometd.Cometd = function (e) {
  843.     function x(e, t) {
  844.         try {
  845.             return e[t]
  846.         } catch (n) {
  847.             return undefined
  848.         }
  849.     }
  850.     function T(e) {
  851.         return org.cometd.Utils.isString(e)
  852.     }
  853.     function N(e) {
  854.         if (e === undefined || e === null) {
  855.             return false
  856.         }
  857.         return typeof e === "function"
  858.     }
  859.     function C(e, t) {
  860.         if (window.console) {
  861.             var n = window.console[e];
  862.             if (N(n)) {
  863.                 n.apply(window.console, t)
  864.             }
  865.         }
  866.     }
  867.     function k(e) {
  868.         t._debug("Configuring cometd object with", e);
  869.         if (T(e)) {
  870.             e = {
  871.                 url: e
  872.             }
  873.         }
  874.         if (!e) {
  875.             e = {}
  876.         }
  877.         S = t._mixin(false, S, e);
  878.         var n = t.getURL();
  879.         if (!n) {
  880.             throw "Missing required configuration parameter 'url' specifying the Bayeux server URL"
  881.         }
  882.         var i = /(^https?:\/\/)?(((\[[^\]]+\])|([^:\/\?#]+))(:(\d+))?)?([^\?#]*)(.*)?/.exec(n);
  883.         var s = i[2];
  884.         var o = i[8];
  885.         var u = i[9];
  886.         r = t._isCrossDomain(s);
  887.         if (S.appendMessageTypeToURL) {
  888.             if (u !== undefined && u.length > 0) {
  889.                 t._info("Appending message type to URI " + o + u + " is not supported, disabling 'appendMessageTypeToURL' configuration");
  890.                 S.appendMessageTypeToURL = false
  891.             } else {
  892.                 var a = o.split("/");
  893.                 var f = a.length - 1;
  894.                 if (o.match(/\/$/)) {
  895.                     f -= 1
  896.                 }
  897.                 if (a[f].indexOf(".") >= 0) {
  898.                     t._info("Appending message type to URI " + o + " is not supported, disabling 'appendMessageTypeToURL' configuration");
  899.                     S.appendMessageTypeToURL = false
  900.                 }
  901.             }
  902.         }
  903.     }
  904.     function L(e) {
  905.         if (e) {
  906.             var n = h[e.channel];
  907.             if (n && n[e.id]) {
  908.                 delete n[e.id];
  909.                 t._debug("Removed", e.listener ? "listener" : "subscription", e)
  910.             }
  911.         }
  912.     }
  913.     function A(e) {
  914.         if (e && !e.listener) {
  915.             L(e)
  916.         }
  917.     }
  918.     function O() {
  919.         for (var e in h) {
  920.             var t = h[e];
  921.             if (t) {
  922.                 for (var n = 0; n < t.length; ++n) {
  923.                     A(t[n])
  924.                 }
  925.             }
  926.         }
  927.     }
  928.     function M(e) {
  929.         if (o !== e) {
  930.             t._debug("Status", o, "->", e);
  931.             o = e
  932.         }
  933.     }
  934.     function _() {
  935.         return o === "disconnecting" || o === "disconnected"
  936.     }
  937.     function D() {
  938.         return ++u
  939.     }
  940.     function P(e, n, r, i, s) {
  941.         try {
  942.             return n.call(e, i)
  943.         } catch (o) {
  944.             t._debug("Exception during execution of extension", r, o);
  945.             var u = t.onExtensionException;
  946.             if (N(u)) {
  947.                 t._debug("Invoking extension exception callback", r, o);
  948.                 try {
  949.                     u.call(t, o, r, s, i)
  950.                 } catch (a) {
  951.                     t._info("Exception during execution of exception callback in extension", r, a)
  952.                 }
  953.             }
  954.             return i
  955.         }
  956.     }
  957.     function H(e) {
  958.         for (var t = 0; t < v.length; ++t) {
  959.             if (e === undefined || e === null) {
  960.                 break
  961.             }
  962.             var n = S.reverseIncomingExtensions ? v.length - 1 - t : t;
  963.             var r = v[n];
  964.             var i = r.extension.incoming;
  965.             if (N(i)) {
  966.                 var s = P(r.extension, i, r.name, e, false);
  967.                 e = s === undefined ? e : s
  968.             }
  969.         }
  970.         return e
  971.     }
  972.     function B(e) {
  973.         for (var t = 0; t < v.length; ++t) {
  974.             if (e === undefined || e === null) {
  975.                 break
  976.             }
  977.             var n = v[t];
  978.             var r = n.extension.outgoing;
  979.             if (N(r)) {
  980.                 var i = P(n.extension, r, n.name, e, true);
  981.                 e = i === undefined ? e : i
  982.             }
  983.         }
  984.         return e
  985.     }
  986.     function j(e, n) {
  987.         var r = h[e];
  988.         if (r && r.length > 0) {
  989.             for (var i = 0; i < r.length; ++i) {
  990.                 var s = r[i];
  991.                 if (s) {
  992.                     try {
  993.                         s.callback.call(s.scope, n)
  994.                     } catch (o) {
  995.                         t._debug("Exception during notification", s, n, o);
  996.                         var u = t.onListenerException;
  997.                         if (N(u)) {
  998.                             t._debug("Invoking listener exception callback", s, o);
  999.                             try {
  1000.                                 u.call(t, o, s, s.listener, n)
  1001.                             } catch (a) {
  1002.                                 t._info("Exception during execution of listener callback", s, a)
  1003.                             }
  1004.                         }
  1005.                     }
  1006.                 }
  1007.             }
  1008.         }
  1009.     }
  1010.     function F(e, t) {
  1011.         j(e, t);
  1012.         var n = e.split("/");
  1013.         var r = n.length - 1;
  1014.         for (var i = r; i > 0; --i) {
  1015.             var s = n.slice(0, i).join("/") + "/*";
  1016.             if (i === r) {
  1017.                 j(s, t)
  1018.             }
  1019.             s += "*";
  1020.             j(s, t)
  1021.         }
  1022.     }
  1023.     function I() {
  1024.         if (d !== null) {
  1025.             org.cometd.Utils.clearTimeout(d)
  1026.         }
  1027.         d = null
  1028.     }
  1029.     function q(e) {
  1030.         I();
  1031.         var n = m.interval + p;
  1032.         t._debug("Function scheduled in", n, "ms, interval =", m.interval, "backoff =", p, e);
  1033.         d = org.cometd.Utils.setTimeout(t, e, n)
  1034.     }
  1035.     function z(e, n, r, i) {
  1036.         for (var o = 0; o < n.length; ++o) {
  1037.             var u = n[o];
  1038.             var f = "" + D();
  1039.             u.id = f;
  1040.             if (a) {
  1041.                 u.clientId = a
  1042.             }
  1043.             var l = undefined;
  1044.             if (N(u._callback)) {
  1045.                 l = u._callback;
  1046.                 delete u._callback
  1047.             }
  1048.             u = B(u);
  1049.             if (u !== undefined && u !== null) {
  1050.                 u.id = f;
  1051.                 n[o] = u;
  1052.                 if (l) {
  1053.                     b[f] = l
  1054.                 }
  1055.             } else {
  1056.                 n.splice(o--, 1)
  1057.             }
  1058.         }
  1059.         if (n.length === 0) {
  1060.             return
  1061.         }
  1062.         var c = t.getURL();
  1063.         if (S.appendMessageTypeToURL) {
  1064.             if (!c.match(/\/$/)) {
  1065.                 c = c + "/"
  1066.             }
  1067.             if (i) {
  1068.                 c = c + i
  1069.             }
  1070.         }
  1071.         var h = {
  1072.             url: c,
  1073.             sync: e,
  1074.             messages: n,
  1075.             onSuccess: function (e) {
  1076.                 try {
  1077.                     R.call(t, e)
  1078.                 } catch (n) {
  1079.                     t._debug("Exception during handling of messages", n)
  1080.                 }
  1081.             },
  1082.             onFailure: function (e, n, r) {
  1083.                 try {
  1084.                     r.connectionType = t.getTransport().getType();
  1085.                     U.call(t, e, n, r)
  1086.                 } catch (i) {
  1087.                     t._debug("Exception during handling of failure", i)
  1088.                 }
  1089.             }
  1090.         };
  1091.         t._debug("Send", h);
  1092.         s.send(h, r)
  1093.     }
  1094.     function W(e) {
  1095.         if (f > 0 || c === true) {
  1096.             l.push(e)
  1097.         } else {
  1098.             z(false, [e], false)
  1099.         }
  1100.     }
  1101.     function X() {
  1102.         p = 0
  1103.     }
  1104.     function V() {
  1105.         if (p < S.maxBackoff) {
  1106.             p += S.backoffIncrement
  1107.         }
  1108.     }
  1109.     function $() {
  1110.         ++f
  1111.     }
  1112.     function J() {
  1113.         var e = l;
  1114.         l = [];
  1115.         if (e.length > 0) {
  1116.             z(false, e, false)
  1117.         }
  1118.     }
  1119.     function K() {
  1120.         --f;
  1121.         if (f < 0) {
  1122.             throw "Calls to startBatch() and endBatch() are not paired"
  1123.         }
  1124.         if (f === 0 && !_() && !c) {
  1125.             J()
  1126.         }
  1127.     }
  1128.     function Q() {
  1129.         if (!_()) {
  1130.             var e = {
  1131.                 channel: "/meta/connect",
  1132.                 connectionType: s.getType()
  1133.             };
  1134.             if (!E) {
  1135.                 e.advice = {
  1136.                     timeout: 0
  1137.                 }
  1138.             }
  1139.             M("connecting");
  1140.             t._debug("Connect sent", e);
  1141.             z(false, [e], true, "connect");
  1142.             M("connected")
  1143.         }
  1144.     }
  1145.     function G() {
  1146.         M("connecting");
  1147.         q(function () {
  1148.             Q()
  1149.         })
  1150.     }
  1151.     function Y(e) {
  1152.         if (e) {
  1153.             m = t._mixin(false, {}, S.advice, e);
  1154.             t._debug("New advice", m)
  1155.         }
  1156.     }
  1157.     function Z(e) {
  1158.         I();
  1159.         if (e) {
  1160.             s.abort()
  1161.         }
  1162.         a = null;
  1163.         M("disconnected");
  1164.         f = 0;
  1165.         X();
  1166.         s = null;
  1167.         if (l.length > 0) {
  1168.             U.call(t, undefined, l, {
  1169.                 reason: "Disconnected"
  1170.             });
  1171.             l = []
  1172.         }
  1173.     }
  1174.     function et(e, n, r) {
  1175.         var i = t.onTransportFailure;
  1176.         if (N(i)) {
  1177.             t._debug("Invoking transport failure callback", e, n, r);
  1178.             try {
  1179.                 i.call(t, e, n, r)
  1180.             } catch (s) {
  1181.                 t._info("Exception during execution of transport failure callback", s)
  1182.             }
  1183.         }
  1184.     }
  1185.     function tt(e, n) {
  1186.         if (N(e)) {
  1187.             n = e;
  1188.             e = undefined
  1189.         }
  1190.         a = null;
  1191.         O();
  1192.         if (_()) {
  1193.             i.reset();
  1194.             Y(S.advice)
  1195.         } else {
  1196.             Y(t._mixin(false, m, {
  1197.                 reconnect: "retry"
  1198.             }))
  1199.         }
  1200.         f = 0;
  1201.         c = true;
  1202.         g = e;
  1203.         y = n;
  1204.         var o = "1.0";
  1205.         var u = t.getURL();
  1206.         var l = i.findTransportTypes(o, r, u);
  1207.         var h = {
  1208.             version: o,
  1209.             minimumVersion: o,
  1210.             channel: "/meta/handshake",
  1211.             supportedConnectionTypes: l,
  1212.             _callback: n,
  1213.             advice: {
  1214.                 timeout: m.timeout,
  1215.                 interval: m.interval
  1216.             }
  1217.         };
  1218.         var p = t._mixin(false, {}, g, h);
  1219.         if (!s) {
  1220.             s = i.negotiateTransport(l, o, r, u);
  1221.             if (!s) {
  1222.                 var d = "Could not find initial transport among: " + i.getTransportTypes();
  1223.                 t._warn(d);
  1224.                 throw d
  1225.             }
  1226.         }
  1227.         t._debug("Initial transport is", s.getType());
  1228.         M("handshaking");
  1229.         t._debug("Handshake sent", p);
  1230.         z(false, [p], false, "handshake")
  1231.     }
  1232.     function nt() {
  1233.         M("handshaking");
  1234.         c = true;
  1235.         q(function () {
  1236.             tt(g, y)
  1237.         })
  1238.     }
  1239.     function rt(e) {
  1240.         var n = b[e.id];
  1241.         if (N(n)) {
  1242.             delete b[e.id];
  1243.             n.call(t, e)
  1244.         }
  1245.     }
  1246.     function it(e) {
  1247.         rt(e);
  1248.         F("/meta/handshake", e);
  1249.         F("/meta/unsuccessful", e);
  1250.         var t = !_() && m.reconnect !== "none";
  1251.         if (t) {
  1252.             V();
  1253.             nt()
  1254.         } else {
  1255.             Z(false)
  1256.         }
  1257.     }
  1258.     function st(e) {
  1259.         if (e.successful) {
  1260.             a = e.clientId;
  1261.             var n = t.getURL();
  1262.             var o = i.negotiateTransport(e.supportedConnectionTypes, e.version, r, n);
  1263.             if (o === null) {
  1264.                 var u = "Could not negotiate transport with server; client=[" + i.findTransportTypes(e.version, r, n) + "], server=[" + e.supportedConnectionTypes + "]";
  1265.                 var f = t.getTransport();
  1266.                 et(f.getType(), null, {
  1267.                     reason: u,
  1268.                     connectionType: f.getType(),
  1269.                     transport: f
  1270.                 });
  1271.                 t._warn(u);
  1272.                 Z(true);
  1273.                 return
  1274.             } else if (s !== o) {
  1275.                 t._debug("Transport", s.getType(), "->", o.getType());
  1276.                 s = o
  1277.             }
  1278.             c = false;
  1279.             J();
  1280.             e.reestablish = w;
  1281.             w = true;
  1282.             rt(e);
  1283.             F("/meta/handshake", e);
  1284.             var l = _() ? "none" : m.reconnect;
  1285.             switch (l) {
  1286.             case "retry":
  1287.                 X();
  1288.                 G();
  1289.                 break;
  1290.             case "none":
  1291.                 Z(false);
  1292.                 break;
  1293.             default:
  1294.                 throw "Unrecognized advice action " + l
  1295.             }
  1296.         } else {
  1297.             it(e)
  1298.         }
  1299.     }
  1300.     function ot(e) {
  1301.         var n = "1.0";
  1302.         var o = t.getURL();
  1303.         var u = t.getTransport();
  1304.         var a = i.findTransportTypes(n, r, o);
  1305.         var f = i.negotiateTransport(a, n, r, o);
  1306.         if (!f) {
  1307.             et(u.getType(), null, e.failure);
  1308.             t._warn("Could not negotiate transport; client=[" + a + "]");
  1309.             Z(true);
  1310.             it(e)
  1311.         } else {
  1312.             t._debug("Transport", u.getType(), "->", f.getType());
  1313.             et(u.getType(), f.getType(), e.failure);
  1314.             it(e);
  1315.             s = f
  1316.         }
  1317.     }
  1318.     function ut(e) {
  1319.         F("/meta/connect", e);
  1320.         F("/meta/unsuccessful", e);
  1321.         var t = _() ? "none" : m.reconnect;
  1322.         switch (t) {
  1323.         case "retry":
  1324.             G();
  1325.             V();
  1326.             break;
  1327.         case "handshake":
  1328.             i.reset();
  1329.             X();
  1330.             nt();
  1331.             break;
  1332.         case "none":
  1333.             Z(false);
  1334.             break;
  1335.         default:
  1336.             throw "Unrecognized advice action" + t
  1337.         }
  1338.     }
  1339.     function at(e) {
  1340.         E = e.successful;
  1341.         if (E) {
  1342.             F("/meta/connect", e);
  1343.             var t = _() ? "none" : m.reconnect;
  1344.             switch (t) {
  1345.             case "retry":
  1346.                 X();
  1347.                 G();
  1348.                 break;
  1349.             case "none":
  1350.                 Z(false);
  1351.                 break;
  1352.             default:
  1353.                 throw "Unrecognized advice action " + t
  1354.             }
  1355.         } else {
  1356.             ut(e)
  1357.         }
  1358.     }
  1359.     function ft(e) {
  1360.         E = false;
  1361.         ut(e)
  1362.     }
  1363.     function lt(e) {
  1364.         Z(true);
  1365.         rt(e);
  1366.         F("/meta/disconnect", e);
  1367.         F("/meta/unsuccessful", e)
  1368.     }
  1369.     function ct(e) {
  1370.         if (e.successful) {
  1371.             Z(false);
  1372.             rt(e);
  1373.             F("/meta/disconnect", e)
  1374.         } else {
  1375.             lt(e)
  1376.         }
  1377.     }
  1378.     function ht(e) {
  1379.         lt(e)
  1380.     }
  1381.     function pt(e) {
  1382.         var n = h[e.subscription];
  1383.         if (n) {
  1384.             for (var r = n.length - 1; r >= 0; --r) {
  1385.                 var i = n[r];
  1386.                 if (i && !i.listener) {
  1387.                     delete n[r];
  1388.                     t._debug("Removed failed subscription", i);
  1389.                     break
  1390.                 }
  1391.             }
  1392.         }
  1393.         rt(e);
  1394.         F("/meta/subscribe", e);
  1395.         F("/meta/unsuccessful", e)
  1396.     }
  1397.     function dt(e) {
  1398.         if (e.successful) {
  1399.             rt(e);
  1400.             F("/meta/subscribe", e)
  1401.         } else {
  1402.             pt(e)
  1403.         }
  1404.     }
  1405.     function vt(e) {
  1406.         pt(e)
  1407.     }
  1408.     function mt(e) {
  1409.         rt(e);
  1410.         F("/meta/unsubscribe", e);
  1411.         F("/meta/unsuccessful", e)
  1412.     }
  1413.     function gt(e) {
  1414.         if (e.successful) {
  1415.             rt(e);
  1416.             F("/meta/unsubscribe", e)
  1417.         } else {
  1418.             mt(e)
  1419.         }
  1420.     }
  1421.     function yt(e) {
  1422.         mt(e)
  1423.     }
  1424.     function bt(e) {
  1425.         rt(e);
  1426.         F("/meta/publish", e);
  1427.         F("/meta/unsuccessful", e)
  1428.     }
  1429.     function wt(e) {
  1430.         if (e.successful === undefined) {
  1431.             if (e.data !== undefined) {
  1432.                 F(e.channel, e)
  1433.             } else {
  1434.                 t._warn("Unknown Bayeux Message", e)
  1435.             }
  1436.         } else {
  1437.             if (e.successful) {
  1438.                 rt(e);
  1439.                 F("/meta/publish", e)
  1440.             } else {
  1441.                 bt(e)
  1442.             }
  1443.         }
  1444.     }
  1445.     function Et(e) {
  1446.         bt(e)
  1447.     }
  1448.     function St(e) {
  1449.         e = H(e);
  1450.         if (e === undefined || e === null) {
  1451.             return
  1452.         }
  1453.         Y(e.advice);
  1454.         var t = e.channel;
  1455.         switch (t) {
  1456.         case "/meta/handshake":
  1457.             st(e);
  1458.             break;
  1459.         case "/meta/connect":
  1460.             at(e);
  1461.             break;
  1462.         case "/meta/disconnect":
  1463.             ct(e);
  1464.             break;
  1465.         case "/meta/subscribe":
  1466.             dt(e);
  1467.             break;
  1468.         case "/meta/unsubscribe":
  1469.             gt(e);
  1470.             break;
  1471.         default:
  1472.             wt(e);
  1473.             break
  1474.         }
  1475.     }
  1476.     function xt(e) {
  1477.         var t = h[e];
  1478.         if (t) {
  1479.             for (var n = 0; n < t.length; ++n) {
  1480.                 if (t[n]) {
  1481.                     return true
  1482.                 }
  1483.             }
  1484.         }
  1485.         return false
  1486.     }
  1487.     function Tt(e, t) {
  1488.         var n = {
  1489.             scope: e,
  1490.             method: t
  1491.         };
  1492.         if (N(e)) {
  1493.             n.scope = undefined;
  1494.             n.method = e
  1495.         } else {
  1496.             if (T(t)) {
  1497.                 if (!e) {
  1498.                     throw "Invalid scope " + e
  1499.                 }
  1500.                 n.method = e[t];
  1501.                 if (!N(n.method)) {
  1502.                     throw "Invalid callback " + t + " for scope " + e
  1503.                 }
  1504.             } else if (!N(t)) {
  1505.                 throw "Invalid callback " + t
  1506.             }
  1507.         }
  1508.         return n
  1509.     }
  1510.     function Nt(e, n, r, i) {
  1511.         var s = Tt(n, r);
  1512.         t._debug("Adding", i ? "listener" : "subscription", "on", e, "with scope", s.scope, "and callback", s.method);
  1513.         var o = {
  1514.             channel: e,
  1515.             scope: s.scope,
  1516.             callback: s.method,
  1517.             listener: i
  1518.         };
  1519.         var u = h[e];
  1520.         if (!u) {
  1521.             u = [];
  1522.             h[e] = u
  1523.         }
  1524.         o.id = u.push(o) - 1;
  1525.         t._debug("Added", i ? "listener" : "subscription", o);
  1526.         o[0] = e;
  1527.         o[1] = o.id;
  1528.         return o
  1529.     }
  1530.     var t = this;
  1531.     var n = e || "default";
  1532.     var r = false;
  1533.     var i = new org.cometd.TransportRegistry;
  1534.     var s;
  1535.     var o = "disconnected";
  1536.     var u = 0;
  1537.     var a = null;
  1538.     var f = 0;
  1539.     var l = [];
  1540.     var c = false;
  1541.     var h = {};
  1542.     var p = 0;
  1543.     var d = null;
  1544.     var v = [];
  1545.     var m = {};
  1546.     var g;
  1547.     var y;
  1548.     var b = {};
  1549.     var w = false;
  1550.     var E = false;
  1551.     var S = {
  1552.         protocol: null,
  1553.         stickyReconnect: true,
  1554.         connectTimeout: 0,
  1555.         maxConnections: 2,
  1556.         backoffIncrement: 1e3,
  1557.         maxBackoff: 6e4,
  1558.         logLevel: "info",
  1559.         reverseIncomingExtensions: true,
  1560.         maxNetworkDelay: 1e4,
  1561.         requestHeaders: {},
  1562.         appendMessageTypeToURL: true,
  1563.         autoBatch: false,
  1564.         advice: {
  1565.             timeout: 6e4,
  1566.             interval: 0,
  1567.             reconnect: "retry"
  1568.         }
  1569.     };
  1570.     this._mixin = function (e, t, n) {
  1571.         var r = t || {};
  1572.         for (var i = 2; i < arguments.length; ++i) {
  1573.             var s = arguments[i];
  1574.             if (s === undefined || s === null) {
  1575.                 continue
  1576.             }
  1577.             for (var o in s) {
  1578.                 var u = x(s, o);
  1579.                 var a = x(r, o);
  1580.                 if (u === t) {
  1581.                     continue
  1582.                 }
  1583.                 if (u === undefined) {
  1584.                     continue
  1585.                 }
  1586.                 if (e && typeof u === "object" && u !== null) {
  1587.                     if (u instanceof Array) {
  1588.                         r[o] = this._mixin(e, a instanceof Array ? a : [], u)
  1589.                     } else {
  1590.                         var f = typeof a === "object" && !(a instanceof Array) ? a : {};
  1591.                         r[o] = this._mixin(e, f, u)
  1592.                     }
  1593.                 } else {
  1594.                     r[o] = u
  1595.                 }
  1596.             }
  1597.         }
  1598.         return r
  1599.     };
  1600.     this._warn = function () {
  1601.         C("warn", arguments)
  1602.     };
  1603.     this._info = function () {
  1604.         if (S.logLevel !== "warn") {
  1605.             C("info", arguments)
  1606.         }
  1607.     };
  1608.     this._debug = function () {
  1609.         if (S.logLevel === "debug") {
  1610.             C("debug", arguments)
  1611.         }
  1612.     };
  1613.     this._isCrossDomain = function (e) {
  1614.         return e && e !== window.location.host
  1615.     };
  1616.     var R;
  1617.     var U;
  1618.     this.send = W;
  1619.     this.receive = St;
  1620.     R = function (e) {
  1621.         t._debug("Received", e);
  1622.         for (var n = 0; n < e.length; ++n) {
  1623.             var r = e[n];
  1624.             St(r)
  1625.         }
  1626.     };
  1627.     U = function (e, n, r) {
  1628.         t._debug("handleFailure", e, n, r);
  1629.         r.transport = e;
  1630.         for (var i = 0; i < n.length; ++i) {
  1631.             var s = n[i];
  1632.             var o = {
  1633.                 id: s.id,
  1634.                 successful: false,
  1635.                 channel: s.channel,
  1636.                 failure: r
  1637.             };
  1638.             r.message = s;
  1639.             switch (s.channel) {
  1640.             case "/meta/handshake":
  1641.                 ot(o);
  1642.                 break;
  1643.             case "/meta/connect":
  1644.                 ft(o);
  1645.                 break;
  1646.             case "/meta/disconnect":
  1647.                 ht(o);
  1648.                 break;
  1649.             case "/meta/subscribe":
  1650.                 o.subscription = s.subscription;
  1651.                 vt(o);
  1652.                 break;
  1653.             case "/meta/unsubscribe":
  1654.                 o.subscription = s.subscription;
  1655.                 yt(o);
  1656.                 break;
  1657.             default:
  1658.                 Et(o);
  1659.                 break
  1660.             }
  1661.         }
  1662.     };
  1663.     this.registerTransport = function (e, t, n) {
  1664.         var r = i.add(e, t, n);
  1665.         if (r) {
  1666.             this._debug("Registered transport", e);
  1667.             if (N(t.registered)) {
  1668.                 t.registered(e, this)
  1669.             }
  1670.         }
  1671.         return r
  1672.     };
  1673.     this.getTransportTypes = function () {
  1674.         return i.getTransportTypes()
  1675.     };
  1676.     this.unregisterTransport = function (e) {
  1677.         var t = i.remove(e);
  1678.         if (t !== null) {
  1679.             this._debug("Unregistered transport", e);
  1680.             if (N(t.unregistered)) {
  1681.                 t.unregistered()
  1682.             }
  1683.         }
  1684.         return t
  1685.     };
  1686.     this.unregisterTransports = function () {
  1687.         i.clear()
  1688.     };
  1689.     this.findTransport = function (e) {
  1690.         return i.find(e)
  1691.     };
  1692.     this.configure = function (e) {
  1693.         k.call(this, e)
  1694.     };
  1695.     this.init = function (e, t) {
  1696.         this.configure(e);
  1697.         this.handshake(t)
  1698.     };
  1699.     this.handshake = function (e, t) {
  1700.         M("disconnected");
  1701.         w = false;
  1702.         tt(e, t)
  1703.     };
  1704.     this.disconnect = function (e, t, n) {
  1705.         if (_()) {
  1706.             return
  1707.         }
  1708.         if (typeof e !== "boolean") {
  1709.             n = t;
  1710.             t = e;
  1711.             e = false
  1712.         }
  1713.         if (N(t)) {
  1714.             n = t;
  1715.             t = undefined
  1716.         }
  1717.         var r = {
  1718.             channel: "/meta/disconnect",
  1719.             _callback: n
  1720.         };
  1721.         var i = this._mixin(false, {}, t, r);
  1722.         M("disconnecting");
  1723.         z(e === true, [i], false, "disconnect")
  1724.     };
  1725.     this.startBatch = function () {
  1726.         $()
  1727.     };
  1728.     this.endBatch = function () {
  1729.         K()
  1730.     };
  1731.     this.batch = function (e, t) {
  1732.         var n = Tt(e, t);
  1733.         this.startBatch();
  1734.         try {
  1735.             n.method.call(n.scope);
  1736.             this.endBatch()
  1737.         } catch (r) {
  1738.             this._info("Exception during execution of batch", r);
  1739.             this.endBatch();
  1740.             throw r
  1741.         }
  1742.     };
  1743.     this.addListener = function (e, t, n) {
  1744.         if (arguments.length < 2) {
  1745.             throw "Illegal arguments number: required 2, got " + arguments.length
  1746.         }
  1747.         if (!T(e)) {
  1748.             throw "Illegal argument type: channel must be a string"
  1749.         }
  1750.         return Nt(e, t, n, true)
  1751.     };
  1752.     this.removeListener = function (e) {
  1753.         if (!e || !e.channel || !("id" in e)) {
  1754.             throw "Invalid argument: expected subscription, not " + e
  1755.         }
  1756.         L(e)
  1757.     };
  1758.     this.clearListeners = function () {
  1759.         h = {}
  1760.     };
  1761.     this.subscribe = function (e, t, n, r, i) {
  1762.         if (arguments.length < 2) {
  1763.             throw "Illegal arguments number: required 2, got " + arguments.length
  1764.         }
  1765.         if (!T(e)) {
  1766.             throw "Illegal argument type: channel must be a string"
  1767.         }
  1768.         if (_()) {
  1769.             throw "Illegal state: already disconnected"
  1770.         }
  1771.         if (N(t)) {
  1772.             i = r;
  1773.             r = n;
  1774.             n = t;
  1775.             t = undefined
  1776.         }
  1777.         if (N(r)) {
  1778.             i = r;
  1779.             r = undefined
  1780.         }
  1781.         var s = !xt(e);
  1782.         var o = Nt(e, t, n, false);
  1783.         if (s) {
  1784.             var u = {
  1785.                 channel: "/meta/subscribe",
  1786.                 subscription: e,
  1787.                 _callback: i
  1788.             };
  1789.             var a = this._mixin(false, {}, r, u);
  1790.             W(a)
  1791.         }
  1792.         return o
  1793.     };
  1794.     this.unsubscribe = function (e, t, n) {
  1795.         if (arguments.length < 1) {
  1796.             throw "Illegal arguments number: required 1, got " + arguments.length
  1797.         }
  1798.         if (_()) {
  1799.             throw "Illegal state: already disconnected"
  1800.         }
  1801.         if (N(t)) {
  1802.             n = t;
  1803.             t = undefined
  1804.         }
  1805.         this.removeListener(e);
  1806.         var r = e.channel;
  1807.         if (!xt(r)) {
  1808.             var i = {
  1809.                 channel: "/meta/unsubscribe",
  1810.                 subscription: r,
  1811.                 _callback: n
  1812.             };
  1813.             var s = this._mixin(false, {}, t, i);
  1814.             W(s)
  1815.         }
  1816.     };
  1817.     this.resubscribe = function (e, t) {
  1818.         A(e);
  1819.         if (e) {
  1820.             return this.subscribe(e.channel, e.scope, e.callback, t)
  1821.         }
  1822.         return undefined
  1823.     };
  1824.     this.clearSubscriptions = function () {
  1825.         O()
  1826.     };
  1827.     this.publish = function (e, t, n, r) {
  1828.         if (arguments.length < 1) {
  1829.             throw "Illegal arguments number: required 1, got " + arguments.length
  1830.         }
  1831.         if (!T(e)) {
  1832.             throw "Illegal argument type: channel must be a string"
  1833.         }
  1834.         if (/^\/meta\//.test(e)) {
  1835.             throw "Illegal argument: cannot publish to meta channels"
  1836.         }
  1837.         if (_()) {
  1838.             throw "Illegal state: already disconnected"
  1839.         }
  1840.         if (N(t)) {
  1841.             r = t;
  1842.             t = n = {}
  1843.         } else if (N(n)) {
  1844.             r = n;
  1845.             n = {}
  1846.         }
  1847.         var i = {
  1848.             channel: e,
  1849.             data: t,
  1850.             _callback: r
  1851.         };
  1852.         var s = this._mixin(false, {}, n, i);
  1853.         W(s)
  1854.     };
  1855.     this.getStatus = function () {
  1856.         return o
  1857.     };
  1858.     this.isDisconnected = _;
  1859.     this.setBackoffIncrement = function (e) {
  1860.         S.backoffIncrement = e
  1861.     };
  1862.     this.getBackoffIncrement = function () {
  1863.         return S.backoffIncrement
  1864.     };
  1865.     this.getBackoffPeriod = function () {
  1866.         return p
  1867.     };
  1868.     this.setLogLevel = function (e) {
  1869.         S.logLevel = e
  1870.     };
  1871.     this.registerExtension = function (e, t) {
  1872.         if (arguments.length < 2) {
  1873.             throw "Illegal arguments number: required 2, got " + arguments.length
  1874.         }
  1875.         if (!T(e)) {
  1876.             throw "Illegal argument type: extension name must be a string"
  1877.         }
  1878.         var n = false;
  1879.         for (var r = 0; r < v.length; ++r) {
  1880.             var i = v[r];
  1881.             if (i.name === e) {
  1882.                 n = true;
  1883.                 break
  1884.             }
  1885.         }
  1886.         if (!n) {
  1887.             v.push({
  1888.                 name: e,
  1889.                 extension: t
  1890.             });
  1891.             this._debug("Registered extension", e);
  1892.             if (N(t.registered)) {
  1893.                 t.registered(e, this)
  1894.             }
  1895.             return true
  1896.         } else {
  1897.             this._info("Could not register extension with name", e, "since another extension with the same name already exists");
  1898.             return false
  1899.         }
  1900.     };
  1901.     this.unregisterExtension = function (e) {
  1902.         if (!T(e)) {
  1903.             throw "Illegal argument type: extension name must be a string"
  1904.         }
  1905.         var t = false;
  1906.         for (var n = 0; n < v.length; ++n) {
  1907.             var r = v[n];
  1908.             if (r.name === e) {
  1909.                 v.splice(n, 1);
  1910.                 t = true;
  1911.                 this._debug("Unregistered extension", e);
  1912.                 var i = r.extension;
  1913.                 if (N(i.unregistered)) {
  1914.                     i.unregistered()
  1915.                 }
  1916.                 break
  1917.             }
  1918.         }
  1919.         return t
  1920.     };
  1921.     this.getExtension = function (e) {
  1922.         for (var t = 0; t < v.length; ++t) {
  1923.             var n = v[t];
  1924.             if (n.name === e) {
  1925.                 return n.extension
  1926.             }
  1927.         }
  1928.         return null
  1929.     };
  1930.     this.getName = function () {
  1931.         return n
  1932.     };
  1933.     this.getClientId = function () {
  1934.         return a
  1935.     };
  1936.     this.getURL = function () {
  1937.         if (s && typeof S.urls === "object") {
  1938.             var e = S.urls[s.getType()];
  1939.             if (e) {
  1940.                 return e
  1941.             }
  1942.         }
  1943.         return S.url
  1944.     };
  1945.     this.getTransport = function () {
  1946.         return s
  1947.     };
  1948.     this.getConfiguration = function () {
  1949.         return this._mixin(true, {}, S)
  1950.     };
  1951.     this.getAdvice = function () {
  1952.         return this._mixin(true, {}, m)
  1953.     };
  1954.     org.cometd.WebSocket = window.WebSocket;
  1955.     if (!org.cometd.WebSocket) {
  1956.         org.cometd.WebSocket = window.MozWebSocket
  1957.     }
  1958. };
  1959. if (typeof define === "function" && define.amd) {
  1960.     define(function () {
  1961.         return org.cometd
  1962.     })
  1963. }(function () {
  1964.     function e(e) {
  1965.         return e.AckExtension = function () {
  1966.             function r(t, n) {
  1967.                 e._debug(t, n)
  1968.             }
  1969.             var e;
  1970.             var t = false;
  1971.             var n = -1;
  1972.             this.registered = function (t, n) {
  1973.                 e = n;
  1974.                 r("AckExtension: executing registration callback")
  1975.             };
  1976.             this.unregistered = function () {
  1977.                 r("AckExtension: executing unregistration callback");
  1978.                 e = null
  1979.             };
  1980.             this.incoming = function (e) {
  1981.                 var i = e.channel;
  1982.                 if (i == "/meta/handshake") {
  1983.                     t = e.ext && e.ext.ack;
  1984.                     r("AckExtension: server supports acks", t)
  1985.                 } else if (t && i == "/meta/connect" && e.successful) {
  1986.                     var s = e.ext;
  1987.                     if (s && typeof s.ack === "number") {
  1988.                         n = s.ack;
  1989.                         r("AckExtension: server sent ack id", n)
  1990.                     }
  1991.                 }
  1992.                 return e
  1993.             };
  1994.             this.outgoing = function (i) {
  1995.                 var s = i.channel;
  1996.                 if (s == "/meta/handshake") {
  1997.                     if (!i.ext) {
  1998.                         i.ext = {}
  1999.                     }
  2000.                     i.ext.ack = e && e.ackEnabled !== false;
  2001.                     n = -1
  2002.                 } else if (t && s == "/meta/connect") {
  2003.                     if (!i.ext) {
  2004.                         i.ext = {}
  2005.                     }
  2006.                     i.ext.ack = n;
  2007.                     r("AckExtension: client sending ack id", n)
  2008.                 }
  2009.                 return i
  2010.             }
  2011.         }
  2012.     }
  2013.     if (typeof define === "function" && define.amd) {
  2014.         define(["org/cometd"], e)
  2015.     } else {
  2016.         e(org.cometd)
  2017.     }
  2018. })();
  2019. (function () {
  2020.     function e(e) {
  2021.         return e.TimeSyncExtension = function (t) {
  2022.             function a(e, t) {
  2023.                 n._debug(e, t)
  2024.             }
  2025.             var n;
  2026.             var r = t && t.maxSamples || 10;
  2027.             var i = [];
  2028.             var s = [];
  2029.             var o = 0;
  2030.             var u = 0;
  2031.             this.registered = function (e, t) {
  2032.                 n = t;
  2033.                 a("TimeSyncExtension: executing registration callback")
  2034.             };
  2035.             this.unregistered = function () {
  2036.                 a("TimeSyncExtension: executing unregistration callback");
  2037.                 n = null;
  2038.                 i = [];
  2039.                 s = []
  2040.             };
  2041.             this.incoming = function (e) {
  2042.                 var t = e.channel;
  2043.                 if (t && t.indexOf("/meta/") === 0) {
  2044.                     if (e.ext && e.ext.timesync) {
  2045.                         var n = e.ext.timesync;
  2046.                         a("TimeSyncExtension: server sent timesync", n);
  2047.                         var f = (new Date).getTime();
  2048.                         var l = (f - n.tc - n.p) / 2;
  2049.                         var c = n.ts - n.tc - l;
  2050.                         i.push(l);
  2051.                         s.push(c);
  2052.                         if (s.length > r) {
  2053.                             s.shift();
  2054.                             i.shift()
  2055.                         }
  2056.                         var h = s.length;
  2057.                         var p = 0;
  2058.                         var d = 0;
  2059.                         for (var v = 0; v < h; ++v) {
  2060.                             p += i[v];
  2061.                             d += s[v]
  2062.                         }
  2063.                         o = parseInt((p / h).toFixed());
  2064.                         u = parseInt((d / h).toFixed());
  2065.                         a("TimeSyncExtension: network lag", o, "ms, time offset with server", u, "ms", o, u)
  2066.                     }
  2067.                 }
  2068.                 return e
  2069.             };
  2070.             this.outgoing = function (t) {
  2071.                 var n = t.channel;
  2072.                 if (n && n.indexOf("/meta/") === 0) {
  2073.                     if (!t.ext) {
  2074.                         t.ext = {}
  2075.                     }
  2076.                     t.ext.timesync = {
  2077.                         tc: (new Date).getTime(),
  2078.                         l: o,
  2079.                         o: u
  2080.                     };
  2081.                     a("TimeSyncExtension: client sending timesync", e.JSON.toJSON(t.ext.timesync))
  2082.                 }
  2083.                 return t
  2084.             };
  2085.             this.getTimeOffset = function () {
  2086.                 return u
  2087.             };
  2088.             this.getTimeOffsetSamples = function () {
  2089.                 return s
  2090.             };
  2091.             this.getNetworkLag = function () {
  2092.                 return o
  2093.             };
  2094.             this.getServerTime = function () {
  2095.                 return (new Date).getTime() + u
  2096.             };
  2097.             this.getServerDate = function () {
  2098.                 return new Date(this.getServerTime())
  2099.             };
  2100.             this.setTimeout = function (t, r) {
  2101.                 var i = r instanceof Date ? r.getTime() : 0 + r;
  2102.                 var s = i - u;
  2103.                 var o = s - (new Date).getTime();
  2104.                 if (o <= 0) {
  2105.                     o = 1
  2106.                 }
  2107.                 return e.Utils.setTimeout(n, t, o)
  2108.             }
  2109.         }
  2110.     }
  2111.     if (typeof define === "function" && define.amd) {
  2112.         define(["org/cometd"], e)
  2113.     } else {
  2114.         e(org.cometd)
  2115.     }
  2116. })();
  2117. (function () {
  2118.     function e(e, t) {
  2119.         function n(e, t) {
  2120.             if (t) {
  2121.                 for (var n in t) {
  2122.                     if (n.toLowerCase() === "content-type") {
  2123.                         continue
  2124.                     }
  2125.                     e.setRequestHeader(n, t[n])
  2126.                 }
  2127.             }
  2128.         }
  2129.         function r() {
  2130.             var r = new t.LongPollingTransport;
  2131.             var i = t.Transport.derive(r);
  2132.             i.xhrSend = function (t) {
  2133.                 return e.ajax({
  2134.                     url: t.url,
  2135.                     async: t.sync !== true,
  2136.                     type: "POST",
  2137.                     contentType: "application/json;charset=UTF-8",
  2138.                     data: t.body,
  2139.                     xhrFields: {
  2140.                         withCredentials: true
  2141.                     },
  2142.                     beforeSend: function (e) {
  2143.                         n(e, t.headers);
  2144.                         return true
  2145.                     },
  2146.                     success: t.onSuccess,
  2147.                     error: function (e, n, r) {
  2148.                         t.onError(n, r)
  2149.                     }
  2150.                 })
  2151.             };
  2152.             return i
  2153.         }
  2154.         function i() {
  2155.             var r = new t.CallbackPollingTransport;
  2156.             var i = t.Transport.derive(r);
  2157.             i.jsonpSend = function (t) {
  2158.                 e.ajax({
  2159.                     url: t.url,
  2160.                     async: t.sync !== true,
  2161.                     type: "GET",
  2162.                     dataType: "jsonp",
  2163.                     jsonp: "jsonp",
  2164.                     data: {
  2165.                         message: t.body
  2166.                     },
  2167.                     beforeSend: function (e) {
  2168.                         n(e, t.headers);
  2169.                         return true
  2170.                     },
  2171.                     success: t.onSuccess,
  2172.                     error: function (e, n, r) {
  2173.                         t.onError(n, r)
  2174.                     }
  2175.                 })
  2176.             };
  2177.             return i
  2178.         }
  2179.         t.JSON.toJSON = JSON.stringify;
  2180.         t.JSON.fromJSON = JSON.parse;
  2181.         e.Cometd = function (e) {
  2182.             var n = new t.Cometd(e);
  2183.             if (t.WebSocket) {
  2184.                 n.registerTransport("ssl-websocket", new t.WebSocketTransport)
  2185.             }
  2186.             n.registerTransport("long-polling", new r);
  2187.             n.registerTransport("ssl-long-polling", new r);
  2188.             n.registerTransport("callback-polling", new i);
  2189.             return n
  2190.         };
  2191.         e.cometd = new e.Cometd;
  2192.         return e.cometd
  2193.     }
  2194.     if (typeof define === "function" && define.amd) {
  2195.         define(["jquery", "org/cometd"], e)
  2196.     } else {
  2197.         e(jQuery, org.cometd)
  2198.     }
  2199. })();
  2200. (function () {
  2201.     function e(e, t) {
  2202.         var n = new e;
  2203.         t.registerExtension("ack", n);
  2204.         return n
  2205.     }
  2206.     if (typeof define === "function" && define.amd) {
  2207.         define(["org/cometd/AckExtension", "jquery.cometd"], e)
  2208.     } else {
  2209.         e(org.cometd.AckExtension, jQuery.cometd)
  2210.     }
  2211. })();
  2212. (function () {
  2213.     function e(e, t) {
  2214.         var n = new e;
  2215.         t.registerExtension("timesync", n);
  2216.         return n
  2217.     }
  2218.     if (typeof define === "function" && define.amd) {
  2219.         define(["org/cometd/TimeSyncExtension", "jquery.cometd"], e)
  2220.     } else {
  2221.         e(org.cometd.TimeSyncExtension, jQuery.cometd)
  2222.     }
  2223. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement