From a7e67b48931a441ba7e31aa48f1150a40a888fab Mon Sep 17 00:00:00 2001 From: Harlan Iverson Date: Sun, 22 Jun 2008 02:06:44 +0000 Subject: [PATCH] added start of Alternative Script Syntax transport... does not work. --- src/assembler/xmpp4js.xml | 1 + src/main/javascript/transport/Script.js.js | 96 ++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/main/javascript/transport/Script.js.js diff --git a/src/assembler/xmpp4js.xml b/src/assembler/xmpp4js.xml index 2c0a022..9601f1e 100644 --- a/src/assembler/xmpp4js.xml +++ b/src/assembler/xmpp4js.xml @@ -33,6 +33,7 @@ io/HttpBindingStream.js --> transport/BOSH.js + transport/Script.js PacketFilter.js diff --git a/src/main/javascript/transport/Script.js.js b/src/main/javascript/transport/Script.js.js new file mode 100644 index 0000000..85965a9 --- /dev/null +++ b/src/main/javascript/transport/Script.js.js @@ -0,0 +1,96 @@ +Ext.namespace( "Xmpp4Js.Transport" ); + +/** + * Functionality that needs testing: + * write: + * sid + * no sid on first request + * always present after session has started + * rid + * always present + * starts random + * sequential + * rollover at int limit + * key + * present / not present if it should be + * first, middle, last, first (init with length 3) + * + * beginSession: + * rid, no sid, correct attributes + * error if called when open + * event is raised + * + * endSession: + * terminate type and correct attributes are present + * error if called while not open + * event is raised + * + * send: + * error before beginSession or after endSession + * multible nodes are combined to make one request + * number of open requests > max open requets + * + * polling: + * doesn't send if there is an open request + * doesn't send if there are items in the queue + * sends empty body if both are empty + */ +Xmpp4Js.Transport.Script = function(config) { + Xmpp4Js.Transport.Script.superclass.constructor.call( this, config ); +} + +Xmpp4Js.Transport.Script.prototype = { + + /** + * Immediately write a raw packet node to the wire. Adds frame data including + * RID, SID and Key if they are present. + * + * Also increments the openRequestCount, which is then decremented in the + * onWriteResponse method. + * + * A possible addition could be to add a "no headers" flag. + * + * @param {DomElement} packetNode + */ + write: function(packetNode) { + + this.addFrameData( packetNode ); + + var xml = packetNode.toString(); + + this.fireEvent( "write", packetNode ); + + this.openRequestCount++; + + + // TODO check for max length constraints in browsers + var requestUrl = "http://"+this.server+":"+this.port+"/"+this.endpoint+"?body="+xml; + var scriptElem = document.createElement( "script" ); + scriptElem.setAttribute( "type", "text/javascript" ); + scriptElem.setAttribute( "src", requestUrl ); + + // TODO handle multiple connections... + window._BOSH_ = function(xml) { + this.handleResponse(); + }.bind(this); + + document.body.appendChild( scriptElem ); + }, + + /** + * Handles the response to a write call. + * + * Decrements the openRequestCount that was incremented in write. + * @private + */ + onWriteResponse: function( xml ) { + this.openRequestCount--; + + // TODO character replacement (18.3)? + + var packetNode = new DOMImplementation().loadXML( xml ).documentElement; + this.fireEvent( "recv", packetNode ); + } +} + +Ext.extend( Xmpp4Js.Transport.Script, Xmpp4Js.Transport.BOSH, Xmpp4Js.Transport.Script.prototype ); -- 2.11.4.GIT