Skip to content
This repository
Browse code

Update generated files

  • Loading branch information...
commit aa169bfa008ff1bc8087f27de25847214a7fd609 1 parent 14d8a0a
Paweł Chmielowski authored March 14, 2012

Showing 2 changed files with 91 additions and 37 deletions. Show diff stats Hide diff stats

  1. 93  p1pp.js
  2. 35  p1pp.js.min
93  p1pp.js
@@ -15,6 +15,7 @@ var P1PP = function(params){
15 15
     domain: "p1pp.net",
16 16
     pubsub_domain: "pubsub.p1pp.net",
17 17
     ws_url: "ws://a.p1pp.net/xmpp",
  18
+    flash_ws_url: "ws://p1pp.net:5280/xmpp",
18 19
     bosh_url: "http://a.p1pp.net/http-bind",
19 20
     connect_timeout: 15000, //How long should we wait before trying BOSH ?
20 21
     connect_delay: 0,       //Connection will not be done before this number of ms
@@ -2704,10 +2705,10 @@ Strophe.Connection.prototype = {
2704 2705
 
2705 2706
     /** Function: flush
2706 2707
      *  Immediately send any pending outgoing data.
2707  
-     *  
  2708
+     *
2708 2709
      *  Normally send() queues outgoing data until the next idle period
2709 2710
      *  (100ms), which optimizes network use in the common cases when
2710  
-     *  several send()s are called in succession. flush() can be used to 
  2711
+     *  several send()s are called in succession. flush() can be used to
2711 2712
      *  immediately send all pending data.
2712 2713
      */
2713 2714
     flush: function ()
@@ -2724,9 +2725,9 @@ Strophe.Connection.prototype = {
2724 2725
      *  Parameters:
2725 2726
      *    (XMLElement) elem - The stanza to send.
2726 2727
      *    (Function) callback - The callback function for a successful request.
2727  
-     *    (Function) errback - The callback function for a failed or timed 
  2728
+     *    (Function) errback - The callback function for a failed or timed
2728 2729
      *      out request.  On timeout, the stanza will be null.
2729  
-     *    (Integer) timeout - The time specified in milliseconds for a 
  2730
+     *    (Integer) timeout - The time specified in milliseconds for a
2730 2731
      *      timeout to occur.
2731 2732
      *
2732 2733
      *  Returns:
@@ -2800,7 +2801,7 @@ Strophe.Connection.prototype = {
2800 2801
                 message: "Cannot queue non-DOMElement."
2801 2802
             };
2802 2803
         }
2803  
-        
  2804
+
2804 2805
         this._data.push(element);
2805 2806
     },
2806 2807
 
@@ -2883,7 +2884,7 @@ Strophe.Connection.prototype = {
2883 2884
      *  boolean). When matchBare is true, the from parameter and the from
2884 2885
      *  attribute on the stanza will be matched as bare JIDs instead of
2885 2886
      *  full JIDs. To use this, pass {matchBare: true} as the value of
2886  
-     *  options. The default value for matchBare is false. 
  2887
+     *  options. The default value for matchBare is false.
2887 2888
      *
2888 2889
      *  The return value should be saved if you wish to remove the handler
2889 2890
      *  with deleteHandler().
@@ -3496,7 +3497,7 @@ Strophe.Connection.prototype = {
3496 3497
         if (hold) { this.hold = parseInt(hold, 10); }
3497 3498
         var wait = bodyWrap.getAttribute('wait');
3498 3499
         if (wait) { this.wait = parseInt(wait, 10); }
3499  
-        
  3500
+
3500 3501
 
3501 3502
         var do_sasl_plain = false;
3502 3503
         var do_sasl_digest_md5 = false;
@@ -3696,7 +3697,7 @@ Strophe.Connection.prototype = {
3696 3697
      */
3697 3698
     _quote: function (str)
3698 3699
     {
3699  
-        return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"'; 
  3700
+        return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
3700 3701
         //" end string workaround for emacs
3701 3702
     },
3702 3703
 
@@ -4134,7 +4135,8 @@ Strophe.Connection.prototype = {
4134 4135
         clearTimeout(this._idleTimeout);
4135 4136
         this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
4136 4137
     }
4137  
-};/*
  4138
+};
  4139
+/*
4138 4140
   Copyright 2008, Stanziq  Inc.
4139 4141
 */
4140 4142
 
@@ -4423,6 +4425,55 @@ Strophe.addConnectionPlugin('pubsub', {
4423 4425
 	    return this._connection.sendIQ(pub.tree(),ok_callback,error_back);
4424 4426
 	}
4425 4427
 });
  4428
+Strophe.addConnectionPlugin("xdomainrequest", {
  4429
+	init: function () {
  4430
+		if (window.XDomainRequest) {
  4431
+			Strophe.debug("using XdomainRequest for IE");
  4432
+			
  4433
+			// override thee send method to fire readystate 2
  4434
+			XDomainRequest.prototype.oldsend = XDomainRequest.prototype.send;
  4435
+			XDomainRequest.prototype.send = function() {
  4436
+				XDomainRequest.prototype.oldsend.apply(this, arguments);
  4437
+				this.readyState = 2;
  4438
+				try {
  4439
+					this.onreadystatechange();
  4440
+				} catch (e) {}
  4441
+			};
  4442
+			
  4443
+			// replace Strophe.Request._newXHR with the xdomainrequest version
  4444
+			Strophe.Request.prototype._newXHR = function () {
  4445
+				var fireReadyStateChange = function (xhr, status) {
  4446
+					xhr.status = status;
  4447
+					xhr.readyState = 4;
  4448
+					try {
  4449
+						xhr.onreadystatechange();
  4450
+					} catch (e) {}
  4451
+				};
  4452
+				var xhr = new XDomainRequest();
  4453
+				
  4454
+				xhr.readyState = 0;
  4455
+				xhr.onreadystatechange = this.func.prependArg(this);
  4456
+				xhr.onload = function () {
  4457
+					xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  4458
+					xmlDoc.async = "false";
  4459
+					xmlDoc.loadXML(xhr.responseText);
  4460
+					xhr.responseXML = xmlDoc;
  4461
+					fireReadyStateChange(xhr, 200);
  4462
+				};
  4463
+				xhr.onerror = function () {
  4464
+					fireReadyStateChange(xhr, 500);
  4465
+				};
  4466
+				xhr.ontimeout = function () {
  4467
+					fireReadyStateChange(xhr, 500);
  4468
+				};
  4469
+				return xhr;
  4470
+			}
  4471
+			
  4472
+		} else {
  4473
+			Strophe.error("XDomainRequest not found. Falling back to native XHR implementation.");
  4474
+		}
  4475
+	}
  4476
+});
4426 4477
 // Contact object
4427 4478
 function Contact() {
4428 4479
     this.name = "";
@@ -6155,7 +6206,9 @@ P1PP.prototype = {
6155 6206
    */
6156 6207
   websocket: function() {
6157 6208
     try {
6158  
-      this.connection = new Strophe.WebSocket(this.params.ws_url);
  6209
+      var ws_url = ("__flash" in WebSocket && this.params.flash_ws_url) || this.params.ws_url;
  6210
+
  6211
+      this.connection = new Strophe.WebSocket(ws_url);
6159 6212
       var cookie = this.rebind_fetch();
6160 6213
       if (!!cookie && this.params.rebind) {
6161 6214
         prev_connection = cookie.split(" ");
@@ -6249,13 +6302,14 @@ P1PP.prototype = {
6249 6302
         // One of them is lying. Or both.
6250 6303
         // In the meantime, a short timeout will do the trick.
6251 6304
         var that = this;
6252  
-        setTimeout(function(){that.fetchNodes(null, false)}, 100);
  6305
+        setTimeout(function(){that.fetchNodes(null, true)}, 100);
6253 6306
       }
6254 6307
     }
6255 6308
     // Connection problem or reattach failed. Will attempt to reconnect after a random wait
6256  
-    else if (!this.closing
6257  
-            && (status === Strophe.Status.CONNFAIL
6258  
-              || status === Strophe.Status.DISCONNECTED)) {
  6309
+    else if (!this.closing &&
  6310
+             (status === Strophe.Status.CONNFAIL
  6311
+              || status === Strophe.Status.DISCONNECTED))
  6312
+    {
6259 6313
       this.connection.deleteTimedHandler(this.bosh_rebind_id);
6260 6314
       this.rebind_delete();
6261 6315
       //login is required. Give user code a chance to fetch jid and password
@@ -6267,19 +6321,16 @@ P1PP.prototype = {
6267 6321
             that.connect();
6268 6322
           }, retry_time);
6269 6323
       }
6270  
-    }
6271  
-    else if (status === Strophe.Status.DISCONNECTED) {
  6324
+    } else if (status === Strophe.Status.DISCONNECTED) {
6272 6325
       this.connection.reset();
6273 6326
       this.closing = false;
6274 6327
       this.params.on_disconnect();
6275  
-    }
6276  
-    // WebSocket rebind failed. Removing user data and reconnecting
6277  
-    else if (status === Strophe.Status.REBINDFAILED) {
  6328
+    } else if (status === Strophe.Status.REBINDFAILED) {
  6329
+      // WebSocket rebind failed. Removing user data and reconnecting
6278 6330
       this.rebind_delete();
6279 6331
       this.connection = null;
6280 6332
       this.connect();
6281  
-    }
6282  
-    else if (status === Strophe.Status.AUTHFAIL) {
  6333
+    } else if (status === Strophe.Status.AUTHFAIL) {
6283 6334
       delete this.connection;
6284 6335
       this.params.on_login_required(login_required_cb);
6285 6336
     }
35  p1pp.js.min
... ...
@@ -1,6 +1,6 @@
1  
-var WEB_SOCKET_DEBUG=!1,WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,P1PP=function(a){this.timeout_id=this.params=this.connection=this.password=this.jid=null;this.retries=0;this.closing=!1;this.defaults={flash_location:"WebSocketMain.swf",domain:"p1pp.net",pubsub_domain:"pubsub.p1pp.net",ws_url:"ws://a.p1pp.net/xmpp",bosh_url:"http://a.p1pp.net/http-bind",connect_timeout:15E3,connect_delay:0,connect_retry:10,rebind:!0,debug:!1,num_old:0,on_strophe_event:function(){},on_login_required:null,publish:function(){},
2  
-retract:function(){},on_disconnected:function(){},on_connected:function(){},cookie_opts:{},nodes:[]};this.params=function(a,c){for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);return a}(this.defaults,a);a=this.params.nodes;0<a.length&&(this.scope=MD5.hexdigest(a.join("-")));!window.console||!window.console.log||!window.console.error?this.console={log:function(){},error:function(){}}:this.params.debug&&(this.console=window.console);this.params.debug&&(window.WEB_SOCKET_DEBUG=!0);window.WEB_SOCKET_SWF_LOCATION=
3  
-this.params.flash_location;window.WebSocket&&window.WebSocket.__initialize&&window.WebSocket.__initialize();return this};P1PP.connect=function(a){this.push_client?!1==this.push_client.connection.connected&&this.push_client.connect():(this.push_client=new P1PP(a),this.push_client.connect());return this.push_client};P1PP.disconnect=function(){this.push_client.disconnect()};
  1
+var WEB_SOCKET_DEBUG=!1,WEB_SOCKET_DISABLE_AUTO_INITIALIZATION=!0,P1PP=function(a){this.timeout_id=this.params=this.connection=this.password=this.jid=null;this.retries=0;this.closing=!1;this.defaults={flash_location:"WebSocketMain.swf",domain:"p1pp.net",pubsub_domain:"pubsub.p1pp.net",ws_url:"ws://a.p1pp.net/xmpp",flash_ws_url:"ws://p1pp.net:5280/xmpp",bosh_url:"http://a.p1pp.net/http-bind",connect_timeout:15E3,connect_delay:0,connect_retry:10,rebind:!0,debug:!1,num_old:0,on_strophe_event:function(){},
  2
+on_login_required:null,publish:function(){},retract:function(){},on_disconnected:function(){},on_connected:function(){},cookie_opts:{},nodes:[]};this.params=function(a,c){for(var d in c)c.hasOwnProperty(d)&&(a[d]=c[d]);return a}(this.defaults,a);a=this.params.nodes;0<a.length&&(this.scope=MD5.hexdigest(a.join("-")));!window.console||!window.console.log||!window.console.error?this.console={log:function(){},error:function(){}}:this.params.debug&&(this.console=window.console);this.params.debug&&(window.WEB_SOCKET_DEBUG=
  3
+!0);window.WEB_SOCKET_SWF_LOCATION=this.params.flash_location;window.WebSocket&&window.WebSocket.__initialize&&window.WebSocket.__initialize();return this};P1PP.connect=function(a){this.push_client?!1==this.push_client.connection.connected&&this.push_client.connect():(this.push_client=new P1PP(a),this.push_client.connect());return this.push_client};P1PP.disconnect=function(){this.push_client.disconnect()};
4 4
 P1PP.subscribeToNode=function(a){if(this.push_client){"string"===typeof a&&(a=[a]);var b=this.push_client.params.nodes;this.merge(b,a);0<b.length&&(this.push_client.scope=MD5.hexdigest(b.join("-")));this.push_client.subscribe(a)}};P1PP.unsubscribeFromNode=function(a){if(this.push_client){"string"===typeof a&&(a=[a]);var b=P1PP.diff(this.push_client.params.nodes,channel);0<b.length&&(this.push_client.scope=MD5.hexdigest(b.join("-")));this.push_client.unsubscribe(a)}};
5 5
 P1PP.publish=function(a,b,c,d){return this.push_client?this.push_client._publish(a,b,c,d):null};P1PP.deleteNode=function(a,b){return this.push_client?this.push_client._deleteNode(a,b):null};P1PP.COOKIE="session";P1PP.couldRebind=function(){var a=["WEBSOCKET","BOSH"];for(p in a)return a=P1PP.COOKIE+"_"+a[p],window.sessionStorage?!!sessionStorage[a]:!!this.cookie(a);return!1};
6 6
 P1PP.merge=function(a,b){var c=a.length,d=0;if("number"===typeof b.length)for(var e=b.length;d<e;d++)a[c++]=b[d];else for(;void 0!==b[d];)a[c++]=b[d++];a.length=c;return a};P1PP.diff=function(a,b){return a.filter(function(a){return!(-1<b.indexOf(a))})};
@@ -107,7 +107,10 @@ d.length&&0!=d.length&&b.appendChild(g);a.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).
107 107
 r.appendChild(u);n.appendChild(r);k.appendChild(n);b=$iq({from:a,to:b,type:"set",id:f});if(d&&d.length&&0!==d.length){for(n=0;n<d.length;n++)k.appendChild(d[n]);g.appendChild(k);b.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("subscribe",{node:c,jid:a}).up().cnode(g)}else b.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("subscribe",{node:c,jid:a});this._connection.addHandler(e,null,"iq",null,f,null);this._connection.send(b.tree());return f},unsubscribe:function(a,b,c,d){var e=this._connection.getUniqueId("unsubscribenode"),
108 108
 b=$iq({from:a,to:b,type:"set",id:e});b.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("unsubscribe",{node:c,jid:a});this._connection.addHandler(d,null,"iq",null,e,null);this._connection.send(b.tree());return e},publish:function(a,b,c,d,e){var f=this._connection.getUniqueId("publishnode"),c=Strophe.xmlElement("publish",[["node",c]]),g;for(g in d){var k=Strophe.xmlElement("item",[["id",d[g].id]]);k.appendChild(d[g].value[0]);c.appendChild(k)}a=$iq({from:a,to:b,type:"set",id:f});a.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).cnode(c);
109 109
 this._connection.addHandler(e,null,"iq",null,f,null);this._connection.send(a.tree());return f},deleteNode:function(a,b,c,d){var e=this._connection.getUniqueId("deletenode"),a=$iq({from:a,to:b,type:"set",id:e});a.c("pubsub",{xmlns:Strophe.NS.PUBSUB_OWNER}).c("delete",{node:c});this._connection.addHandler(d,null,"iq",null,e,null);this._connection.send(a.tree());return e},items:function(a,b,c,d,e,f){a=$iq({from:a,to:b,type:"get"});a.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("items",{node:c,max_items:d});
110  
-return this._connection.sendIQ(a.tree(),e,f)},item:function(a,b,c,d,e,f){a=$iq({from:a,to:b,type:"get"});a.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("items",{node:c}).c("item",{id:d});return this._connection.sendIQ(a.tree(),e,f)}});function Contact(){this.name="";this.resources={};this.subscription="none";this.ask="";this.groups=[]}Contact.prototype={online:function(){var a=!1,b;for(b in this.resources){a=!0;break}return a}};
  110
