[Xmpp4js-commit] SF.net SVN: xmpp4js: [723] trunk/src/main/javascript/transport
Status: Beta
Brought to you by:
h-iverson
From: <h-i...@us...> - 2008-07-05 21:31:07
|
Revision: 723 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=723&view=rev Author: h-iverson Date: 2008-07-05 14:31:15 -0700 (Sat, 05 Jul 2008) Log Message: ----------- made script transport raise error events, and added useKeys option for security Modified Paths: -------------- trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-05 05:56:32 UTC (rev 722) +++ trunk/src/main/javascript/transport/Base.js 2008-07-05 21:31:15 UTC (rev 723) @@ -118,7 +118,7 @@ * The keysequence object * @private */ - this.keySeq = null; + this.keySeq = config.useKeys ? new KeySequence(25): null; /** * The max number of requests that can be open at once, sent by the server @@ -133,6 +133,12 @@ */ this.hold = null; + /** + * + * @private + */ + this.polling = 5; + /** * The number of open XHR requests. Used for polling. * @private @@ -223,7 +229,7 @@ packetNode.setAttribute( "xmlns:xmpp", "urn:xmpp:xbosh"); packetNode.setAttribute( "xmpp:version", "1.0" ); - + this.on("recv", this.onBeginSessionResponse, this, {single:true}); this.write( packetNode ); @@ -254,6 +260,10 @@ // FIXME ideally xhr's timeout should be updated this.wait = packetNode.getAttribute("wait").toString(); } + + if( packetNode.hasAttribute("polling") ) { + this.polling = packetNode.getAttribute("polling").toString(); + } this.startup(); @@ -360,6 +370,14 @@ * @private */ sendPoll: function() { + // if we're trying to poll too frequently + /*var now = new Date().getTime(); + if( this.lastPoll != undefined && this.polling != 0 && (now - this.lastPoll < (this.polling * 1000)) ) { + return; + } + this.lastPoll = now; + */ + if( this.openRequestCount == 0 && this.queue.length == 0 ) { var packetNode = this.createPacketNode(); this.write( packetNode ); Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-05 05:56:32 UTC (rev 722) +++ trunk/src/main/javascript/transport/Script.js 2008-07-05 21:31:15 UTC (rev 723) @@ -45,6 +45,12 @@ var superConfig = config; + // TODO handle multiple connections... + window._BOSH_ = function(xml) { + this.onWriteResponse(xml); + }.bind(this); + + Xmpp4Js.Transport.Script.superclass.constructor.call( this, config ); } @@ -77,11 +83,7 @@ scriptElem.setAttribute( "src", requestUrl ); scriptElem.setAttribute( "id", "xmpp4js"+"."+this.sid+"."+packetNode.getAttribute("rid") ); - // TODO handle multiple connections... - window._BOSH_ = function(xml) { - this.onWriteResponse(xml); - }.bind(this); - + document.body.appendChild( scriptElem ); }, @@ -97,7 +99,40 @@ // TODO character replacement (18.3)? var packetNode = new DOMImplementation().loadXML( xml ).documentElement; - this.fireEvent( "recv", packetNode ); + + if(packetNode.getAttribute("type").toString() == "terminal") { + this.shutdown(); + + var condition = null; + if( packetNode != null ) { + condition = packetNode.getAttribute( "condition" ).toString(); + } else if( !response.status ) { + condition = "undefined-condition"; + } else if( response.status != 200 ){ + condition = "status."+response.status; + } else { + condition = "undefined-condition"; + } + + var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title; + var message = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].message; + + this.fireEvent( "termerror", title, message, packetNode ); + } else if( packetNode.getAttribute("type").toString() == "error" ) { + // 17.3 Recoverable Binding Conditions + + // TODO this should attempt to resend all packets back + // to the one that created the error. This could be + // implemented by putting each sent packet into a queue + // and removing it upon a successful response. + // + // Ideally this error event would not even be visible beyond + // the the BOSH transport. + + this.fireEvent( "error", packetNode ); + } else { + this.fireEvent( "recv", packetNode ); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |