root / trunk / web / dojo / dojox / cometd / longPollTransportFormEncoded.js
History | View | Annotate | Download (3.99 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.cometd.longPollTransportFormEncoded"]){ |
| 9 |
dojo._hasResource["dojox.cometd.longPollTransportFormEncoded"]=true; |
| 10 |
dojo.provide("dojox.cometd.longPollTransportFormEncoded");
|
| 11 |
dojo.require("dojox.cometd._base");
|
| 12 |
dojox.cometd.longPollTransportFormEncoded=new function(){ |
| 13 |
this._connectionType="long-polling"; |
| 14 |
this._cometd=null; |
| 15 |
this.check=function(_1,_2,_3){ |
| 16 |
return ((!_3)&&(dojo.indexOf(_1,"long-polling")>=0)); |
| 17 |
}; |
| 18 |
this.tunnelInit=function(){ |
| 19 |
var _4={channel:"/meta/connect",clientId:this._cometd.clientId,connectionType:this._connectionType,id:""+this._cometd.messageId++}; |
| 20 |
_4=this._cometd._extendOut(_4);
|
| 21 |
this.openTunnelWith({message:dojo.toJson([_4])}); |
| 22 |
}; |
| 23 |
this.tunnelCollapse=function(){ |
| 24 |
if(!this._cometd._initialized){ |
| 25 |
return;
|
| 26 |
} |
| 27 |
if(this._cometd._advice&&this._cometd._advice["reconnect"]=="none"){ |
| 28 |
return;
|
| 29 |
} |
| 30 |
var _5=this._cometd._interval(); |
| 31 |
if(this._cometd._status=="connected"){ |
| 32 |
setTimeout(dojo.hitch(this,"_connect"),_5); |
| 33 |
}else{
|
| 34 |
setTimeout(dojo.hitch(this._cometd,function(){ |
| 35 |
this.init(this.url,this._props); |
| 36 |
}),_5); |
| 37 |
} |
| 38 |
}; |
| 39 |
this._connect=function(){ |
| 40 |
if(!this._cometd._initialized){ |
| 41 |
return;
|
| 42 |
} |
| 43 |
if(this._cometd._polling){ |
| 44 |
return;
|
| 45 |
} |
| 46 |
if((this._cometd._advice)&&(this._cometd._advice["reconnect"]=="handshake")){ |
| 47 |
this._cometd._status="unconnected"; |
| 48 |
this._initialized=false; |
| 49 |
this._cometd.init(this._cometd.url,this._cometd._props); |
| 50 |
}else{
|
| 51 |
if(this._cometd._status=="connected"){ |
| 52 |
var _6={channel:"/meta/connect",connectionType:this._connectionType,clientId:this._cometd.clientId,id:""+this._cometd.messageId++}; |
| 53 |
if(this._cometd.connectTimeout>=this._cometd.expectedNetworkDelay){ |
| 54 |
_6.advice={timeout:this._cometd.connectTimeout-this._cometd.expectedNetworkDelay};
|
| 55 |
} |
| 56 |
_6=this._cometd._extendOut(_6);
|
| 57 |
this.openTunnelWith({message:dojo.toJson([_6])}); |
| 58 |
} |
| 59 |
} |
| 60 |
}; |
| 61 |
this.deliver=function(_7){ |
| 62 |
}; |
| 63 |
this.openTunnelWith=function(_8,_9){ |
| 64 |
this._cometd._polling=true; |
| 65 |
var _a={url:(_9||this._cometd.url),content:_8,handleAs:this._cometd.handleAs,load:dojo.hitch(this,function(_b){ |
| 66 |
this._cometd._polling=false; |
| 67 |
this._cometd.deliver(_b);
|
| 68 |
this._cometd._backon();
|
| 69 |
this.tunnelCollapse();
|
| 70 |
}),error:dojo.hitch(this,function(_c){ |
| 71 |
var _d={failure:true,error:_c,advice:this._cometd._advice}; |
| 72 |
this._cometd._polling=false; |
| 73 |
this._cometd._publishMeta("connect",false,_d); |
| 74 |
this._cometd._backoff();
|
| 75 |
this.tunnelCollapse();
|
| 76 |
})}; |
| 77 |
var _e=this._cometd._connectTimeout(); |
| 78 |
if(_e>0){ |
| 79 |
_a.timeout=_e; |
| 80 |
} |
| 81 |
this._poll=dojo.xhrPost(_a);
|
| 82 |
}; |
| 83 |
this.sendMessages=function(_f){ |
| 84 |
for(var i=0;i<_f.length;i++){ |
| 85 |
_f[i].clientId=this._cometd.clientId;
|
| 86 |
_f[i].id=""+this._cometd.messageId++; |
| 87 |
_f[i]=this._cometd._extendOut(_f[i]);
|
| 88 |
} |
| 89 |
return dojo.xhrPost({url:this._cometd.url||dojo.config["cometdRoot"],handleAs:this._cometd.handleAs,load:dojo.hitch(this._cometd,"deliver"),content:{message:dojo.toJson(_f)},error:dojo.hitch(this,function(err){ |
| 90 |
this._cometd._publishMeta("publish",false,{messages:_f}); |
| 91 |
}),timeout:this._cometd.expectedNetworkDelay}); |
| 92 |
}; |
| 93 |
this.startup=function(_10){ |
| 94 |
if(this._cometd._status=="connected"){ |
| 95 |
return;
|
| 96 |
} |
| 97 |
this.tunnelInit();
|
| 98 |
}; |
| 99 |
this.disconnect=function(){ |
| 100 |
var _11={channel:"/meta/disconnect",clientId:this._cometd.clientId,id:""+this._cometd.messageId++}; |
| 101 |
_11=this._cometd._extendOut(_11);
|
| 102 |
dojo.xhrPost({url:this._cometd.url||dojo.config["cometdRoot"],handleAs:this._cometd.handleAs,content:{message:dojo.toJson([_11])}});
|
| 103 |
}; |
| 104 |
this.cancelConnect=function(){ |
| 105 |
if(this._poll){ |
| 106 |
this._poll.cancel();
|
| 107 |
this._cometd._polling=false; |
| 108 |
this._cometd._publishMeta("connect",false,{cancel:true}); |
| 109 |
this._cometd._backoff();
|
| 110 |
this.disconnect();
|
| 111 |
this.tunnelCollapse();
|
| 112 |
} |
| 113 |
}; |
| 114 |
}; |
| 115 |
dojox.cometd.longPollTransport=dojox.cometd.longPollTransportFormEncoded; |
| 116 |
dojox.cometd.connectionTypes.register("long-polling",dojox.cometd.longPollTransport.check,dojox.cometd.longPollTransportFormEncoded);
|
| 117 |
dojox.cometd.connectionTypes.register("long-polling-form-encoded",dojox.cometd.longPollTransport.check,dojox.cometd.longPollTransportFormEncoded);
|
| 118 |
} |