+return this._connection.sendIQ(a.tree(),e,f)},item:function(a,b,c,d,e,f){a=$iq({from:a,to:b,type:"get"});a.c("pubsub",{xmlns:Strophe.NS.PUBSUB}).c("items",{node:c}).c("item",{id:d});return this._connection.sendIQ(a.tree(),e,f)}});
  111
+Strophe.addConnectionPlugin("xdomainrequest",{init:function(){window.XDomainRequest?(Strophe.debug("using XdomainRequest for IE"),XDomainRequest.prototype.oldsend=XDomainRequest.prototype.send,XDomainRequest.prototype.send=function(){XDomainRequest.prototype.oldsend.apply(this,arguments);this.readyState=2;try{this.onreadystatechange()}catch(a){}},Strophe.Request.prototype._newXHR=function(){var a=function(a,b){a.status=b;a.readyState=4;try{a.onreadystatechange()}catch(e){}},b=new XDomainRequest;b.readyState=
  112
+0;b.onreadystatechange=this.func.prependArg(this);b.onload=function(){xmlDoc=new ActiveXObject("Microsoft.XMLDOM");xmlDoc.async="false";xmlDoc.loadXML(b.responseText);b.responseXML=xmlDoc;a(b,200)};b.onerror=function(){a(b,500)};b.ontimeout=function(){a(b,500)};return b}):Strophe.error("XDomainRequest not found. Falling back to native XHR implementation.")}});function Contact(){this.name="";this.resources={};this.subscription="none";this.ask="";this.groups=[]}
  113
+Contact.prototype={online:function(){var a=!1,b;for(b in this.resources){a=!0;break}return a}};
111 114
 Strophe.addConnectionPlugin("roster",{init:function(a){this.connection=a;this.contacts={};Strophe.addNamespace("ROSTER","jabber:iq:roster")},statusChanged:function(a){if(a===Strophe.Status.CONNECTED){this.contacts={};this.connection.addHandler(this.rosterChanged.bind(this),Strophe.NS.ROSTER,"iq","set");this.connection.addHandler(this.presenceChanged.bind(this),null,"presence");var b=this;this.connection.sendIQ($iq({type:"get"}).c("query",{xmlns:Strophe.NS.ROSTER}),function(a){$(a).find("item").each(function(){var a=
112 115
 new Contact;a.name=$(this).attr("name")||"";a.subscription=$(this).attr("subscription")||"none";a.ask=$(this).attr("ask")||"";$(this).find("group").each(function(){a.groups.push($(this).text())});b.contacts[$(this).attr("jid")]=a});$(document).trigger("roster_changed",b)})}else if(a===Strophe.Status.DISCONNECTED){for(var c in this.contacts)this.contacts[c].resources={};$(document).trigger("roster_changed",this)}},rosterChanged:function(a){var b=$(a).find("item"),c=b.attr("jid"),d=b.attr("subscription")||
113 116
 "";if("remove"===d)delete this.contacts[c];else if("none"===d){var e=new Contact;e.name=b.attr("name")||"";b.find("group").each(function(){e.groups.push(this.text())});this.contacts[c]=e}else e=this.contacts[c],e.name=b.attr("name")||e.name,e.subscription=d||e.subscription,e.ask=b.attr("ask")||e.ask,e.groups=[],b.find("group").each(function(){e.groups.push(this.text())});this.connection.send($iq({type:"result",id:$(a).attr("id")}));$(document).trigger("roster_changed",this);return!0},presenceChanged:function(a){var b=
@@ -149,15 +152,15 @@ this._doDisconnect();return!1},_onIdle:function(){for(var a,b,c,d;0<this.removeT
149 152
 this._idleTimeout=setTimeout(this._onIdle.bind(this),100)}};
150 153
 P1PP.prototype={connect:function(a){var b=this,c=this.params;if(!this.connection||!this.connection.connected){this._check_rebind();var d=function(){b.retries++;b.retries>c.connectretry?b.console.log(c.connectretry+" connect retry exceeded"):(b.timeout_id=setTimeout(function(){b.connect(!0)},c.connect_timeout),!a&&c.ws_url&&window.WebSocket?(b.current_protocol="WEBSOCKET",b.websocket()):(b.current_protocol="BOSH",b.bosh()))};0==this.retries&&!a?setTimeout(d.bind(this),c.connect_delay):d()}},disconnect:function(){this.closing=
151 154
 !0;window.clearTimeout(this.timeout_id);this.rebind_delete();this.connection&&(this.connection.deleteTimedHandler(this.bosh_rebind_id),this.connection.disconnect())},bosh:function(){try{this.connection=new Strophe.Connection(this.params.bosh_url);var a=this.rebind_fetch();a&&this.params.rebind?(prev_connection=a.split(" "),"BOSH"==prev_connection[0]?this.connection.attach(prev_connection[1],prev_connection[2],prev_connection[3],this.conn_callback.bind(this)):this._transport_connect()):this._transport_connect()}catch(b){this.connect()}},
152  
-websocket:function(){try{this.connection=new Strophe.WebSocket(this.params.ws_url);var a=this.rebind_fetch();a&&this.params.rebind?(prev_connection=a.split(" "),this.connection.rebind(prev_connection[1],prev_connection[2],this.conn_callback.bind(this))):this._transport_connect()}catch(b){this.rebind_delete(),this.connect()}},_transport_connect:function(){this.connection.connect(this.params.jid?this.params.jid:this.params.domain,this.params.password?this.params.password:"",this.conn_callback.bind(this))},
153  
-_check_rebind:function(){if(this.params.rebind){var a=this.rebind_fetch();if(a&&this.params.jid&&""!==this.params.jid){a.split(" ");var b=Strophe.getBareJidFromJid(this.params.jid),a=Strophe.getBareJidFromJid(a.split(" ")[1]);b!=a&&this.rebind_delete()}}},conn_callback:function(a){var b=this;this.params.debug&&(this.connection.rawOutput=function(a){b.console.log("out -> "+a)},this.connection.rawInput=function(a){b.console.log("in <- "+a)});window.clearTimeout(this.timeout_id);this.bosh_rebind_id=
154  
-this.connection.addTimedHandler(2E3,function(){if("BOSH"===b.current_protocol&&!b.closing){var a=["BOSH",b.connection.jid,b.connection.sid,b.connection.rid].join(" ");b.rebind_store(a)}return!0});this.params.on_strophe_event(a,this.connection);var c=function(a,c){b.params.jid=a;b.params.password=c;b.connect()};if(a===Strophe.Status.CONNECTED)this.params.on_connected(),this.retries=0,!0==this.params.rebind&&"WEBSOCKET"==this.current_protocol&&this.connection.save(function(){var a=["WEBSOCKET",b.connection.jid,
155  
-b.connection.streamId].join(" ");b.rebind_store(a)},function(){}),this.subscribe();else if(a===Strophe.Status.ATTACHED)"WEBSOCKET"==this.current_protocol?this.subscribe():(b=this,setTimeout(function(){b.fetchNodes(null,!1)},100));else if(!this.closing&&(a===Strophe.Status.CONNFAIL||a===Strophe.Status.DISCONNECTED))if(this.connection.deleteTimedHandler(this.bosh_rebind_id),this.rebind_delete(),!this.params.jid&&this.params.login_required)this.params.on_login_required(c);else a=Math.round(Math.random()*
156  
-this.params.connect_timeout*(this.retries+1)),this.timeout_id=setTimeout(function(){b.connect()},a);else a===Strophe.Status.DISCONNECTED?(this.connection.reset(),this.closing=!1,this.params.on_disconnect()):a===Strophe.Status.REBINDFAILED?(this.rebind_delete(),this.connection=null,this.connect()):a===Strophe.Status.AUTHFAIL&&(delete this.connection,this.params.on_login_required(c))},fetchNodes:function(a,b){void 0===a&&(a=this.params.nodes);for(var c in a)if("string"==typeof a[c]){if(0<this.params.num_old){var d=
157  
-this;this.connection.pubsub.items(this.connection.jid,this.params.pubsub_domain,a[c],this.params.num_old,function(b){for(var b=b.getElementsByTagName("item"),c=0;c<b.length;c++){var g=b[c].getAttribute("id");d.params.publish(g,b[c].firstChild,a[c])}})}b&&this.connection.pubsub.subscribe(this.connection.jid,this.params.pubsub_domain,a[c],[],function(){})}this.connection.addHandler(this.on_event.bind(this),null,"message",null,null,this.params.pubsub_domain)},subscribe:function(a){this.fetchNodes(a,
158  
-!0)},unsubscribe:function(a){void 0===a&&(a=this.params.nodes);for(var b in a)"string"==typeof a[b]&&this.connection.pubsub.unsubscribe(this.connection.jid,this.params.pubsub_domain,a[b],function(){})},_extract_error_code:function(a){var b=a.getElementsByTagNameNS("http://jabber.org/protocol/pubsub#errors","*");b.length||(b=a.getElementsByTagNameNS("urn:ietf:params:xml:ns:xmpp-stanzas","*"));return b.length?b[0].localName:null},_publish:function(a,b,c,d){var e=this;null==b&&(b=this.connection.getUniqueId("publish"));
159  
-this.connection.pubsub.publish(this.connection.jid,this.params.pubsub_domain,a,[{id:b,value:[c]}],d?function(a){e._done_publish(a,d)}:null);return b},_done_publish:function(a,b){var c=a.getElementsByTagName("item"),c=c.length?c[0].getAttribute("id"):null;"result"==a.getAttribute("type")?b(c,"ok"):b(c,this._extract_error_code(a)||"error")},_deleteNode:function(a,b){var c=this;this.connection.pubsub.deleteNode(this.connection.jid,this.params.pubsub_domain,a,b?function(a){c._done_delete(a,b)}:null)},
160  
-_done_delete:function(a,b){"result"==a.getAttribute("type")?b("ok"):b(this._extract_error_code(a)||"error")},on_event:function(a){for(var b=a.getElementsByTagName("retract"),c=b.length,d=0;d<c;d++)this.params.retract(b[d].getAttribute("id"),b[d].parentNode.getAttribute("node"));b=void 0;c=a.getElementsByTagName("delay");c.length&&(b=c[0].getAttribute("stamp"));for(var a=a.getElementsByTagName("items"),c=a.length,e,f,g,d=0;d<c;d++){e=a[d].getAttribute("node");f=a[d].getElementsByTagName("item");g=
161  
-f.length;for(d=0;d<g;d++)this.params.publish(f[d].getAttribute("id"),f[d].firstChild,e,b)}return!0},cookie:function(a,b){if("undefined"!=typeof b){options=this.params.cookie_opts;null===b&&(b="",options.expires=-1);var c="";if(options.expires&&("number"==typeof options.expires||options.expires.toUTCString))"number"==typeof options.expires?(c=new Date,c.setTime(c.getTime()+864E5*options.expires)):c=options.expires,c="; expires="+c.toUTCString();var d=options.path?"; path="+options.path:"",e=options.domain?
162  
-"; domain="+options.domain:"",f=options.secure?"; secure":"";document.cookie=[a,"=",encodeURIComponent(b),c,d,e,f].join("")}else{c=null;if(document.cookie&&""!=document.cookie){d=document.cookie.split(";");for(e=0;e<d.length;e++)if(f="function"===typeof String.trim?(d[e]||"").trim():(d[e]||"").replace(/^\s\s*/,"").replace(/\s\s*$/,""),f.substring(0,a.length+1)==a+"="){c=decodeURIComponent(f.substring(a.length+1));break}}return c}},rebind_store:function(a){var b=this._build_key();window.sessionStorage?
163  
-sessionStorage[b]=a:this.cookie(b,a)},rebind_delete:function(){var a=this._build_key();window.sessionStorage?sessionStorage.removeItem(a):this.cookie(a,null)},rebind_fetch:function(){var a=this._build_key();return window.sessionStorage?sessionStorage[a]:this.cookie(a)},_build_key:function(){var a=P1PP.COOKIE+"_"+this.current_protocol;"BOSH"===this.current_protocol&&(a=a+"_"+this.scope);return a}};
  155
+websocket:function(){try{this.connection=new Strophe.WebSocket("__flash"in WebSocket&&this.params.flash_ws_url||this.params.ws_url);var a=this.rebind_fetch();a&&this.params.rebind?(prev_connection=a.split(" "),this.connection.rebind(prev_connection[1],prev_connection[2],this.conn_callback.bind(this))):this._transport_connect()}catch(b){this.rebind_delete(),this.connect()}},_transport_connect:function(){this.connection.connect(this.params.jid?this.params.jid:this.params.domain,this.params.password?
  156
+this.params.password:"",this.conn_callback.bind(this))},_check_rebind:function(){if(this.params.rebind){var a=this.rebind_fetch();if(a&&this.params.jid&&""!==this.params.jid){a.split(" ");var b=Strophe.getBareJidFromJid(this.params.jid),a=Strophe.getBareJidFromJid(a.split(" ")[1]);b!=a&&this.rebind_delete()}}},conn_callback:function(a){var b=this;this.params.debug&&(this.connection.rawOutput=function(a){b.console.log("out -> "+a)},this.connection.rawInput=function(a){b.console.log("in <- "+a)});window.clearTimeout(this.timeout_id);
  157
+this.bosh_rebind_id=this.connection.addTimedHandler(2E3,function(){if("BOSH"===b.current_protocol&&!b.closing){var a=["BOSH",b.connection.jid,b.connection.sid,b.connection.rid].join(" ");b.rebind_store(a)}return!0});this.params.on_strophe_event(a,this.connection);var c=function(a,c){b.params.jid=a;b.params.password=c;b.connect()};if(a===Strophe.Status.CONNECTED)this.params.on_connected(),this.retries=0,!0==this.params.rebind&&"WEBSOCKET"==this.current_protocol&&this.connection.save(function(){var a=
  158
+["WEBSOCKET",b.connection.jid,b.connection.streamId].join(" ");b.rebind_store(a)},function(){}),this.subscribe();else if(a===Strophe.Status.ATTACHED)"WEBSOCKET"==this.current_protocol?this.subscribe():(b=this,setTimeout(function(){b.fetchNodes(null,!0)},100));else if(!this.closing&&(a===Strophe.Status.CONNFAIL||a===Strophe.Status.DISCONNECTED))if(this.connection.deleteTimedHandler(this.bosh_rebind_id),this.rebind_delete(),!this.params.jid&&this.params.login_required)this.params.on_login_required(c);
  159
+else a=Math.round(Math.random()*this.params.connect_timeout*(this.retries+1)),this.timeout_id=setTimeout(function(){b.connect()},a);else a===Strophe.Status.DISCONNECTED?(this.connection.reset(),this.closing=!1,this.params.on_disconnect()):a===Strophe.Status.REBINDFAILED?(this.rebind_delete(),this.connection=null,this.connect()):a===Strophe.Status.AUTHFAIL&&(delete this.connection,this.params.on_login_required(c))},fetchNodes:function(a,b){void 0===a&&(a=this.params.nodes);for(var c in a)if("string"==
  160
+typeof a[c]){if(0<this.params.num_old){var d=this;this.connection.pubsub.items(this.connection.jid,this.params.pubsub_domain,a[c],this.params.num_old,function(b){for(var b=b.getElementsByTagName("item"),c=0;c<b.length;c++){var g=b[c].getAttribute("id");d.params.publish(g,b[c].firstChild,a[c])}})}b&&this.connection.pubsub.subscribe(this.connection.jid,this.params.pubsub_domain,a[c],[],function(){})}this.connection.addHandler(this.on_event.bind(this),null,"message",null,null,this.params.pubsub_domain)},
  161
+subscribe:function(a){this.fetchNodes(a,!0)},unsubscribe:function(a){void 0===a&&(a=this.params.nodes);for(var b in a)"string"==typeof a[b]&&this.connection.pubsub.unsubscribe(this.connection.jid,this.params.pubsub_domain,a[b],function(){})},_extract_error_code:function(a){var b=a.getElementsByTagNameNS("http://jabber.org/protocol/pubsub#errors","*");b.length||(b=a.getElementsByTagNameNS("urn:ietf:params:xml:ns:xmpp-stanzas","*"));return b.length?b[0].localName:null},_publish:function(a,b,c,d){var e=
  162
+this;null==b&&(b=this.connection.getUniqueId("publish"));this.connection.pubsub.publish(this.connection.jid,this.params.pubsub_domain,a,[{id:b,value:[c]}],d?function(a){e._done_publish(a,d)}:null);return b},_done_publish:function(a,b){var c=a.getElementsByTagName("item"),c=c.length?c[0].getAttribute("id"):null;"result"==a.getAttribute("type")?b(c,"ok"):b(c,this._extract_error_code(a)||"error")},_deleteNode:function(a,b){var c=this;this.connection.pubsub.deleteNode(this.connection.jid,this.params.pubsub_domain,
  163
+a,b?function(a){c._done_delete(a,b)}:null)},_done_delete:function(a,b){"result"==a.getAttribute("type")?b("ok"):b(this._extract_error_code(a)||"error")},on_event:function(a){for(var b=a.getElementsByTagName("retract"),c=b.length,d=0;d<c;d++)this.params.retract(b[d].getAttribute("id"),b[d].parentNode.getAttribute("node"));b=void 0;c=a.getElementsByTagName("delay");c.length&&(b=c[0].getAttribute("stamp"));for(var a=a.getElementsByTagName("items"),c=a.length,e,f,g,d=0;d<c;d++){e=a[d].getAttribute("node");
  164
+f=a[d].getElementsByTagName("item");g=f.length;for(d=0;d<g;d++)this.params.publish(f[d].getAttribute("id"),f[d].firstChild,e,b)}return!0},cookie:function(a,b){if("undefined"!=typeof b){options=this.params.cookie_opts;null===b&&(b="",options.expires=-1);var c="";if(options.expires&&("number"==typeof options.expires||options.expires.toUTCString))"number"==typeof options.expires?(c=new Date,c.setTime(c.getTime()+864E5*options.expires)):c=options.expires,c="; expires="+c.toUTCString();var d=options.path?
  165
+"; path="+options.path:"",e=options.domain?"; domain="+options.domain:"",f=options.secure?"; secure":"";document.cookie=[a,"=",encodeURIComponent(b),c,d,e,f].join("")}else{c=null;if(document.cookie&&""!=document.cookie){d=document.cookie.split(";");for(e=0;e<d.length;e++)if(f="function"===typeof String.trim?(d[e]||"").trim():(d[e]||"").replace(/^\s\s*/,"").replace(/\s\s*$/,""),f.substring(0,a.length+1)==a+"="){c=decodeURIComponent(f.substring(a.length+1));break}}return c}},rebind_store:function(a){var b=
  166
+this._build_key();window.sessionStorage?sessionStorage[b]=a:this.cookie(b,a)},rebind_delete:function(){var a=this._build_key();window.sessionStorage?sessionStorage.removeItem(a):this.cookie(a,null)},rebind_fetch:function(){var a=this._build_key();return window.sessionStorage?sessionStorage[a]:this.cookie(a)},_build_key:function(){var a=P1PP.COOKIE+"_"+this.current_protocol;"BOSH"===this.current_protocol&&(a=a+"_"+this.scope);return a}};

0 notes on commit aa169bf

Please sign in to comment.
Something went wrong with that request. Please try again.