xmpp4js-commit Mailing List for xmpp4js: javascript xmpp/jabber library
Status: Beta
Brought to you by:
h-iverson
You can subscribe to this list here.
2008 |
Jan
|
Feb
(18) |
Mar
(1) |
Apr
|
May
(4) |
Jun
(6) |
Jul
(47) |
Aug
(7) |
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <h-i...@us...> - 2008-08-26 23:06:28
|
Revision: 770 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=770&view=rev Author: h-iverson Date: 2008-08-26 23:06:37 +0000 (Tue, 26 Aug 2008) Log Message: ----------- added readme and finished deleting project stuff Added Paths: ----------- trunk/README.moved.txt Removed Paths: ------------- trunk/.project trunk/LGPL.txt trunk/nbactions.xml trunk/pom.xml Deleted: trunk/.project =================================================================== --- trunk/.project 2008-08-26 23:04:52 UTC (rev 769) +++ trunk/.project 2008-08-26 23:06:37 UTC (rev 770) @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>xmpp4js</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - </buildSpec> - <natures> - </natures> -</projectDescription> Deleted: trunk/LGPL.txt =================================================================== --- trunk/LGPL.txt 2008-08-26 23:04:52 UTC (rev 769) +++ trunk/LGPL.txt 2008-08-26 23:06:37 UTC (rev 770) @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. Added: trunk/README.moved.txt =================================================================== --- trunk/README.moved.txt (rev 0) +++ trunk/README.moved.txt 2008-08-26 23:06:37 UTC (rev 770) @@ -0,0 +1,3 @@ +This project has switched to a Git repository: + +http://github.com/harlanji/xmpp4js/tree/master \ No newline at end of file Deleted: trunk/nbactions.xml =================================================================== --- trunk/nbactions.xml 2008-08-26 23:04:52 UTC (rev 769) +++ trunk/nbactions.xml 2008-08-26 23:06:37 UTC (rev 770) @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<actions> - <action> - <actionName>build</actionName> - <packagings> - <packaging>*</packaging> - </packagings> - <goals> - <goal>install</goal> - </goals> - <properties> - <maven.test.skip>true</maven.test.skip> - </properties> - </action> - </actions> Deleted: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-08-26 23:04:52 UTC (rev 769) +++ trunk/pom.xml 2008-08-26 23:06:37 UTC (rev 770) @@ -1,153 +0,0 @@ -<?xml version="1.0"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 -http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>com.soashable.lib</groupId> - <artifactId>xmpp4js</artifactId> - <packaging>javascript</packaging> - <version>0.2-SNAPSHOT</version> - <name>xmpp4js</name> - <description> - xmpp4js is an xmpp connection library for Javascript. It is written with a heavy emphasis - on resuability and extensibility, and is naturally heavilly tested. - </description> - <url>http://xmpp4js.sourceforge.net</url> - <dependencies> - <dependency> - <groupId>uk.org.pajhome</groupId> - <artifactId>crypto</artifactId> - <type>javascript</type> - <version>1.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>net.sf.xml4script</groupId> - <artifactId>xml4script</artifactId> - <type>javascript</type> - <version>3.1-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>de.berlios.log4js</groupId> - <artifactId>log4js</artifactId> - <type>javascript</type> - <version>1.0-RC1</version> - </dependency> - </dependencies> - <build> - <extensions> - <extension> - <groupId>org.codehaus.mojo.javascript</groupId> - <artifactId>javascript-maven-extensions</artifactId> - <version>1.0-alpha-1-SNAPSHOT</version> - </extension> - </extensions> - <plugins> - <plugin> - <groupId>org.codehaus.mojo.javascript</groupId> - <artifactId>javascript-maven-plugin</artifactId> - <version>1.0-alpha-1-SNAPSHOT</version> - <extensions>true</extensions> - <configuration> - <descriptor>${basedir}/src/assembler/xmpp4js.xml</descriptor> - <includes> - <include>LangTest.html</include> - </includes> - <excludes> - <!-- hasn't been ported to new connection stuff yet --> - <exclude>MUC_JoinTest.html</exclude> - </excludes> - <browsers> - <browser>firefox</browser> - </browsers> - </configuration> - <executions> - </executions> - </plugin> - </plugins> - </build> - <reporting> - <plugins> - <plugin> - <groupId>org.codehaus.mojo.javascript</groupId> - <artifactId>javascript-report-maven-plugin</artifactId> - <configuration> - <reports> - <report>jsdoc</report> - </reports> - </configuration> - </plugin> - <!-- - - There is a bug in js plugin that prevents site from building if this - is enabled and tests fail. - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-report-plugin</artifactId> - </plugin> - --> - </plugins> - </reporting> - <distributionManagement> - <repository> - <id>mvn.soashable.com</id> - <url> - http://mvn.soashable.com:8180/artifactory/libs-snapshots - </url> - </repository> - <snapshotRepository> - <id>mvn.soashable.com</id> - <url> - http://mvn.soashable.com:8180/artifactory/libs-snapshots - </url> - </snapshotRepository> - <site> - <id>sourceforge.net-site</id> - <url>scp://shell.sourceforge.net/home/groups/x/xm/xmpp4js/htdocs</url> - </site> - </distributionManagement> - <scm> - <connection>scm:svn:http://xmpp4js.svn.sourceforge.net/svnroot/xmpp4js/trunk</connection> - <developerConnection>scm:svn:https://xmpp4js.svn.sourceforge.net/svnroot/xmpp4js/trunk</developerConnection> - <url>http://xmpp4js.svn.sourceforge.net/viewvc/xmpp4js/</url> - </scm> - <licenses> - <license> - <name>GNU Lesser Public License (LGPL)</name> - <url>http://www.gnu.org/licenses/lgpl-3.0.txt</url> - </license> - </licenses> - <issueManagement> - <system>Google Code Issues</system> - <url>http://code.google.com/p/soashable/issues/list</url> - </issueManagement> - <developers> - <developer> - <id>h.iverson</id> - <name>Harlan Iverson</name> - <email>h.iverson at gmail dot com</email> - <url>http://blog.devspan.com</url> - </developer> - </developers> - <contributors> - <contributor> - <name>Matthew Purland</name> - <email>m.purland at gmail dot com</email> - </contributor> - </contributors> - <repositories> - <repository> - <id>soashable-libs-snapshots</id> - <url>http://mvn.soashable.com/artifactory/libs-snapshots</url> - <releases> - <enabled>false</enabled> - <updatePolicy>never</updatePolicy> - <checksumPolicy>fail</checksumPolicy> - </releases> - <snapshots> - <checksumPolicy>warn</checksumPolicy> - </snapshots> - </repository> - </repositories> -</project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-26 23:04:44
|
Revision: 769 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=769&view=rev Author: h-iverson Date: 2008-08-26 23:04:52 +0000 (Tue, 26 Aug 2008) Log Message: ----------- deleted Removed Paths: ------------- trunk/lib/ trunk/src/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-26 19:40:13
|
Revision: 768 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=768&view=rev Author: h-iverson Date: 2008-08-26 19:40:19 +0000 (Tue, 26 Aug 2008) Log Message: ----------- added extension support page Modified Paths: -------------- trunk/src/site/site.xml Added Paths: ----------- trunk/src/site/xdoc/extension-support.xml Modified: trunk/src/site/site.xml =================================================================== --- trunk/src/site/site.xml 2008-08-04 23:00:23 UTC (rev 767) +++ trunk/src/site/site.xml 2008-08-26 19:40:19 UTC (rev 768) @@ -49,6 +49,7 @@ </menu> <menu name="Developer Docs"> <item name="Code Samples" href="code-samples.html"/> + <item name="Extension Support" href="extension-support.html"/> <item name="BOSH Environment" href="bosh-environment.html"/> <item name="The HACKING File" href="hacking.html"/> <item name="XEP-0124 (BOSH)" href="http://www.xmpp.org/extensions/xep-0124.html"/> Added: trunk/src/site/xdoc/extension-support.xml =================================================================== --- trunk/src/site/xdoc/extension-support.xml (rev 0) +++ trunk/src/site/xdoc/extension-support.xml 2008-08-26 19:40:19 UTC (rev 768) @@ -0,0 +1,80 @@ +<document> + <properties> + <author email="h.i...@gm...">Harlan Iverson</author> + <title>Extension Support</title> + </properties> + + <body> + + <section name="Extension Support"> + <table> + <thead> + <tr> + + <th>Extension</th> + <th>Supported?</th> + <th>Validated?</th> + </tr> + </thead> + <tbody> + + + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0004.html">XEP-0004: Data Forms</a></td> + <td>Yes</td> + <td>No</td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0030.html">XEP-0030: Service Discovery</a></td> + <td>Yes</td> + <td>No</td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0045.html">XEP-0045: Multi-User Chat</a></td> + <td><a href="http://code.google.com/p/soashable/issues/detail?id=4">Planned</a></td> + <td></td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0049.html">XEP-0049: Private XML Storage</a></td> + <td>Yes</td> + <td>No</td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0060.html">XEP-0060: Publish-Subscribe</a></td> + <td><a href="http://code.google.com/p/soashable/issues/detail?id=69">Planned</a></td> + <td></td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0077.html">XEP-0077: In-Band Registration</a></td> + <td>Yes</td> + <td>No</td> + </tr> + + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0085.html">XEP-0085: Chat State Notifications</a></td> + <td>Yes</td> + <td>No</td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0100.html">XEP-0100: Gateway Interaction</a></td> + <td>Yes</td> + <td>No</td> + </tr> + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0124.html">XEP-0124: Bidirectional-streams Over Synchronous HTTP (BOSH)</a></td> + <td>Yes</td> + <td>No</td> + </tr> + + <tr> + <td><a href="http://www.xmpp.org/extensions/xep-0163.html">XEP-0163: Personal Eventing via Pubsub</a></td> + <td><a href="http://code.google.com/p/soashable/issues/detail?id=69">Planned</a></td> + <td></td> + </tr> + </tbody> + </table> + + </section> + + </body> +</document> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-04 23:00:16
|
Revision: 767 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=767&view=rev Author: h-iverson Date: 2008-08-04 23:00:23 +0000 (Mon, 04 Aug 2008) Log Message: ----------- added PacketTypeFilter Modified Paths: -------------- trunk/src/main/javascript/PacketFilter.js Modified: trunk/src/main/javascript/PacketFilter.js =================================================================== --- trunk/src/main/javascript/PacketFilter.js 2008-08-04 22:29:58 UTC (rev 766) +++ trunk/src/main/javascript/PacketFilter.js 2008-08-04 23:00:23 UTC (rev 767) @@ -132,7 +132,7 @@ Xmpp4Js.Lang.extend(Xmpp4Js.PacketFilter.AllPacketFilter, Xmpp4Js.PacketFilter.PacketFilter, Xmpp4Js.PacketFilter.AllPacketFilter.prototype); /** - * Filters for packets of a particular type. The type is given as a Class object, so example types would: + * Filters for packets of a particular class. The given should be a constructor, so example types would: * * Packet.Message * * Packet.IQ * * Packet.Presence @@ -154,6 +154,29 @@ Xmpp4Js.Lang.extend(Xmpp4Js.PacketFilter.PacketClassFilter, Xmpp4Js.PacketFilter.PacketFilter, Xmpp4Js.PacketFilter.PacketClassFilter.prototype); + /** + * Filters for packets of a particular type. The type is given as a string. + * This can be used for any packet class. + * + * @constructor + * @extends Xmpp4Js.PacketFilter.PacketFilter + */ +Xmpp4Js.PacketFilter.PacketTypeFilter = function(type) { + Xmpp4Js.PacketFilter.PacketTypeFilter.superclass.constructor.apply(this, arguments); + + this.type = type; +} + +Xmpp4Js.PacketFilter.PacketTypeFilter.prototype = { + accept: function(packet) { + return packet.getType() == this.type; + } +}; + + +Xmpp4Js.Lang.extend(Xmpp4Js.PacketFilter.PacketTypeFilter, Xmpp4Js.PacketFilter.PacketFilter, Xmpp4Js.PacketFilter.PacketTypeFilter.prototype); + + /** * Filters for packets with a particular packet ID. * @constructor This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-04 22:29:58
|
Revision: 766 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=766&view=rev Author: h-iverson Date: 2008-08-04 22:29:58 +0000 (Mon, 04 Aug 2008) Log Message: ----------- changed PacketTypeFilter to PacketClassFilter Modified Paths: -------------- trunk/src/main/javascript/PacketFilter.js trunk/src/main/javascript/chat/ChatManager.js trunk/src/main/javascript/chat/MessageThreadFilter.js trunk/src/main/javascript/muc/MucPresenceFilter.js trunk/src/main/javascript/roster/Roster.js trunk/src/site/xdoc/code-samples.xml trunk/src/test/javascript/PacketFilterTest.html Modified: trunk/src/main/javascript/PacketFilter.js =================================================================== --- trunk/src/main/javascript/PacketFilter.js 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/main/javascript/PacketFilter.js 2008-08-04 22:29:58 UTC (rev 766) @@ -139,20 +139,20 @@ * @constructor * @extends Xmpp4Js.PacketFilter.PacketFilter */ -Xmpp4Js.PacketFilter.PacketTypeFilter = function(type) { - Xmpp4Js.PacketFilter.PacketTypeFilter.superclass.constructor.apply(this, arguments); +Xmpp4Js.PacketFilter.PacketClassFilter = function(type) { + Xmpp4Js.PacketFilter.PacketClassFilter.superclass.constructor.apply(this, arguments); this.type = type; } -Xmpp4Js.PacketFilter.PacketTypeFilter.prototype = { +Xmpp4Js.PacketFilter.PacketClassFilter.prototype = { accept: function(packet) { return packet instanceof (this.type); } }; -Xmpp4Js.Lang.extend(Xmpp4Js.PacketFilter.PacketTypeFilter, Xmpp4Js.PacketFilter.PacketFilter, Xmpp4Js.PacketFilter.PacketTypeFilter.prototype); +Xmpp4Js.Lang.extend(Xmpp4Js.PacketFilter.PacketClassFilter, Xmpp4Js.PacketFilter.PacketFilter, Xmpp4Js.PacketFilter.PacketClassFilter.prototype); /** * Filters for packets with a particular packet ID. @@ -203,7 +203,7 @@ Xmpp4Js.PacketFilter.IQQueryNSFilter = function(namespace) { Xmpp4Js.PacketFilter.IQQueryNSFilter.superclass.constructor.apply(this, arguments); - this.iqFilter = new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.IQ ); + this.iqFilter = new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.IQ ); this.namespace = namespace; } Modified: trunk/src/main/javascript/chat/ChatManager.js =================================================================== --- trunk/src/main/javascript/chat/ChatManager.js 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/main/javascript/chat/ChatManager.js 2008-08-04 22:29:58 UTC (rev 766) @@ -72,7 +72,7 @@ _registerEvents : function() { this.con.addPacketListener( function(stanza) { this._handleMessageReceived( stanza ); - }.bind(this), new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Message )); + }.bind(this), new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Message )); }, /** Modified: trunk/src/main/javascript/chat/MessageThreadFilter.js =================================================================== --- trunk/src/main/javascript/chat/MessageThreadFilter.js 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/main/javascript/chat/MessageThreadFilter.js 2008-08-04 22:29:58 UTC (rev 766) @@ -10,9 +10,9 @@ this.thread = thread; /** A filter for Message packets * @private - * @type Xmpp4Js.PacketFilter.PacketTypeFilter + * @type Xmpp4Js.PacketFilter.PacketClassFilter */ - this.packetTypeFilter = new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Message ); + this.packetClassFilter = new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Message ); } Xmpp4Js.Chat.MessageThreadFilter.prototype = { @@ -20,7 +20,7 @@ * Return true if this is a Message packet and its thread equals the one we're interested in. */ accept: function(stanza) { - return this.packetTypeFilter.accept(stanza) + return this.packetClassFilter.accept(stanza) && stanza.getThread() == this.thread; } } Modified: trunk/src/main/javascript/muc/MucPresenceFilter.js =================================================================== --- trunk/src/main/javascript/muc/MucPresenceFilter.js 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/main/javascript/muc/MucPresenceFilter.js 2008-08-04 22:29:58 UTC (rev 766) @@ -9,7 +9,7 @@ Xmpp4Js.Muc.MucPresenceFilter = function(fromJid) { this.fromJid = fromJid; - this.presenceFilter = new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Presence ); + this.presenceFilter = new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Presence ); if(fromJid != undefined) { this.fromFilter = new Xmpp4Js.PacketFilter.FromContainsFilter(fromJid); } Modified: trunk/src/main/javascript/roster/Roster.js =================================================================== --- trunk/src/main/javascript/roster/Roster.js 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/main/javascript/roster/Roster.js 2008-08-04 22:29:58 UTC (rev 766) @@ -27,10 +27,10 @@ this.con = con; - this.con.addPacketListener( this.rosterItemManager.rosterPacketListener.bind(this.rosterItemManager), new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.RosterPacket ) ); - this.con.addPacketListener( this.rosterItemManager.rosterSubSyncPacketListener.bind(this.rosterItemManager), new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Presence ) ); + this.con.addPacketListener( this.rosterItemManager.rosterPacketListener.bind(this.rosterItemManager), new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.RosterPacket ) ); + this.con.addPacketListener( this.rosterItemManager.rosterSubSyncPacketListener.bind(this.rosterItemManager), new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Presence ) ); - this.con.addPacketListener( this.presenceManager.presencePacketListener.bind(this.presenceManager), new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Presence ) ); + this.con.addPacketListener( this.presenceManager.presencePacketListener.bind(this.presenceManager), new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Presence ) ); } Modified: trunk/src/site/xdoc/code-samples.xml =================================================================== --- trunk/src/site/xdoc/code-samples.xml 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/site/xdoc/code-samples.xml 2008-08-04 22:29:58 UTC (rev 766) @@ -173,7 +173,7 @@ } else { alert( from + " is offline." ); } -}, new PacketTypeFilter( Packet.Presence ) ); +}, new PacketClassFilter( Packet.Presence ) ); ]]></pre> </subsection> @@ -197,7 +197,7 @@ outPres.setTo( presence.getFrom() ); con.send( outPres ); } -}, new PacketTypeFilter( Packet.Presence ) ); +}, new PacketClassFilter( Packet.Presence ) ); ]]></pre> </subsection> @@ -217,7 +217,7 @@ }, // capture only Message packets with MessageEventExtension new AndFilter( - new PacketTypeFilter( Packet.Message ), + new PacketClassFilter( Packet.Message ), new ExtensionFilter( MessageEventExtension.XMLNS ) ) ); Modified: trunk/src/test/javascript/PacketFilterTest.html =================================================================== --- trunk/src/test/javascript/PacketFilterTest.html 2008-08-04 18:47:58 UTC (rev 765) +++ trunk/src/test/javascript/PacketFilterTest.html 2008-08-04 22:29:58 UTC (rev 766) @@ -34,20 +34,20 @@ } -function testPacketTypeFilter_True() { +function testPacketClassFilter_True() { var stanza = packetHelper.createIQ( "te...@te...", "set", "jabber:iq:roster" ); - var pf = new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.IQ ); + var pf = new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.IQ ); var result = pf.accept( stanza ); assertTrue( result ); } -function testPacketTypeFilter_False() { +function testPacketClassFilter_False() { var stanza = packetHelper.createIQ( "te...@te...", "set", "jabber:iq:roster" ); - var pf = new Xmpp4Js.PacketFilter.PacketTypeFilter( Xmpp4Js.Packet.Message ); + var pf = new Xmpp4Js.PacketFilter.PacketClassFilter( Xmpp4Js.Packet.Message ); var result = pf.accept( stanza ); assertFalse( result ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-04 18:48:02
|
Revision: 765 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=765&view=rev Author: h-iverson Date: 2008-08-04 18:47:58 +0000 (Mon, 04 Aug 2008) Log Message: ----------- - fixed error in IE where I forgot to bind a function context - fixed parse error when not in debug mode - added error message to packet listener manager Modified Paths: -------------- trunk/src/main/javascript/packet/PacketListenerManager.js trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/packet/PacketListenerManager.js =================================================================== --- trunk/src/main/javascript/packet/PacketListenerManager.js 2008-08-04 18:45:25 UTC (rev 764) +++ trunk/src/main/javascript/packet/PacketListenerManager.js 2008-08-04 18:47:58 UTC (rev 765) @@ -5,6 +5,8 @@ this.stanzaProvider = config.stanzaProvider; } +Xmpp4Js.PacketListenerManager.logger = Xmpp4Js.createLogger("xmpp4js.packetlistener"); + Xmpp4Js.PacketListenerManager.prototype = { /** * Add a listener for certain types of packets. All packets are @@ -65,7 +67,7 @@ } else { for( var j = 0; j < packetNode.childNodes.getLength(); j++ ) { var node = packetNode.childNodes.item(j); - + // if it's not a normal element ignore it if( node.nodeType != 1 /* ELEMENT - are there cross-browser constants? */) { continue; @@ -85,6 +87,7 @@ } } } catch( e ) { +;;; Xmpp4Js.PacketListenerManager.logger.error( "Error running packet listener"); // alert( "Exception executing filter: " + e +"\n" + e.fileName + "(" + e.lineNumber + ")"); // alert( e.stack ); } Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-08-04 18:45:25 UTC (rev 764) +++ trunk/src/main/javascript/transport/Base.js 2008-08-04 18:47:58 UTC (rev 765) @@ -277,8 +277,7 @@ this.polling = packetNode.getAttribute("polling").toString(); } -;;; Xmpp4Js.Transport.Base.logger.debug( "Get beginSession response. Session ID="+this.sid - +", hold="+this.hold+", wait="+this.wait+", polling="+this.polling ); +;;; Xmpp4Js.Transport.Base.logger.debug( "Get beginSession response. Session ID="+this.sid+", hold="+this.hold+", wait="+this.wait+", polling="+this.polling ); this.startup(); Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-08-04 18:45:25 UTC (rev 764) +++ trunk/src/main/javascript/transport/Script.js 2008-08-04 18:47:58 UTC (rev 765) @@ -101,16 +101,16 @@ scriptElem.onreadystatechange = function() { if(scriptElem.readyState == 4 || scriptElem.readyState == "loaded") { this.onScriptLoad( scriptElem ); - } + } // TODO add error... - } + }.bind(this); } document.body.appendChild( scriptElem ); }, onScriptLoad: function(scriptElem) { - document.body.removeChild( scriptElem ); + document.body.removeChild( scriptElem ); }, onScriptError: function(scriptElem) { @@ -155,7 +155,7 @@ try { // this will throw an exception if there is an error. this.handleErrors( packetNode ); - + this.fireEvent( "recv", packetNode ); } catch(e) { this.shutdown(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-08-04 18:45:26
|
Revision: 764 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=764&view=rev Author: h-iverson Date: 2008-08-04 18:45:25 +0000 (Mon, 04 Aug 2008) Log Message: ----------- added Xmpp4Js.setLogLevel method Modified Paths: -------------- trunk/src/main/javascript/adapter/Default.js Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-29 16:59:44 UTC (rev 763) +++ trunk/src/main/javascript/adapter/Default.js 2008-08-04 18:45:25 UTC (rev 764) @@ -4,13 +4,25 @@ Xmpp4Js.logLevel = Log4js.Level.ALL; Xmpp4Js.appender = new Log4js.ConsoleAppender(); +Xmpp4Js.loggers = []; + Xmpp4Js.createLogger = function(logId) { var logger = Log4js.getLogger( logId ); logger.setLevel( Xmpp4Js.logLevel ); logger.addAppender( Xmpp4Js.appender ); + Xmpp4Js.loggers.push( logger ); + return logger; } +//javascript:Xmpp4Js.setLogLevel( Log4js.Level.OFF ); +Xmpp4Js.setLogLevel = function(level) { + Xmpp4Js.logLevel = level; + + for(var i = 0; i < Xmpp4Js.loggers.length; i++ ) { + Xmpp4Js.loggers[i].setLevel( level ); + } +} /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-29 16:59:36
|
Revision: 763 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=763&view=rev Author: h-iverson Date: 2008-07-29 16:59:44 +0000 (Tue, 29 Jul 2008) Log Message: ----------- added async option Modified Paths: -------------- trunk/src/main/javascript/adapter/Default.js Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-29 16:58:51 UTC (rev 762) +++ trunk/src/main/javascript/adapter/Default.js 2008-07-29 16:59:44 UTC (rev 763) @@ -347,7 +347,7 @@ asyncRequest: function(request) { var xhr = Xmpp4Js.Lang.createXhr(); - xhr.open(request.method, request.url, true); + xhr.open(request.method, request.url, request.async != undefined ? request.async : true); for( var header in request.headers ) { xhr.setRequestHeader( header, request.headers[ header ] ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-29 16:58:42
|
Revision: 762 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=762&view=rev Author: h-iverson Date: 2008-07-29 16:58:51 +0000 (Tue, 29 Jul 2008) Log Message: ----------- tweaks to pausing stuff, moved serializeState and deserializeState to separate methods Modified Paths: -------------- trunk/src/main/javascript/transport/BOSH.js trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/transport/BOSH.js =================================================================== --- trunk/src/main/javascript/transport/BOSH.js 2008-07-28 17:31:19 UTC (rev 761) +++ trunk/src/main/javascript/transport/BOSH.js 2008-07-29 16:58:51 UTC (rev 762) @@ -75,7 +75,10 @@ xmlNode: packetNode, // this isn't a real option... but it's needed for testing. scope: this, callback: this.onWriteResponse, - + /*async: !this.isPausing, // use synchronous requests if we're pausing + // because it's generally called from onunload + // which will cut off async requests. + */ url: this.endpoint, method: "POST", // FIXME this.wait is sent by initial response. Change this timeout Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-28 17:31:19 UTC (rev 761) +++ trunk/src/main/javascript/transport/Base.js 2008-07-29 16:58:51 UTC (rev 762) @@ -228,6 +228,8 @@ * then mark the session open and start the sendQueueTask. */ beginSession: function() { + this.isPausing = false; + this.rid = this.createInitialRid(); var packetNode = this.createPacketNode(); @@ -503,7 +505,11 @@ return Math.floor( Math.random() * 10000 ); }, + isPausing: false, + pause: function(time) { + this.isPausing = true; + ;;; Xmpp4Js.Transport.Base.logger.info( "Pausing session." ); this.fireEvent( "beforepause", time ); @@ -526,6 +532,15 @@ this.shutdown(); + var pauseStruct = this.serializeState(); + + // give others an opportunity to serialize proprties + this.fireEvent( "pause", pauseStruct ); + + return pauseStruct; + }, + + serializeState: function() { var pauseStruct = { maxpause: 120, // TODO not hard code me maxRequests: this.maxRequests, @@ -542,15 +557,10 @@ keySeqIdx: this.keySeq._idx }; - // give others an opportunity to serialize proprties - this.fireEvent( "pause", pauseStruct ); - return pauseStruct; }, - resume: function(pauseStruct) { -;;; Xmpp4Js.Transport.Base.logger.info( "Resume session. Session ID="+pauseStruct.sid+", Request ID="+pauseStruct.rid ); - + deserializeState: function(pauseStruct) { // this.maxpause = pauseStruct.maxpause; this.maxpause = pauseStruct.maxpause; this.hold = pauseStruct.hold; @@ -566,7 +576,15 @@ this.keySeq._keys = pauseStruct.keysSeqKeys; this.keySeq._idx = pauseStruct.keySeqIdx; + }, + + resume: function(pauseStruct) { + this.isPausing = false; +;;; Xmpp4Js.Transport.Base.logger.info( "Resume session. Session ID="+pauseStruct.sid+", Request ID="+pauseStruct.rid ); + + this.deserializeState(pauseStruct); + this.startup(); // give others an opportunity to deserialize properties Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-28 17:31:19 UTC (rev 761) +++ trunk/src/main/javascript/transport/Script.js 2008-07-29 16:58:51 UTC (rev 762) @@ -64,24 +64,7 @@ Xmpp4Js.Transport.Script.logger = Xmpp4Js.createLogger( "xmpp4js.transport.script" ); Xmpp4Js.Transport.Script.prototype = { - isPausing: false, - - pause: function() { - this.isPausing = true; - return Xmpp4Js.Transport.Script.superclass.pause.apply( this, arguments ); - }, - - resume: function() { - this.isPausing = false; - return Xmpp4Js.Transport.Script.superclass.resume.apply( this, arguments ) - }, - - connect: function() { - this.isPausing = false; - return Xmpp4Js.Transport.Script.superclass.connect.apply( this, arguments ) - }, - - + /** * Immediately write a raw packet node to the wire. Adds frame data including * RID, SID and Key if they are present. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-28 17:31:10
|
Revision: 761 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=761&view=rev Author: h-iverson Date: 2008-07-28 17:31:19 +0000 (Mon, 28 Jul 2008) Log Message: ----------- fixed http error response codes Modified Paths: -------------- trunk/src/main/javascript/transport/BOSH.js Modified: trunk/src/main/javascript/transport/BOSH.js =================================================================== --- trunk/src/main/javascript/transport/BOSH.js 2008-07-28 16:08:54 UTC (rev 760) +++ trunk/src/main/javascript/transport/BOSH.js 2008-07-28 17:31:19 UTC (rev 761) @@ -98,21 +98,16 @@ ;;; Xmpp4Js.Transport.BOSH.logger.debug( "Got write response." ); - var packetNode = null; + // 17.4 XML Stanza Conditions? + // this condition would be true if we closed the connection + // before a response was received + // + // TODO setting xhr.timeout to a higher value than wait would + // eliminate this issue, unless there was a network + // inturruption before the server responded. figure out + // how to handle this. + - if( response.responseText != null ) { - // 17.4 XML Stanza Conditions? - // this condition would be true if we closed the connection - // before a response was received - // - // TODO setting xhr.timeout to a higher value than wait would - // eliminate this issue, unless there was a network - // inturruption before the server responded. figure out - // how to handle this. - - packetNode = new DOMImplementation().loadXML( response.responseText ).documentElement; - } - /* TODO - 17.1 A legacy client (or connection manager) is a client (or @@ -136,9 +131,7 @@ ;;; Xmpp4Js.Transport.BOSH.logger.warn( "Deprecated HTTP code error" ); var condition = null; - if( packetNode != null ) { - condition = packetNode.getAttribute( "condition" ).toString(); - } else if( !response.status ) { + if( !response.status ) { condition = "undefined-condition"; } else if( response.status != 200 ){ condition = "status."+response.status; @@ -160,6 +153,10 @@ } } else { try { + + var packetNode = new DOMImplementation().loadXML( response.responseText ).documentElement; + + // this will throw an exception if there is an error. this.handleErrors( packetNode ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-28 16:08:45
|
Revision: 760 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=760&view=rev Author: h-iverson Date: 2008-07-28 16:08:54 +0000 (Mon, 28 Jul 2008) Log Message: ----------- added beforepause event to transports and connection Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-28 14:52:17 UTC (rev 759) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-28 16:08:54 UTC (rev 760) @@ -117,6 +117,7 @@ streamerror: this.onStreamError, beginsession: this.onBeginSession, endsession: this.onEndSession, + beforepause: this.onBeforePause, pause: this.onPause, resume: this.onResume // recv will be added in beginSession. @@ -276,6 +277,10 @@ this.fireEvent( "close" ); }, + onBeforePause: function(time) { + this.fireEvent( "beforepause", time ); + }, + /** * Event handler for when the transport session is paused. Bubbles the event * through to listeners on this connection. Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-28 14:52:17 UTC (rev 759) +++ trunk/src/main/javascript/transport/Base.js 2008-07-28 16:08:54 UTC (rev 760) @@ -207,6 +207,8 @@ */ endsession: true, + beforepause: true, + pause: true, resume: true @@ -236,8 +238,8 @@ packetNode.setAttribute( "xml:lang", "en"); packetNode.setAttribute( "xmlns:xmpp", "urn:xmpp:xbosh"); packetNode.setAttribute( "xmpp:version", "1.0" ); + - this.on("recv", this.onBeginSessionResponse, this, {single:true}); this.write( packetNode ); @@ -503,6 +505,8 @@ pause: function(time) { ;;; Xmpp4Js.Transport.Base.logger.info( "Pausing session." ); + + this.fireEvent( "beforepause", time ); var pauseNode = this.createPacketNode(); pauseNode.setAttribute( "pause", time ); Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-28 14:52:17 UTC (rev 759) +++ trunk/src/main/javascript/transport/Script.js 2008-07-28 16:08:54 UTC (rev 760) @@ -94,9 +94,10 @@ * @param {DomElement} packetNode */ write: function(packetNode) { -;;; Xmpp4Js.Transport.Script.logger.debug( "Writing packet." ); + this.prepareWrite( packetNode ); - +;;; Xmpp4Js.Transport.Script.logger.debug( "Writing packet. rid="+packetNode.getAttribute("rid") ); + var xml = packetNode.toString(); // TODO check for max length constraints in browsers This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-28 14:52:09
|
Revision: 759 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=759&view=rev Author: h-iverson Date: 2008-07-28 14:52:17 +0000 (Mon, 28 Jul 2008) Log Message: ----------- added hack so that error condition can be terminal for openfire Modified Paths: -------------- trunk/src/main/javascript/transport/Base.js Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-28 05:56:18 UTC (rev 758) +++ trunk/src/main/javascript/transport/Base.js 2008-07-28 14:52:17 UTC (rev 759) @@ -575,7 +575,8 @@ errorNode = errorNode.getLength() > 0 ? errorNode.item(0) : null; // HACK these errors should be given with terminate / remote-stream-error but in Openfire they are not. - if( errorNode == null && packetNode.getAttribute("type").toString() == "terminate" ) { + if( errorNode == null && (packetNode.getAttribute("type").toString() == "terminate" || + packetNode.getAttribute("type").toString() == "terminal")) { // HACK openfire uses terminal? var condition = packetNode.getAttribute( "condition" ).toString(); var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-28 05:56:08
|
Revision: 758 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=758&view=rev Author: h-iverson Date: 2008-07-28 05:56:18 +0000 (Mon, 28 Jul 2008) Log Message: ----------- changed wait timeout to 45 because safari has a 60 second timeout and it was problematic on polls Modified Paths: -------------- trunk/src/main/javascript/transport/Base.js Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-28 05:16:47 UTC (rev 757) +++ trunk/src/main/javascript/transport/Base.js 2008-07-28 05:56:18 UTC (rev 758) @@ -53,10 +53,11 @@ */ this.port = config.port || 5222; /** - * The time to wait for a response from the server, in seconds. defaults to 60 and can be adjusted by server. + * The time to wait for a response from the server, in seconds. defaults to 45 and can be adjusted by server. + * This is 45 because Safari has a 60 second timeout and it's problematic. - 7/2008 * @private */ - this.wait = config.wait || 60; + this.wait = config.wait || 45; /** * Picked up by Observable. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-28 05:16:39
|
Revision: 757 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=757&view=rev Author: h-iverson Date: 2008-07-28 05:16:47 +0000 (Mon, 28 Jul 2008) Log Message: ----------- added more logging Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js trunk/src/main/javascript/adapter/Default.js trunk/src/main/javascript/transport/BOSH.js trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-27 22:02:28 UTC (rev 756) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-28 05:16:47 UTC (rev 757) @@ -92,6 +92,8 @@ } +Xmpp4Js.Connection.logger = Xmpp4Js.createLogger( "xmpp4js.connection" ); + Xmpp4Js.Connection.prototype = { setupTransport: function(server, port) { @@ -131,6 +133,7 @@ // TODO it would be nice to be able to give a connect // event as a parameter, that registers on this and // unregisters right after it's called. +;;; Xmpp4Js.Connection.logger.info( "Connecting to "+domain+", server="+server+", port="+port ); if( this.isConnected() ) { throw new Xmpp4Js.Error( "Already Connected" ); @@ -145,6 +148,7 @@ * Close the connection. */ close: function() { +;;; Xmpp4Js.Connection.logger.info( "Closing connection to "+this.domain ); if( !this.isConnected() ) { throw new Xmpp4Js.Error( "Not Connected" ); } @@ -161,6 +165,7 @@ * @see Xmpp4Js.PacketFilter.PacketIdFilter */ send: function(packet, callback) { +;;; Xmpp4Js.Connection.logger.debug( "Sending packet. Callback? "+(callback!=null) ); if( !this.isConnected() ) { throw new Xmpp4Js.Error( "Not Connected" ); } @@ -216,6 +221,7 @@ * @private */ onRecv: function(packetNode) { +;;; Xmpp4Js.Connection.logger.debug( "Received a packet" ); this.packetListenerManager.run( packetNode ); }, /** @@ -224,6 +230,7 @@ * @private */ onTerminalError: function(title, message, packetNode) { +;;; Xmpp4Js.Connection.logger.error( "Terminal error. title="+title+", message="+message ); this.shutdown(); this.fireEvent( "error", true, packetNode, title, message ); }, @@ -234,6 +241,7 @@ * @private */ onStreamError: function(packetNode, errorNode, errorCode, text) { +;;; Xmpp4Js.Connection.logger.error("Stream error. code="+errorCode+", text="+text ); this.shutdown(); this.fireEvent( "error", true, packetNode, errorCode, text ); }, @@ -244,6 +252,7 @@ * @private */ onError: function(packetNode) { +;;; Xmpp4Js.Connection.logger.warn("Recoverable error."); this.fireEvent( "error", false, packetNode ); }, @@ -252,6 +261,7 @@ * @private */ onBeginSession: function() { +;;; Xmpp4Js.Connection.logger.info( "Begin session. Session ID="+this.transport.sid ); this.startup(); this.fireEvent( "connect" ); }, @@ -261,6 +271,7 @@ * @private */ onEndSession: function() { +;;; Xmpp4Js.Connection.logger.info( "End session. Session ID="+this.transport.sid ); this.shutdown(); this.fireEvent( "close" ); }, @@ -286,7 +297,8 @@ * @param {Object} pauseStruct the r/w object containing info about the pause. * @private */ - onResume: function() { + onResume: function(pauseStruct) { +;;; Xmpp4Js.Connection.logger.info( "Connection resumed. Session ID="+this.transport.sid ); // deserialize our junk this.domain = pauseStruct.domain; this.jid = pauseStruct.jid; @@ -300,6 +312,7 @@ * @private */ shutdown: function() { +;;; Xmpp4Js.Connection.logger.info( "Shutting down connection" ); this.transport.un("recv", this.onRecv, this ); this.connected = false; @@ -310,6 +323,7 @@ * @private */ startup: function() { +;;; Xmpp4Js.Connection.logger.info( "Starting up connection" ); this.connected = true; this.transport.on({ @@ -340,7 +354,8 @@ * @public */ pause: function(time) { - +;;; Xmpp4Js.Connection.logger.debug( "Requesting session pause. time="+time+" seconds, Session ID="+this.transport.sid ); + // serialize transport's junk var pauseStruct = this.transport.pause(time); @@ -354,6 +369,7 @@ * @public */ resume: function(pauseStruct) { +;;; Xmpp4Js.Connection.logger.debug( "Resuming session. Session ID="+this.transport.sid ); this.setupTransport( pauseStruct.server, pauseStruct.port ); // deserialize transport's junk Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-27 22:02:28 UTC (rev 756) +++ trunk/src/main/javascript/adapter/Default.js 2008-07-28 05:16:47 UTC (rev 757) @@ -423,7 +423,7 @@ } Function.prototype.bind = function(scope) { -;;; Xmpp4Js.Lang.logger.warn( "Using Function.prototype.bind" ); +//;;; Xmpp4Js.Lang.logger.warn( "Using Function.prototype.bind" ); var args = Array.prototype.slice.call(arguments); args.unshift( this ); // add fn argument to the beginning return Xmpp4Js.Lang.bind.apply( this, args ); Modified: trunk/src/main/javascript/transport/BOSH.js =================================================================== --- trunk/src/main/javascript/transport/BOSH.js 2008-07-27 22:02:28 UTC (rev 756) +++ trunk/src/main/javascript/transport/BOSH.js 2008-07-28 05:16:47 UTC (rev 757) @@ -48,6 +48,7 @@ } +Xmpp4Js.Transport.BOSH.logger = Xmpp4Js.createLogger("xmpp4js.transport.bosh"); Xmpp4Js.Transport.BOSH.prototype = { @@ -66,6 +67,8 @@ */ write: function(packetNode) { this.prepareWrite( packetNode ); + +;;; Xmpp4Js.Transport.BOSH.logger.debug( "Writing packet." ); Xmpp4Js.Lang.asyncRequest({ @@ -93,6 +96,8 @@ onWriteResponse: function(options, success, response) { this.openRequestCount--; +;;; Xmpp4Js.Transport.BOSH.logger.debug( "Got write response." ); + var packetNode = null; if( response.responseText != null ) { @@ -128,6 +133,7 @@ // we aborted the connection, do nothing. close? } else if( !success || response.status != 200 ) { // Deprecated HTTP error conditions +;;; Xmpp4Js.Transport.BOSH.logger.warn( "Deprecated HTTP code error" ); var condition = null; if( packetNode != null ) { Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-27 22:02:28 UTC (rev 756) +++ trunk/src/main/javascript/transport/Base.js 2008-07-28 05:16:47 UTC (rev 757) @@ -271,6 +271,9 @@ if( packetNode.hasAttribute("polling") ) { this.polling = packetNode.getAttribute("polling").toString(); } + +;;; Xmpp4Js.Transport.Base.logger.debug( "Get beginSession response. Session ID="+this.sid + +", hold="+this.hold+", wait="+this.wait+", polling="+this.polling ); this.startup(); @@ -282,6 +285,7 @@ * @private */ startup: function() { +;;; Xmpp4Js.Transport.Base.logger.info( "Starting up transport" ); this.isSessionOpen = true; this.taskRunner.start( this.sendQueueTask ); this.taskRunner.start( this.sendPollTask ); @@ -292,6 +296,7 @@ * Send a terminate message, mark the sesion as closed, and stop the polling task. */ endSession: function() { +;;; Xmpp4Js.Transport.Base.logger.info( "End Session. Session ID="+this.sid ); var packetNode = this.createPacketNode(); packetNode.setAttribute( "type", "terminate" ); @@ -309,7 +314,7 @@ * @private */ shutdown: function() { -;;; Xmpp4Js.Transport.Base.logger.debug( "Transport Shutdown (stopping tasks)" ); +;;; Xmpp4Js.Transport.Base.logger.info( "Transport Shutdown (stopping tasks)" ); this.isSessionOpen = false; this.taskRunner.stop( this.sendQueueTask ); this.taskRunner.stop( this.sendPollTask ); @@ -324,6 +329,7 @@ * @param {DomElement} node */ send: function(node) { +;;; Xmpp4Js.Transport.Base.logger.debug( "Sending packet." ); this.queue.push( node ); }, @@ -346,7 +352,7 @@ * @param {DomElement} packetNode */ write: function(packetNode) { - throw new Error( "write: Not Implemented" ); +;;; Xmpp4Js.Transport.Base.logger.error( "write: Not Implemented" ); }, /** @@ -356,7 +362,7 @@ * @private */ onWriteResponse: function() { - throw new Error( "onWriteResponse: Not Implemented" ); +;;; Xmpp4Js.Transport.Base.logger.error( "onWriteResponse: Not Implemented" ); }, /** @@ -388,7 +394,7 @@ */ if( this.openRequestCount == 0 && this.queue.length == 0 ) { -;;; Xmpp4Js.Transport.Base.logger.debug( "Send Poll" ); +;;; Xmpp4Js.Transport.Base.logger.debug( "Send Poll." ); var packetNode = this.createPacketNode(); this.write( packetNode ); } @@ -407,6 +413,8 @@ return; } +;;; Xmpp4Js.Transport.Base.logger.debug( "sendQueue with "+this.queue.length+" waiting stanzas." ); + var packetNode = this.createPacketNode(); while( this.queue.length > 0 ) { @@ -464,6 +472,7 @@ // if it's the last key, reset the KeySequence and add a newkey attribute. if( isLastKey ) { +;;; Xmpp4Js.Transport.Base.logger.debug( "Resetting key sequence." ); keySeq.reset(); var newKey = keySeq.getNextKey(); @@ -492,6 +501,8 @@ }, pause: function(time) { +;;; Xmpp4Js.Transport.Base.logger.info( "Pausing session." ); + var pauseNode = this.createPacketNode(); pauseNode.setAttribute( "pause", time ); @@ -533,6 +544,7 @@ }, resume: function(pauseStruct) { +;;; Xmpp4Js.Transport.Base.logger.info( "Resume session. Session ID="+pauseStruct.sid+", Request ID="+pauseStruct.rid ); // this.maxpause = pauseStruct.maxpause; this.maxpause = pauseStruct.maxpause; @@ -557,6 +569,7 @@ }, handleErrors: function(packetNode) { + // TODO add log messages here var errorNode = packetNode.getElementsByTagNameNS("http://etherx.jabber.org/streams","error"); errorNode = errorNode.getLength() > 0 ? errorNode.item(0) : null; Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-27 22:02:28 UTC (rev 756) +++ trunk/src/main/javascript/transport/Script.js 2008-07-28 05:16:47 UTC (rev 757) @@ -61,6 +61,8 @@ Xmpp4Js.Transport.Script.superclass.constructor.call( this, config ); } +Xmpp4Js.Transport.Script.logger = Xmpp4Js.createLogger( "xmpp4js.transport.script" ); + Xmpp4Js.Transport.Script.prototype = { isPausing: false, @@ -92,7 +94,7 @@ * @param {DomElement} packetNode */ write: function(packetNode) { - +;;; Xmpp4Js.Transport.Script.logger.debug( "Writing packet." ); this.prepareWrite( packetNode ); var xml = packetNode.toString(); @@ -128,7 +130,11 @@ }, onScriptError: function(scriptElem) { - if( this.isPausing ) { return; } + if( this.isPausing ) { +;;; Xmpp4Js.Transport.Script.logger.debug( "Script error while pausing. Ignoring error." ); + return; + } +;;; Xmpp4Js.Transport.Script.logger.error( "Deprecated HTTP code script error." ); document.body.removeChild( scriptElem ); @@ -156,6 +162,7 @@ * @private */ onWriteResponse: function( xml ) { +;;; Xmpp4Js.Transport.Script.logger.debug( "Got write response." ); this.openRequestCount--; // TODO character replacement (18.3)? This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-27 22:02:19
|
Revision: 756 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=756&view=rev Author: h-iverson Date: 2008-07-27 22:02:28 +0000 (Sun, 27 Jul 2008) Log Message: ----------- added log4js to try to avoid console stuff and got rid of some old compat stuff Modified Paths: -------------- trunk/pom.xml trunk/src/assembler/xmpp4js.xml trunk/src/main/javascript/adapter/Default.js trunk/src/main/javascript/ext/DataForm.js trunk/src/main/javascript/transport/Base.js trunk/src/test/javascript/PacketReaderTest.html trunk/src/test/javascript/broken/DataFormTest.html Removed Paths: ------------- trunk/src/main/javascript/console.js trunk/src/main/javascript/msie-createElementNS.js trunk/src/main/javascript/msie-importNode.js Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/pom.xml 2008-07-27 22:02:28 UTC (rev 756) @@ -27,6 +27,12 @@ <type>javascript</type> <version>3.1-SNAPSHOT</version> </dependency> + <dependency> + <groupId>de.berlios.log4js</groupId> + <artifactId>log4js</artifactId> + <type>javascript</type> + <version>1.0-RC1</version> + </dependency> </dependencies> <build> <extensions> Modified: trunk/src/assembler/xmpp4js.xml =================================================================== --- trunk/src/assembler/xmpp4js.xml 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/assembler/xmpp4js.xml 2008-07-27 22:02:28 UTC (rev 756) @@ -8,9 +8,7 @@ <include>adapter/Default.js</include> <!-- utils --> - <include>console.js</include> <include>Jid.js</include> - <include>msie-createElementNS.js</include> <include>DomBuilder.js</include> <!-- packets --> Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/main/javascript/adapter/Default.js 2008-07-27 22:02:28 UTC (rev 756) @@ -1,6 +1,18 @@ var Xmpp4Js = {}; + +Xmpp4Js.logLevel = Log4js.Level.ALL; +Xmpp4Js.appender = new Log4js.ConsoleAppender(); +Xmpp4Js.createLogger = function(logId) { + var logger = Log4js.getLogger( logId ); + logger.setLevel( Xmpp4Js.logLevel ); + logger.addAppender( Xmpp4Js.appender ); + + return logger; +} + + /** * Do not fork for a browser if it can be avoided. Use feature detection when * you can. Use the user agent as a last resort. YAHOO.env.ua stores a version @@ -153,6 +165,8 @@ }(); Xmpp4Js.Lang = { + logger: Xmpp4Js.createLogger("xmpp4js.lang"), + /** * Determines whether or not the property was added * to the object instance. Returns false if the property is not present @@ -409,7 +423,7 @@ } Function.prototype.bind = function(scope) { -;;; console.warn( "Using Function.prototype.bind" ); +;;; Xmpp4Js.Lang.logger.warn( "Using Function.prototype.bind" ); var args = Array.prototype.slice.call(arguments); args.unshift( this ); // add fn argument to the beginning return Xmpp4Js.Lang.bind.apply( this, args ); Deleted: trunk/src/main/javascript/console.js =================================================================== --- trunk/src/main/javascript/console.js 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/main/javascript/console.js 2008-07-27 22:02:28 UTC (rev 756) @@ -1,10 +0,0 @@ -if( window['console'] == undefined ) { - console = { - info: Xmpp4Js.Lang.noOp, - log: Xmpp4Js.Lang.noOp, - dir: Xmpp4Js.Lang.noOp, - dirxml: Xmpp4Js.Lang.noOp, - warn: Xmpp4Js.Lang.noOp, - error: Xmpp4Js.Lang.noOp - } -} Modified: trunk/src/main/javascript/ext/DataForm.js =================================================================== --- trunk/src/main/javascript/ext/DataForm.js 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/main/javascript/ext/DataForm.js 2008-07-27 22:02:28 UTC (rev 756) @@ -338,7 +338,7 @@ // dataForm, formId, template if( arguments.length > 1 ) { -;;; console.warn( "Using deprecated ctor for DataFormView" ); +//;;; console.warn( "Using deprecated ctor for DataFormView" ); config = { dataForm: arguments[0], @@ -413,7 +413,7 @@ * @deprecated in favor of renderAndReturn */ getRenderedNode: function() { -;;; console.warn( "renderAndReturn is deprecated." ); +//;;; console.warn( "renderAndReturn is deprecated." ); return this.renderAndReturn(); }, Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/main/javascript/transport/Base.js 2008-07-27 22:02:28 UTC (rev 756) @@ -215,6 +215,8 @@ } +Xmpp4Js.Transport.Base.logger = Xmpp4Js.createLogger("xmpp4js.transport.base"); + Xmpp4Js.Transport.Base.prototype = { @@ -307,7 +309,7 @@ * @private */ shutdown: function() { -;;; console.debug( "Transport Shutdown (stopping tasks)" ); +;;; Xmpp4Js.Transport.Base.logger.debug( "Transport Shutdown (stopping tasks)" ); this.isSessionOpen = false; this.taskRunner.stop( this.sendQueueTask ); this.taskRunner.stop( this.sendPollTask ); @@ -376,7 +378,6 @@ * @private */ sendPoll: function() { -;;; console.debug( "Send Poll" ); // if we're trying to poll too frequently /*var now = new Date().getTime(); @@ -387,6 +388,7 @@ */ if( this.openRequestCount == 0 && this.queue.length == 0 ) { +;;; Xmpp4Js.Transport.Base.logger.debug( "Send Poll" ); var packetNode = this.createPacketNode(); this.write( packetNode ); } Modified: trunk/src/test/javascript/PacketReaderTest.html =================================================================== --- trunk/src/test/javascript/PacketReaderTest.html 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/test/javascript/PacketReaderTest.html 2008-07-27 22:02:28 UTC (rev 756) @@ -41,7 +41,6 @@ var wasInvoked = false; con.addPacketListener( function(stanza) { wasInvoked = true; - console.dir( stanza ); assertEquals( stanzaNode, stanza.getNode() ); } ); Modified: trunk/src/test/javascript/broken/DataFormTest.html =================================================================== --- trunk/src/test/javascript/broken/DataFormTest.html 2008-07-27 21:43:41 UTC (rev 755) +++ trunk/src/test/javascript/broken/DataFormTest.html 2008-07-27 22:02:28 UTC (rev 756) @@ -25,8 +25,7 @@ var node = loadTestPacket( "packets/dataform_get.xml" ); df.read( node ); - - console.dir( df ); + } </script> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-27 21:43:37
|
Revision: 755 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=755&view=rev Author: h-iverson Date: 2008-07-27 21:43:41 +0000 (Sun, 27 Jul 2008) Log Message: ----------- removed unused files Removed Paths: ------------- trunk/src/main/javascript/BayeuxXmppClient.js trunk/src/main/javascript/JabberClient.js Deleted: trunk/src/main/javascript/BayeuxXmppClient.js =================================================================== --- trunk/src/main/javascript/BayeuxXmppClient.js 2008-07-27 20:36:44 UTC (rev 754) +++ trunk/src/main/javascript/BayeuxXmppClient.js 2008-07-27 21:43:41 UTC (rev 755) @@ -1,83 +0,0 @@ -Xmpp4Js.Lang.namespace( "Xmpp4Js" ); - -/** - * This is an experimental Bayeux connection class that is not currently used. - * @constructor - */ -Xmpp4Js.BayeuxXmppClient = function() { - this.addEvents({ - "beforesend" : true, - "recv" : true - }); - this.comet = dojox.cometd; - - this.comet.init( "/CometTest/cometd" ); - this.comet.subscribe( "/service/jabber", this.handlePacket.bind(this) ); -} - -Xmpp4Js.BayeuxXmppClient .prototype = { - connect : function() { - // no need to do anything yet - //this.comet.publish( "/service/jabber", {packet : ""} ); - }, - handlePacket : function(msg) { - var packetXml = msg.data.packet; - - var doc = new DOMParser().parseFromString(packetXml, 'text/xml'); - - var stanza = this.stanzaProvider.fromNode( doc.documentElement ); - this.fireEvent( "recv", stanza ); - }, - send : function(stanza, callback) { - this.fireEvent( "beforesend", stanza ); - var xml = serializeNode( stanza.getNode() ); - - - - // register a temporary listener for the packet ID - if( callback ) { - var id = packet.getId(); - var filter = new Xmpp4Js.PacketFilter.PacketIdFilter( id ); - - var wrappedListener; - var wrappedCallback = function(packet) { - this.removePacketListener( wrappedListener ); - callback(packet); - }.bind(this); - wrappedListener = this.addPacketListener( wrappedCallback, filter ); - } - - this.comet.publish( "/service/jabber", {packet : xml}); - }, - addPacketListener : function(listener, filter) { - var wrappedListener = function(packet) { - if( filter && filter.accept(packet) ) { - listener(packet); - } - }; - this.on( "recv", wrappedListener, this); - - return wrappedListener; - }, - removePacketListener : function( listener ) { - this.un( "recv", listener) - }, - - - - authenticatePlaintext : function( username, password, resource ) { - var iq = this.getPacketHelper().createAuthPlaintext( username, password, resource ); - iq.send( this ); - }, - - getPacketHelper : function() { - if( this.packetHelper == null ) { - this.packetHelper = new Xmpp4Js.Packet.PacketHelper(); - } - - return this.packetHelper; - } - -} - -Xmpp4Js.Lang.extend(Xmpp4Js.BayeuxXmppClient , Xmpp4Js.Event.EventProvider, Xmpp4Js.BayeuxXmppClient .prototype); \ No newline at end of file Deleted: trunk/src/main/javascript/JabberClient.js =================================================================== --- trunk/src/main/javascript/JabberClient.js 2008-07-27 20:36:44 UTC (rev 754) +++ trunk/src/main/javascript/JabberClient.js 2008-07-27 21:43:41 UTC (rev 755) @@ -1,638 +0,0 @@ -// Copyright (C) 2007 Harlan Iverson <h.iverson at gmail.com> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - -/** -* @class The main class in establishing a Jabber connection. -* @param {String} server The domain (and hostname) of the Jabber server to connect to. -* @param {String} baseUrl The URL to an XEP-0124 HTTP Binding proxy--bound by same origin policy. -* @constructor -* @deprecated used Xmpp4Js.Connection instead -*/ -Xmpp4Js.JabberConnection = function(server, baseUrl) { - /** @private @type String */ - this.baseUrl = baseUrl; - - /** TODO let domain and server be different, and specify port. @private @type String */ - this.domain = server; - /** @private @type String */ - this.server = server; - /** @private @type int */ - this.port = 5222; - - /** @private @type boolean */ - this.connected = false; - /** @private @type Xmpp4Js.IO.HttpBindingStream */ - this.stream = new Xmpp4Js.IO.HttpBindingStream( baseUrl ); - - /** @private @type Xmpp4Js.Roster.PresenceManager */ - this.presenceManager = new Xmpp4Js.Roster.PresenceManager(); - - this.addPacketListener( this._onTerminalError.bind(this), new Xmpp4Js.PacketFilter.TerminalErrorPacketFilter() ); - this.addPacketListener( this._onRecoverableError.bind(this), new Xmpp4Js.PacketFilter.RecoverableErrorPacketFilter() ); - this.addPacketListener( this.presenceManager.presencePacketListener.bind(this.presenceManager), new Xmpp4Js.PacketFilter.PacketTypeFilter(Xmpp4Js.Packet.Presence) ); - - - this._registerEvents(); -} - -Xmpp4Js.JabberConnection.prototype = { - /** - * @private - */ - _registerEvents : function() { - this.addEvents({ - /** - * @event onconnect - * Fires when connect has completed - */ - "onconnect" : true, - - /** - * @event onauth - * Fires when auth has completed - */ - "onauth" : true, - - /** - * @event beginsession - * Fired when beginsession is finished and authentication / registration - * / normal operation can happen. - */ - "beginsession": true, - - /** - * Fired when a terminal (non-recoverable) error is received from the server. - * - * @event terminate - * @param connection {Xmpp4Js.JabberConnection} - * @param title {String} the reason for termination - * @param message {String} an explanation of the termination - * @param bodyElement {Element} the body element, to access app-specific info. - */ - "terminate" : true, - - /** - * Fired when a recoverable error is received from the server. - * - * @event error - * @param connection {Xmpp4Js.JabberConnection} - * @param bodyElement {Element} the body element, to access app-specific info. - */ - "error" : true, - - /** - * Fired when the connection is closed by the client. - * - * @event error - * @param connection {Xmpp4Js.JabberConnection} - * @todo add unit test - */ - "close" : true, - - "autherror" : true - }); - }, - - /** - * Fire error event. - * @private - */ - _onRecoverableError : function(bodyElement) { - this.fireEvent( "error", this, bodyElement ); - }, - - /** - * Fire terminate event. Automatically invokes endSession. - * @private - */ - _onTerminalError : function(bodyElement) { - var condition = bodyElement.getAttribute( "condition" ); - - var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title - var message = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].message; - - this.fireEvent( "terminate", this, title, message, bodyElement ); - this.endSession(); - }, - - /** - * Adds a packet listener and returns its function. See PacketReader. - * @return Function - * @see Xmpp4Js.IO.PacketReader#addPacketListener - */ - addPacketListener : function( listener, filter ) { - return this.stream.getReader().addPacketListener( listener, filter ); - }, - - /** - * Removes a packet listener by function. See PacketReader. - * @param {Function} listener The listener returned by addPacketListener - * @see Xmpp4Js.IO.PacketReader#removePacketListener - */ - removePacketListener : function( listener ) { - return this.stream.getReader().removePacketListener( listener ); - }, - - /** - * Send a packet across the wire, and register a PacketIdListener if a callback - * is supplied - * - * @param {Xmpp4Js.Packet.Base} packet - * @param {function} callback The callback to be invoked when the server sends a response with same ID. - * @see Xmpp4Js.PacketFilter.PacketIdFilter - */ - send : function( packet, callback ) { - - - /* - if( callback ) { - var id = packet.getId(); - - var pf = new Xmpp4Js.PacketFilter.PacketIdFilter(id); - var listener = function(packet) { - callback(packet); - this.removePacketListener( listener ); - }.bind(this); - - this.addPacketListener( listener, pf ); - } - */ - - if( callback ) { - var id = packet.getId(); - - - var pf = new Xmpp4Js.PacketFilter.PacketIdFilter( id ); - var listener = function( stanza ) { - this.removePacketListener( listener ); - - callback( stanza ); - }.bind(this); - - this.addPacketListener( listener, pf ); - } - - - this.stream.pw.write( packet ); - }, - - /** - * The same as send, except it takes an XML string instead of a Packet object. - * - * @param {String} xml - * @param {function} callback The callback to be invoked when the server sends a response with same ID. - * @see #send - */ - sendXml : function( xml, callback ) { - // parse XML string into a packet - var doc = parseXmlToDoc(xml); - - var stanza = this.getStream().getReader().stanzaProvider.fromNode( doc.documentElement ); - - return this.send( stanza, callback ); - }, - - /** - * Sends the initial request to the jabber server. This must be called before any - * other requests can be sent. The 'beginsession' event is fired when packets - * may be sent. - */ - beginSession : function() { - // Only begin a session that is not connected - if (!this.connected) { - var writer = this.stream.getWriter(); - - var packet = this.getPacketHelper().createPacket(); - - packet.setAttribute( "wait", writer.wait ); - packet.setAttribute( "hold", writer.hold ); - packet.setAttribute( "to", this.domain ); - packet.setAttribute( "route", "xmpp:" + this.server + ":" + this.port); - packet.setAttribute( "ver", "1.6"); - packet.setAttribute( "ack", "1"); - packet.setAttribute( "xml:lang", "en"); - packet.setAttribute( "xmlns:xmpp", "urn:xmpp:xbosh"); - packet.setAttribute( "xmpp:version", "1.0" ); - - /* - packet.appendChild( - Builder.node("features", {xmlns:"http://etherx.jabber.org/streams"}, [ - Builder.node("mechanisms", {xmlns: "urn:ietf:params:xml:ns:xmpp-sasl"}, [ - Builder.node( "mechanism", "DIGEST-MD5" ), - Builder.node( "mechanism", "PLAIN" ) - ]) - ] ) - ); - */ - - var listener = function( frame ) { - // ONLY the packets we want contain a sid attribute - if( !frame.hasAttribute( "sid" ) ) { - console.error( "no sid on response" ); - return; - } - - this.removePacketListener( listener ); - - var writer = this.stream.getWriter(); - - // TODO refactor this stuff into HttpBindingStream. - writer.sid = frame.getAttribute( "sid" ); - writer.maxRequests = frame.getAttribute( "requests" ); - writer.hold = writer.maxRequests - 1; - writer.wait = frame.getAttribute("wait"); - - this.connected = true; - - writer.setPolling( true ); - - this.fireEvent( "beginsession", this ); - - //this.stream.setAutoFlush(true); - }.bind(this); - - var pf = new Xmpp4Js.PacketFilter.RawPacketFilter(); - - this.addPacketListener( listener, pf ); - - // write the inital request and stop sending packets until - // we get a response. - //this.stream.setAutoFlush(false); - this.stream.getWriter().writeRaw( packet ); - //this.stream.getWriter().flush(); - - } - }, - - /** - * Sends a request to the server to pause for 120 seconds. I don't believe - * this currently works. - */ - pause : function() { - var packet = this.getPacketHelper().createPacket(); - packet.setAttribute( "pause", 120 ); - this.stream.getWriter().writeRaw( packet ); - - // TODO store stuff in cookie... - // host,port,secure,_rid,_last_rid,_wait,_min_polling,_inactivity,_hold,_last_requests,_pause - - }, - - /** - * Resumes a paused connection. Not currently implemented. - */ - resume : function() { - - }, - - /** - * Send the terminate request to end the session. Fires the "close" event. - */ - endSession : function() { - var writer = this.stream.getWriter(); - - var packet = this.getPacketHelper().createPacket(); - - packet.setAttribute( "type", "terminate" ); - packet.setAttribute( "wait", writer.wait ); - packet.setAttribute( "hold", writer.hold ); - packet.setAttribute( "to", this.domain ); - packet.setAttribute( "route", "xmpp:" + this.domain + ":"+this.port); - packet.setAttribute( "ver", "1.6"); - packet.setAttribute( "ack", "1"); - packet.setAttribute( "xml:lang", "en"); - packet.setAttribute( "xmlns:xmpp", "urn:xmpp:xbosh"); - packet.setAttribute( "xmpp:version", "1.0" ); - - this.stream.getWriter().writeRaw( packet ); - //this.stream.getWriter().flush(); - - // FIXME for some reason terminate isn't sent if this is called... but it stops the flushing. - this.stream.setAutoFlush(false); - - this.connected = false; - - this.fireEvent( "close", this ); - }, - - /** - * Returns the Jid of the currently connected user, if any. - * @type Xmpp4Js.Jid - */ - getJid : function() { - return new Xmpp4Js.Jid(this.jid); - }, - - /** - * Authenticate as anonymous on the jabber server. Currently works by sending - * an empty auth packet which is supported on Openfire, but ideally it would - * use SASL anonymous. - */ - // TODO make this a packet type or something... that means it will need - // a reference to connection in order to register its filter - authenticateAnonymous : function() { - var iq = this.getPacketHelper().createIQ( this.domain, "set", "jabber:iq:auth" ); - iq.setId( "auth1" ); - - this.send( iq, function( responseIq ) { - if( responseIq.getType() == 'error' ) { - console.info( "error doing anonymous auth" ); - } else { - console.info( "anonymous auth success" ); - this.jid = responseIq.getTo(); - - this.fireEvent( "onconnect" ); - this.fireEvent( "onauth" ); - } - }.bind(this) ); - - }, - - /** - * Send a 'plaintext' authentication request. The 'onauth' event is fired upon success. - * Packets not requiring an authenticated session may be exchanged before 'onauth' comes. - * @param {String} username The username, without host part, to authenticate as. - * @param {String} password The plaintext password - * @param {String} resource The resource to use. 'xmpp4js' is the sensible default. - */ - authenticatePlaintext : function( username, password, resource ) { - if( !resource ) { resource = 'xmpp4js'; }; - var iq = this.getPacketHelper().createAuthPlaintext( username, password, resource ); - iq.send( this ); - }, - - /** - * Authenticates using SASL MD5. Currently flawed and hardly works. Fires the 'onauth' event on success. - * - * TODO clean up... messy as crap, but works. - * get rid of sendXml stuff, add comments, etc. tired and its late. - * - * @param {String} username The username, without host part, to authenticate as. - * @param {String} password The plaintext password - * @param {String} resource The resource to use. 'xmpp4js' is the sensible default. - * - * @see #authenticatePlaintext - */ - authenticateMd5 : function( username, password, resource ) { - if( !resource ) { resource = 'xmpp4js'; }; - - var sasl = new Md5Sasl( username, password, this.domain ); - - var saslListener = function(bodyElement) { - var elem = bodyElement.firstChild; - - if( elem.localName == "challenge" ) { - var challenge = elem.textContent; - var fields = sasl.deserializeFields(sasl.decodeChallenge(challenge)); - - - console.dir( fields ); - - var response = ""; - if(fields.qop == "auth") { - response = sasl.computeChallengeResponse( challenge ); - - console.dir( sasl.deserializeFields(sasl.decodeChallenge(response)) ); - } else if( fields.rspauth ) { - if( !sasl.checkResponse( challenge ) ) { - // problem... - throw new Error( "Invalid response from server!" ); - } - } - - - - this.sendXml( '<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">'+response+'</response>' ); - } else if( elem.localName == "success" ) { - // w00t. - var writer = this.stream.getWriter(); - - var packet = this.getPacketHelper().createPacket(); - packet.setAttribute( "xml:lang", "en"); - packet.setAttribute( "xmlns:xmpp", "urn:xmpp:xbosh"); - packet.setAttribute( "xmpp:restart", "true" ); - - writer.writeRaw( packet ); - - var bindIq = new Xmpp4Js.Packet.IQ( null, "set", "jabber:client" ); - bindIq.setId( "bind_1" ); - - var doc = bindIq.getNode().ownerDocument; - var bindNode = bindIq.getNode().appendChild( createElementNS(doc, "urn:ietf:params:xml:ns:xmpp-bind", "bind" ) ); - var resourceNode = bindNode.appendChild( createElementNS(doc, "urn:ietf:params:xml:ns:xmpp-bind", "resource" ) ); - resourceNode.textContent = resource; - - this.send( bindIq, function(respIq) { - - // FIXME bug that casuses infinite loop right here. For some reason - // this listener is being invoked for sess_1, which means - // that there's a bug in the packet reader stuff somewhere. aside - // from that, sasl auth works. - - - var sessionIq = new Xmpp4Js.Packet.IQ( null, "set", "jabber:client" ); - sessionIq.setId( "sess_1" ); - - var doc = sessionIq.getNode().ownerDocument; - var sessionNode = sessionIq.getNode().appendChild( createElementNS(doc, "urn:ietf:params:xml:ns:xmpp-session", "session" ) ); - - this.send( sessionIq, function(respIq) { - this.jid = respIq.getTo(); - console.info( "authenticated as "+this.jid ); - - this.fireEvent( "onconnect" ); - this.fireEvent( "onauth" ); - }.bind(this)); - - }.bind(this)); - - cleanup(); - } else if( elem.localName == "failure" ) { - cleanup(); - this.close(); - } - }.bind(this); - - var cleanup = function() { - this.removePacketListener(saslListener); - }.bind(this); - - this.addPacketListener( saslListener, new Xmpp4Js.PacketFilter.RawPacketFilter() ); - - this.sendXml( '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>' ); - - /* - - var anonAuth = DomHelper.node( - "auth", - { - xmlns: "urn:ietf:params:xml:ns:xmpp-sasl", - mechanism: "ANONYMOUS" - } - ); - - // http://tools.ietf.org/html/draft-saintandre-rfc3920bis-04 - var md5Auth = DomHelper.node( - "auth", - { - xmlns: "urn:ietf:params:xml:ns:xmpp-sasl", - mechanism: "DIGEST-MD5" - } - ); - - var plainAuth = DomHelper.node( - "auth", - { - xmlns: "urn:ietf:params:xml:ns:xmpp-sasl", - mechanism: "PLAIN" - } - , - [ - username+"@"+this.domain+String.fromCharCode(0)+username+String.fromCharCode(0)+password - ] - ); - */ - }, - - /** - * Another implementation of authenticatePlaintext. Dunno. - * @see #authenticatePlaintext - */ - authenticatePlaintext2 : function( username, password, resource ) { - var iq = this.getPacketHelper().createIQ( this.domain, "set", "jabber:iq:auth" ); - iq.setId( "auth1" ); - - var query = iq.getQuery(); - var doc = query.ownerDocument; - - query.appendChild( doc.createElement( "username" ) ).textContent = username; - query.appendChild( doc.createElement( "password" ) ).textContent = password; - query.appendChild( doc.createElement( "resource" ) ).textContent = resource; - query.appendChild( doc.createElement( "plaintext" ) ); - - this.send( iq, function( responseIq ) { - if( responseIq.getType() == 'error' ) { - alert( "error doing plaintext auth" ); - } else { - alert( "plaintext auth success" ); - this.jid = responseIq.getTo(); - } - } ); - }, - - /** - * Register an account on the remote jabber server. This needs to be refactored out of here. - */ - register : function( username, password, callback ) { - var iq = this.getPacketHelper().createIQ( this.domain, "set", "jabber:iq:register" ); - iq.setId( "reg1" ); - - var query = iq.getQuery(); - var doc = query.ownerDocument; - - query.appendChild( doc.createElement( "username" ) ).textContent = username; - query.appendChild( doc.createElement( "password" ) ).textContent = password; - - this.send( iq, function( regIq ) { - if( regIq.getType() == 'error' ) { - alert( "error doing registration" ); - } - if(callback){ callback( regIq ); } - } ); - }, - - /** - * Unregister an account on the remote jabber server. This needs to be refactored out of here. - */ - unregister : function() { - var iq = this.getPacketHelper().createIQ( this.domain, "set", "jabber:iq:register" ); - iq.setId( "unreg1" ); - - var query = iq.getQuery(); - var doc = query.ownerDocument; - - query.appendChild( doc.createElement( "remove" ) ); - - this.send( iq, function( packet ) { - if( iq.getType() == 'error' ) { - alert( "error doing unregistration" ); - } - } ); - }, - - /** - * Gets the presence manager for the current connection. - * - * @return Xmpp4Js.Roster.PresenceManager - */ - getPresenceManager : function() { - return this.presenceManager - }, - - /** - * No idea if this is even used. - * @private - */ - elemToXml : function( elem ) { - var xml = Try.these( - function() { return (new XMLSerializer()).serializeToString(elem); }, - function() { return (new XMLSerializer()).serializeToString(elem.ownerDocument); }, - function() { return elem.xml; } - ); - - return xml; - }, - - - - /** - * @return Xmpp4Js.Packet.PacketHelper - */ - getPacketHelper : function() { - if( this.packetHelper == null ) { - this.packetHelper = new Xmpp4Js.Packet.PacketHelper(); - } - - return this.packetHelper; - }, - - setPacketHelper : function(packetHelper) { - this.packetHelper = packetHelper; - }, - - /** - * @return Xmpp4Js.IO.HttpBindingStream - */ - getStream : function() { - return this.stream; - } -} - -Xmpp4Js.Lang.extend(Xmpp4Js.JabberConnection, Xmpp4Js.Event.EventProvider, Xmpp4Js.JabberConnection.prototype); - -/** - * @constructor - * @extends Xmpp4Js.JabberConnection - * @deprecated Used by tests, but is worthless after refactoring - */ -Xmpp4Js.XmppDummyConnection = function(server, baseUrl) { - Xmpp4Js.XmppDummyConnection.superclass.constructor.call(this, server, baseUrl); -} - -Xmpp4Js.Lang.extend(Xmpp4Js.XmppDummyConnection, Xmpp4Js.JabberConnection, {}); - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-27 20:36:37
|
Revision: 754 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=754&view=rev Author: h-iverson Date: 2008-07-27 20:36:44 +0000 (Sun, 27 Jul 2008) Log Message: ----------- - moved pause / resume event listeners to their own onPause and onResume - made shutdown / startup functions not call connect/close events. instead begin and end sessions do. this changes events a little bit, in that close is no longer called after errors Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-27 20:22:38 UTC (rev 753) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-27 20:36:44 UTC (rev 754) @@ -115,31 +115,8 @@ streamerror: this.onStreamError, beginsession: this.onBeginSession, endsession: this.onEndSession, - pause: function(pauseStruct) { - // serialize our junk (domain is covered by transport) - pauseStruct.jid = this.jid; - - // stop doing stuff - // will this cause problems collecting any last packet? - this.connected = false; - this.transport.un("recv", this.onRecv, this ); - - this.fireEvent( "pause", pauseStruct ); - }, - resume: function(pauseStruct) { - // deserialize our junk - this.domain = pauseStruct.domain; - this.jid = pauseStruct.jid; - - // return to connected state - this.connected = true; - this.transport.on({ - scope: this, - recv: this.onRecv - }); - - this.fireEvent( "resume", pauseStruct ); - } + pause: this.onPause, + resume: this.onResume // recv will be added in beginSession. } }); @@ -276,6 +253,7 @@ */ onBeginSession: function() { this.startup(); + this.fireEvent( "connect" ); }, /** @@ -284,9 +262,40 @@ */ onEndSession: function() { this.shutdown(); + this.fireEvent( "close" ); }, /** + * Event handler for when the transport session is paused. Bubbles the event + * through to listeners on this connection. + * + * @param {Object} pauseStruct the r/w object containing info about the pause. + * @private + */ + onPause: function(pauseStruct) { + // serialize our junk (domain is covered by transport) + pauseStruct.jid = this.jid; + this.fireEvent( "pause", pauseStruct ); + this.shutdown(); + }, + + /** + * Event handler for when the transport session is resumed. Bubbles the event + * through to listeners on this connection. + * + * @param {Object} pauseStruct the r/w object containing info about the pause. + * @private + */ + onResume: function() { + // deserialize our junk + this.domain = pauseStruct.domain; + this.jid = pauseStruct.jid; + + this.startup(); + this.fireEvent( "resume", pauseStruct ); + }, + + /** * Set connected to false, fire the close event, and remove the recv listener. * @private */ @@ -294,7 +303,6 @@ this.transport.un("recv", this.onRecv, this ); this.connected = false; - this.fireEvent( "close" ); }, /** @@ -308,8 +316,6 @@ scope: this, recv: this.onRecv }); - - this.fireEvent( "connect" ); }, /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-27 20:22:30
|
Revision: 753 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=753&view=rev Author: h-iverson Date: 2008-07-27 20:22:38 +0000 (Sun, 27 Jul 2008) Log Message: ----------- added initial stream error handling code Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js trunk/src/main/javascript/transport/BOSH.js trunk/src/main/javascript/transport/Base.js trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-26 20:39:04 UTC (rev 752) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-27 20:22:38 UTC (rev 753) @@ -112,6 +112,7 @@ scope: this, termerror: this.onTerminalError, error: this.onError, + streamerror: this.onStreamError, beginsession: this.onBeginSession, endsession: this.onEndSession, pause: function(pauseStruct) { @@ -251,6 +252,16 @@ }, /** + * Shutdown before firing error event to give the listener an opportunity + * to reconnect. + * @private + */ + onStreamError: function(packetNode, errorNode, errorCode, text) { + this.shutdown(); + this.fireEvent( "error", true, packetNode, errorCode, text ); + }, + + /** * Handle non-terminal errors * @param {DomElement} packetNode * @private Modified: trunk/src/main/javascript/transport/BOSH.js =================================================================== --- trunk/src/main/javascript/transport/BOSH.js 2008-07-26 20:39:04 UTC (rev 752) +++ trunk/src/main/javascript/transport/BOSH.js 2008-07-27 20:22:38 UTC (rev 753) @@ -125,10 +125,9 @@ session is still active. */ if( response.status == -1 ) { - // we aborted the transaction, do nothing. + // we aborted the connection, do nothing. close? } else if( !success || response.status != 200 ) { - // 17.2 Terminal Binding Conditions - this.shutdown(); + // Deprecated HTTP error conditions var condition = null; if( packetNode != null ) { @@ -140,25 +139,28 @@ } 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 + var title = "Unknown Error"; + var message = "There was an unknown error with the connection."; - // 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 ); + var errorPacketNode = this.createPacketNode(); + errorPacketNode.setAttribute( "type", "terminate" ); + errorPacketNode.setAttribute( "condition", condition ); + + try { + this.handleErrors( errorPacketNode ); + } catch(e) { + this.shutdown(); + } } else { - this.fireEvent( "recv", packetNode ); + try { + // this will throw an exception if there is an error. + this.handleErrors( packetNode ); + + this.fireEvent( "recv", packetNode ); + } catch(e) { + this.shutdown(); + } } } } Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-26 20:39:04 UTC (rev 752) +++ trunk/src/main/javascript/transport/Base.js 2008-07-27 20:22:38 UTC (rev 753) @@ -187,6 +187,9 @@ */ termerror : true, + + streamerror : true, + /** * @event sessionStarted * @@ -304,6 +307,7 @@ * @private */ shutdown: function() { +;;; console.debug( "Transport Shutdown (stopping tasks)" ); this.isSessionOpen = false; this.taskRunner.stop( this.sendQueueTask ); this.taskRunner.stop( this.sendPollTask ); @@ -372,6 +376,8 @@ * @private */ sendPoll: function() { +;;; console.debug( "Send Poll" ); + // 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)) ) { @@ -429,7 +435,7 @@ */ addRid: function( packetNode ) { if( this.rid !== null ) { - packetNode.setAttribute( "rid", this.rid++ ); + packetNode.setAttribute( "rid", ++this.rid ); } }, @@ -546,6 +552,52 @@ // give others an opportunity to deserialize properties this.fireEvent( "resume", pauseStruct ); + }, + + handleErrors: function(packetNode) { + var errorNode = packetNode.getElementsByTagNameNS("http://etherx.jabber.org/streams","error"); + errorNode = errorNode.getLength() > 0 ? errorNode.item(0) : null; + + // HACK these errors should be given with terminate / remote-stream-error but in Openfire they are not. + if( errorNode == null && packetNode.getAttribute("type").toString() == "terminate" ) { + var condition = packetNode.getAttribute( "condition" ).toString(); + + var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title; + var message = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].message; + + this.fireEvent( "termerror", packetNode, title, message ); + throw new Error( "Error in packet" ); + } 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 ); + throw new Error( "Error in packet" ); + } else if(errorNode != null) { + // loop through stream nodes to find the condition and + // optionally text + var childNodes = errorNode.getChildNodes(); + for( var i = 0; i < childNodes.getLength(); i++ ) { + var node = childNodes.item(i); + if( node.getNamespaceURI() == "urn:ietf:params:xml:ns:xmpp-streams" ) { + if( node.getLocalName() == "text" ) { + var text = node.getText(); + } else { + var errorCode = node.getLocalName(); + } + } + } + + this.fireEvent( "streamerror", packetNode, errorNode, errorCode, text ); + throw new Error( "Error in packet" ); + } } } Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-26 20:39:04 UTC (rev 752) +++ trunk/src/main/javascript/transport/Script.js 2008-07-27 20:22:38 UTC (rev 753) @@ -135,14 +135,18 @@ // we can't find out anything about what the error is. var condition = "undefined-condition"; - var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title; - var message = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].message; + var title = "Unknown Error"; + var message = "There was an unknown error with the connection."; var packetNode = this.createPacketNode(); packetNode.setAttribute( "type", "terminate" ); packetNode.setAttribute( "condition", condition ); - this.fireEvent( "termerror", title, message, packetNode ); + try { + this.handleErrors( packetNode ); + } catch(e) { + this.shutdown(); + } }, /** @@ -152,45 +156,19 @@ * @private */ onWriteResponse: function( xml ) { - this.openRequestCount--; - + this.openRequestCount--; + // TODO character replacement (18.3)? + var packetNode = new DOMImplementation().loadXML( xml ).documentElement; - var packetNode = new DOMImplementation().loadXML( xml ).documentElement; - - if(packetNode.getAttribute("type").toString() == "terminal") { + try { + // this will throw an exception if there is an error. + this.handleErrors( packetNode ); + + this.fireEvent( "recv", packetNode ); + } catch(e) { 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. |
From: <h-i...@us...> - 2008-07-26 20:38:54
|
Revision: 752 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=752&view=rev Author: h-iverson Date: 2008-07-26 20:39:04 +0000 (Sat, 26 Jul 2008) Log Message: ----------- added terminal error event when scripts don't load. behavior around pausing is still buggy Modified Paths: -------------- trunk/src/main/javascript/transport/Script.js Modified: trunk/src/main/javascript/transport/Script.js =================================================================== --- trunk/src/main/javascript/transport/Script.js 2008-07-26 20:35:54 UTC (rev 751) +++ trunk/src/main/javascript/transport/Script.js 2008-07-26 20:39:04 UTC (rev 752) @@ -62,7 +62,24 @@ } Xmpp4Js.Transport.Script.prototype = { + isPausing: false, + + pause: function() { + this.isPausing = true; + return Xmpp4Js.Transport.Script.superclass.pause.apply( this, arguments ); + }, + resume: function() { + this.isPausing = false; + return Xmpp4Js.Transport.Script.superclass.resume.apply( this, arguments ) + }, + + connect: function() { + this.isPausing = false; + return Xmpp4Js.Transport.Script.superclass.connect.apply( this, arguments ) + }, + + /** * Immediately write a raw packet node to the wire. Adds frame data including * RID, SID and Key if they are present. @@ -92,20 +109,42 @@ // remove the script element when it's been loaded. if(scriptElem.addEventListener) { - scriptElem.addEventListener("load", function() { - document.body.removeChild( scriptElem ); - }, false ); + scriptElem.addEventListener("load", this.onScriptLoad.bind(this, scriptElem), false ); + scriptElem.addEventListener("error", this.onScriptError.bind(this, scriptElem), false ); } else { - scriptElem.onreadystatechange = function() { - if(scriptElem.readyState == 4 || scriptElem.readyState == "loaded") { - document.body.removeChild( scriptElem ); - } - } + scriptElem.onreadystatechange = function() { + if(scriptElem.readyState == 4 || scriptElem.readyState == "loaded") { + this.onScriptLoad( scriptElem ); + } + // TODO add error... + } } document.body.appendChild( scriptElem ); }, + onScriptLoad: function(scriptElem) { + document.body.removeChild( scriptElem ); + }, + + onScriptError: function(scriptElem) { + if( this.isPausing ) { return; } + + document.body.removeChild( scriptElem ); + + // we can't find out anything about what the error is. + var condition = "undefined-condition"; + + var title = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].title; + var message = Xmpp4Js.PacketFilter.TerminalErrorPacketFilter.conditions[ condition ].message; + + var packetNode = this.createPacketNode(); + packetNode.setAttribute( "type", "terminate" ); + packetNode.setAttribute( "condition", condition ); + + this.fireEvent( "termerror", title, message, packetNode ); + }, + /** * Handles the response to a write call. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-26 20:35:46
|
Revision: 751 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=751&view=rev Author: h-iverson Date: 2008-07-26 20:35:54 +0000 (Sat, 26 Jul 2008) Log Message: ----------- changed onTerminalError to shutdown the connection before firing the error event to give the listener an opportunity to reconnect Modified Paths: -------------- trunk/src/main/javascript/XmppConnection.js Modified: trunk/src/main/javascript/XmppConnection.js =================================================================== --- trunk/src/main/javascript/XmppConnection.js 2008-07-25 21:01:04 UTC (rev 750) +++ trunk/src/main/javascript/XmppConnection.js 2008-07-26 20:35:54 UTC (rev 751) @@ -56,6 +56,8 @@ */ error: true, + beforepause: true, + pause: true, resume: true @@ -239,12 +241,13 @@ this.packetListenerManager.run( packetNode ); }, /** - * Sets connected to false and removes the onRecv listener. + * Shutdown before firing error event to give the listener an opportunity + * to reconnect. * @private */ onTerminalError: function(title, message, packetNode) { + this.shutdown(); this.fireEvent( "error", true, packetNode, title, message ); - this.shutdown(); }, /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-25 21:00:55
|
Revision: 750 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=750&view=rev Author: h-iverson Date: 2008-07-25 21:01:04 +0000 (Fri, 25 Jul 2008) Log Message: ----------- send any packets that are left before pause Modified Paths: -------------- trunk/src/main/javascript/transport/Base.js Modified: trunk/src/main/javascript/transport/Base.js =================================================================== --- trunk/src/main/javascript/transport/Base.js 2008-07-25 16:36:16 UTC (rev 749) +++ trunk/src/main/javascript/transport/Base.js 2008-07-25 21:01:04 UTC (rev 750) @@ -496,7 +496,8 @@ this.fireEvent( "pause", pauseStruct ); }, this, {single:true}); */ - + this.sendQueue(); + this.write( pauseNode ); this.shutdown(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-25 16:36:10
|
Revision: 749 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=749&view=rev Author: h-iverson Date: 2008-07-25 16:36:16 +0000 (Fri, 25 Jul 2008) Log Message: ----------- removed dependency on prototype Modified Paths: -------------- trunk/pom.xml trunk/src/main/javascript/Events.js trunk/src/main/javascript/adapter/Default.js trunk/src/main/javascript/roster/PresenceManager.js trunk/src/main/javascript/roster/RosterEntry.js trunk/src/main/javascript/roster/RosterGroup.js trunk/src/main/javascript/roster/RosterItemManager.js trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js trunk/src/test/javascript/EventListenerManagerTest.html trunk/src/test/javascript/RosterItemManagerTest.html trunk/src/test/javascript/broken/RosterTest.html trunk/src/test/javascript/common-test-library.js Added Paths: ----------- trunk/src/test/javascript/LangTest.html Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/pom.xml 2008-07-25 16:36:16 UTC (rev 749) @@ -16,12 +16,6 @@ <url>http://xmpp4js.sourceforge.net</url> <dependencies> <dependency> - <groupId>com.prototype</groupId> - <artifactId>prototype</artifactId> - <type>javascript</type> - <version>1.5.1-SNAPSHOT</version> - </dependency> - <dependency> <groupId>uk.org.pajhome</groupId> <artifactId>crypto</artifactId> <type>javascript</type> @@ -51,7 +45,7 @@ <configuration> <descriptor>${basedir}/src/assembler/xmpp4js.xml</descriptor> <includes> - <include>*Test.html</include> + <include>LangTest.html</include> </includes> <excludes> <!-- hasn't been ported to new connection stuff yet --> Modified: trunk/src/main/javascript/Events.js =================================================================== --- trunk/src/main/javascript/Events.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/Events.js 2008-07-25 16:36:16 UTC (rev 749) @@ -42,15 +42,15 @@ * Fire each delegate method with arguments that were passed to fire */ fire: function() { - var fireArgs = arguments; - $H(this.map).each(function(pair) { + var fireArgs = Array.prototype.slice.call(arguments); + for( var k in this.map) { try { // scope doesn't matter, should have been set with bind() - pair.value.apply(null,fireArgs); + this.map[k].apply(null,fireArgs); } catch(e) { // TODO do something } - }); + } }, // TODO test... even though it hardly needs it. getMap: function() { @@ -102,7 +102,7 @@ } EventListenerManager.prototype.fireArgs = function( event, args ) { - var callArgs = $A(args); + var callArgs = args.slice(0); // put event onto the beginning of the arg stack callArgs.unshift( event ); @@ -115,7 +115,7 @@ // get passed arguments and shift the first (event) off the front - var args = $A(arguments); + var args = Array.prototype.slice.call(arguments); args.shift(); dm.fire.apply( dm, args ); @@ -196,7 +196,7 @@ }, fireEvent: function(event, args) { - var callArgs = $A(arguments); + var callArgs = Array.prototype.slice.call(arguments); callArgs.shift(); // pull off the event this.eventListenerManager.fireArgs( event, callArgs ); Modified: trunk/src/main/javascript/adapter/Default.js =================================================================== --- trunk/src/main/javascript/adapter/Default.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/adapter/Default.js 2008-07-25 16:36:16 UTC (rev 749) @@ -395,12 +395,27 @@ return output; }, - noOp: function(){} + noOp: function(){}, - + bind: function( fn, scope ) { + var args = Array.prototype.slice.call(arguments); + args.shift(); args.shift(); // remove fn and scope + + return function() { + var fnArgs = Array.prototype.slice.call(arguments) + return fn.apply(scope, args.concat(fnArgs)); + } + } } +Function.prototype.bind = function(scope) { +;;; console.warn( "Using Function.prototype.bind" ); + var args = Array.prototype.slice.call(arguments); + args.unshift( this ); // add fn argument to the beginning + return Xmpp4Js.Lang.bind.apply( this, args ); +} + Xmpp4Js.Lang.TaskRunner = function(interval) { this.interval = interval; this.tasks = []; Modified: trunk/src/main/javascript/roster/PresenceManager.js =================================================================== --- trunk/src/main/javascript/roster/PresenceManager.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/roster/PresenceManager.js 2008-07-25 16:36:16 UTC (rev 749) @@ -87,11 +87,12 @@ remove: function(jid, resource) { if( this.map[jid] == undefined ) { return; } + // remove all resources if none is specified if( !resource ) { - $H(this.map[jid]).each(function(pair) { - var resource = pair.value; - this.remove( jid, resource); - }.bind(this)); + for( var k in this.map[jid]) { + var mapResource = this.map[jid][k]; + this.remove( jid, mapResource); + } delete this.map[jid]; } else { if( this.map[jid][resource] == undefined ) { return; } @@ -152,8 +153,8 @@ var bestPresence = undefined; var bestWeight = 0; - $H(presenceList).each(function(pair) { - var presence = pair.value; + for(var k in presenceList) { + var presence = presenceList[k]; // these return default values if empty. var show = presence.getShow(); @@ -171,7 +172,7 @@ bestPresence = presence; bestWeight = weight; } - }.bind(this)); + }; return bestPresence; } Modified: trunk/src/main/javascript/roster/RosterEntry.js =================================================================== --- trunk/src/main/javascript/roster/RosterEntry.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/roster/RosterEntry.js 2008-07-25 16:36:16 UTC (rev 749) @@ -25,24 +25,25 @@ }, /** references to all groups this entry belongs to. 0 or more. */ getGroups: function() { - var retGroups = []; - // TODO possibly refactor this to roster.getGroups and make use of that... for each group, if contains this jid, add to list - // gets groups off of con.roster - if( this.groups.length == 0 ) { - retGroups.push( this.roster.getUnfiledContacts() ); - } else { - $A(this.groups).each(function(groupName) { - var group = this.roster.getGroup(groupName); - // if group is undefined, that means that this entry is not associated with - // an existing group--perhaps it was just removed. - // TODO make a test for this case. - if( group == undefined ) { - group = new Xmpp4Js.Roster.VirtualRosterGroup( groupName, [this], this.roster ); - } - retGroups.push( group ); - }.bind(this)); - } + var retGroups = []; + // TODO possibly refactor this to roster.getGroups and make use of that... for each group, if contains this jid, add to list + // gets groups off of con.roster + if( this.groups.length == 0 ) { + retGroups.push( this.roster.getUnfiledContacts() ); + } else { + for(var i = 0; i < this.groups.length; i++) { + var groupName = this.groups[i]; + var group = this.roster.getGroup(groupName); + // if group is undefined, that means that this entry is not associated with + // an existing group--perhaps it was just removed. + // TODO make a test for this case. + if( group == undefined ) { + group = new Xmpp4Js.Roster.VirtualRosterGroup( groupName, [this], this.roster ); + } + retGroups.push( group ); + }; + } return retGroups; - } + } } Modified: trunk/src/main/javascript/roster/RosterGroup.js =================================================================== --- trunk/src/main/javascript/roster/RosterGroup.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/roster/RosterGroup.js 2008-07-25 16:36:16 UTC (rev 749) @@ -13,8 +13,8 @@ getEntries: function() { var retEntries = []; - $H(this.roster.map).each(function(pair) { - var entry = pair.value; + for(var k in this.roster.map) { + var entry = this.roster.map[k]; var groups = entry.groups; for( var j = 0; j < groups.length; j++ ) { @@ -23,20 +23,21 @@ retEntries.push( entry ); } } - }.bind(this)); + }; return retEntries; }, - getEntry: function(jid) { - var entries = this.getEntries(); - var retEntry = undefined; - $A(entries).each(function(entry) { - if( entry.jid == jid ) { - retEntry = entry; - } - }.bind(this)); - - return retEntry; + getEntry: function(jid) { + var entries = this.getEntries(); + var retEntry = undefined; + for(var i = 0; i < entries.length; i++) { + var entry = entries[i]; + if( entry.jid == jid ) { + retEntry = entry; + } + }; - } + return retEntry; + + } } Modified: trunk/src/main/javascript/roster/RosterItemManager.js =================================================================== --- trunk/src/main/javascript/roster/RosterItemManager.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/roster/RosterItemManager.js 2008-07-25 16:36:16 UTC (rev 749) @@ -71,16 +71,17 @@ retGroups.push( this.getUnfiledContacts() ); - $H(this.map).each(function(pair) { - var entry = pair.value; - $A(entry.groups).each(function(groupName) { + for( var k in this.map) { + var entry = this.map[k]; + for(var i = 0; i < entry.groups.length; i++) { + var groupName = entry.groups[i]; if( groupNames[groupName] == undefined ) { groupNames[ groupName ] = 1; retGroups.push( new Xmpp4Js.Roster.RosterGroup( groupName, this ) ); } - }.bind(this)); + }; - }.bind(this)); + }; return retGroups; }, Modified: trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js =================================================================== --- trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/main/javascript/roster/UnfiledEntriesRosterGroup.js 2008-07-25 16:36:16 UTC (rev 749) @@ -12,14 +12,14 @@ getEntries: function() { var retEntries = []; - $H(this.roster.map).each(function(pair) { - var entry = pair.value; + for(var k in this.roster.map) { + var entry = this.roster.map[k]; var groups = entry.groups; if( !groups || groups.length == 0 ) { retEntries.push( entry ); } - }.bind(this)); + } return retEntries; } Modified: trunk/src/test/javascript/EventListenerManagerTest.html =================================================================== --- trunk/src/test/javascript/EventListenerManagerTest.html 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/test/javascript/EventListenerManagerTest.html 2008-07-25 16:36:16 UTC (rev 749) @@ -35,7 +35,7 @@ var listeners = el.getMap( EVENT_NAME ); - assertEquals( 1, $H(listeners).keys().length ); + assertEquals( 1, mapLength(listeners) ); assertEquals( listener, listeners[id] ); } @@ -52,7 +52,7 @@ var listeners = el.getMap( EVENT_NAME ); - assertEquals( 2, $H(listeners).keys().length ); + assertEquals( 2, mapLength(listeners) ); assertEquals( listener1, listeners[ l1id ] ); assertEquals( listener2, listeners[ l2id ] ); @@ -67,7 +67,7 @@ var listeners = el.getMap( EVENT_NAME ); - assertEquals( 0, $H(listeners).keys().length ); + assertEquals( 0, mapLength(listeners) ); assertUndefined( listeners[id] ); } @@ -80,7 +80,7 @@ var listeners = el.getMap( EVENT_NAME ); - assertEquals( 0, $H(listeners).keys().length ); + assertEquals( 0, mapLength(listeners) ); assertUndefined( listeners[id] ); } Added: trunk/src/test/javascript/LangTest.html =================================================================== --- trunk/src/test/javascript/LangTest.html (rev 0) +++ trunk/src/test/javascript/LangTest.html 2008-07-25 16:36:16 UTC (rev 749) @@ -0,0 +1,91 @@ +<html> + <head> + <title>JSUnit - RosterWindowTest</title> + <script language="javascript" src="app/jsUnitCore.js"></script> + + <script type="text/javascript" src="includes.js"></script> + <script type="text/javascript" src="common-test-library.js"></script> + + </head> + <body> + <script type="text/javascript"> + + + + + +function setUp() { + +} +function tearDown() { + +} + +function testBind() { + var expectedThis = {testProperty: "abc123"}; + var actualThis = null; + var fn = function() { + actualThis = this; + } + + var boundFn = Xmpp4Js.Lang.bind( fn, expectedThis ); + boundFn(); + + assertEquals( "Scope was no correct.", expectedThis, actualThis ); + assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty ); +} + +function testBindArguments() { + var expectedThis = {testProperty: "abc123"}; + var actualThis = null; + var fn = function(arg1, arg2) { + actualThis = this; + assertEquals( "123", arg1 ); + assertEquals( "456", arg2 ); + } + + var boundFn = Xmpp4Js.Lang.bind( fn, expectedThis, "123" ); + boundFn("456"); + + assertEquals( "Scope was no correct.", expectedThis, actualThis ); + assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty ); +} + +// temporary, will go away when all instances of .bind() are removed +function testFunctionPrototypeBind() { + var expectedThis = {testProperty: "abc123"}; + var actualThis = null; + var fn = function() { + actualThis = this; + } + + var boundFn = fn.bind( expectedThis ); + boundFn(); + + assertEquals( "Scope was no correct.", expectedThis, actualThis ); + assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty ); +} + +// temporary, will go away when all instances of .bind() are removed +function FunctionPrototypeBindArguments() { + var expectedThis = {testProperty: "abc123"}; + var actualThis = null; + var fn = function(arg1, arg2) { + actualThis = this; + assertEquals( "123", arg1 ); + assertEquals( "456", arg2 ); + } + + var boundFn = fn.bind( expectedThis, "123" ); + boundFn("456"); + + assertEquals( "Scope was no correct.", expectedThis, actualThis ); + assertEquals( "Scope was no correct.", expectedThis.testProperty, actualThis.testProperty ); +} + + + </script> + </body> +</html> + + Modified: trunk/src/test/javascript/RosterItemManagerTest.html =================================================================== --- trunk/src/test/javascript/RosterItemManagerTest.html 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/test/javascript/RosterItemManagerTest.html 2008-07-25 16:36:16 UTC (rev 749) @@ -73,9 +73,10 @@ function testGetGroup() { rim.update( JID1, ALIAS1, null, null, GROUPS1 ); - $A(GROUPS1).each(function(groupName) { + for(var i = 0; i < GROUPS1.length; i++) { + var groupName = GROUPS1[i]; assertNotUndefined( rim.getGroup( groupName ) ); - }.bind(this)); + }; } function testGetGroupsFromEntry() { @@ -88,21 +89,20 @@ assertEquals( GROUPS1.length, groups.length ); /* TODO compare group names - $A(groups).each(function(group) { - - }.bind(this)); + */ } function testGetEntryFromGroup() { rim.update( JID1, ALIAS1, null, null, GROUPS1 ); - $A(GROUPS1).each(function(groupName) { + for(var i = 0; i < GROUPS1.length; i++) { + var groupName = GROUPS1[i]; var group = rim.getGroup( groupName ); var entry = group.getEntry( JID1 ); assertNotUndefined( entry ); assertEquals( JID1, entry.jid ); - }.bind(this)); + }; } function testAddEntryNoGroup() { @@ -165,9 +165,10 @@ var entry = rim.get( JID1 ); assertUndefined(entry); - $A(GROUPS1).each(function(groupName) { + for(var i = 0; i < GROUPS1.length; i++) { + var groupName = GROUPS1[i]; assertUndefined( rim.getGroup( groupName) ); - }.bind(this)); + }; } Modified: trunk/src/test/javascript/broken/RosterTest.html =================================================================== --- trunk/src/test/javascript/broken/RosterTest.html 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/test/javascript/broken/RosterTest.html 2008-07-25 16:36:16 UTC (rev 749) @@ -73,12 +73,13 @@ var entry = rim.update( JID1, ALIAS1, null, null, GROUPS1 ); - $A( GROUPS1 ).each( function(groupName ) { + for( var i = 0; i < GROUPS1.length; i++ ) { + var groupName = GROUPSi[i]; var group = rim.getGroup( groupName ); var entryNode = ri._getEntryNode( entry, group ); assertNotUndefined( entryNode ); - }); + }; } Modified: trunk/src/test/javascript/common-test-library.js =================================================================== --- trunk/src/test/javascript/common-test-library.js 2008-07-25 04:26:41 UTC (rev 748) +++ trunk/src/test/javascript/common-test-library.js 2008-07-25 16:36:16 UTC (rev 749) @@ -322,4 +322,12 @@ } } +function mapLength(map) { + var length = 0; + for(var k in map) { + length++; + } + return length; +} + Xmpp4Js.Lang.extend( MockConnection, Xmpp4Js.Event.EventProvider, MockConnection.prototype ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-25 04:26:34
|
Revision: 748 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=748&view=rev Author: h-iverson Date: 2008-07-25 04:26:41 +0000 (Fri, 25 Jul 2008) Log Message: ----------- removed json2 library because it didn't work with prototype, and just use prototype Modified Paths: -------------- xmpp4js-launcher/src/main/webapp/simpleclient.html Removed Paths: ------------- xmpp4js-launcher/src/main/javascript/json2.js Deleted: xmpp4js-launcher/src/main/javascript/json2.js =================================================================== --- xmpp4js-launcher/src/main/javascript/json2.js 2008-07-25 04:04:22 UTC (rev 747) +++ xmpp4js-launcher/src/main/javascript/json2.js 2008-07-25 04:26:41 UTC (rev 748) @@ -1,475 +0,0 @@ -/* - http://www.JSON.org/json2.js - 2008-07-15 - - Public Domain. - - NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. - - See http://www.JSON.org/js.html - - This file creates a global JSON object containing two methods: stringify - and parse. - - JSON.stringify(value, replacer, space) - value any JavaScript value, usually an object or array. - - replacer an optional parameter that determines how object - values are stringified for objects. It can be a - function or an array. - - space an optional parameter that specifies the indentation - of nested structures. If it is omitted, the text will - be packed without extra whitespace. If it is a number, - it will specify the number of spaces to indent at each - level. If it is a string (such as '\t' or ' '), - it contains the characters used to indent at each level. - - This method produces a JSON text from a JavaScript value. - - When an object value is found, if the object contains a toJSON - method, its toJSON method will be called and the result will be - stringified. A toJSON method does not serialize: it returns the - value represented by the name/value pair that should be serialized, - or undefined if nothing should be serialized. The toJSON method - will be passed the key associated with the value, and this will be - bound to the object holding the key. - - For example, this would serialize Dates as ISO strings. - - Date.prototype.toJSON = function (key) { - function f(n) { - // Format integers to have at least two digits. - return n < 10 ? '0' + n : n; - } - - return this.getUTCFullYear() + '-' + - f(this.getUTCMonth() + 1) + '-' + - f(this.getUTCDate()) + 'T' + - f(this.getUTCHours()) + ':' + - f(this.getUTCMinutes()) + ':' + - f(this.getUTCSeconds()) + 'Z'; - }; - - You can provide an optional replacer method. It will be passed the - key and value of each member, with this bound to the containing - object. The value that is returned from your method will be - serialized. If your method returns undefined, then the member will - be excluded from the serialization. - - If the replacer parameter is an array, then it will be used to - select the members to be serialized. It filters the results such - that only members with keys listed in the replacer array are - stringified. - - Values that do not have JSON representations, such as undefined or - functions, will not be serialized. Such values in objects will be - dropped; in arrays they will be replaced with null. You can use - a replacer function to replace those with JSON values. - JSON.stringify(undefined) returns undefined. - - The optional space parameter produces a stringification of the - value that is filled with line breaks and indentation to make it - easier to read. - - If the space parameter is a non-empty string, then that string will - be used for indentation. If the space parameter is a number, then - the indentation will be that many spaces. - - Example: - - text = JSON.stringify(['e', {pluribus: 'unum'}]); - // text is '["e",{"pluribus":"unum"}]' - - - text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); - // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' - - text = JSON.stringify([new Date()], function (key, value) { - return this[key] instanceof Date ? - 'Date(' + this[key] + ')' : value; - }); - // text is '["Date(---current time---)"]' - - - JSON.parse(text, reviver) - This method parses a JSON text to produce an object or array. - It can throw a SyntaxError exception. - - The optional reviver parameter is a function that can filter and - transform the results. It receives each of the keys and values, - and its return value is used instead of the original value. - If it returns what it received, then the structure is not modified. - If it returns undefined then the member is deleted. - - Example: - - // Parse the text. Values that look like ISO date strings will - // be converted to Date objects. - - myData = JSON.parse(text, function (key, value) { - var a; - if (typeof value === 'string') { - a = -/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); - if (a) { - return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], - +a[5], +a[6])); - } - } - return value; - }); - - myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { - var d; - if (typeof value === 'string' && - value.slice(0, 5) === 'Date(' && - value.slice(-1) === ')') { - d = new Date(value.slice(5, -1)); - if (d) { - return d; - } - } - return value; - }); - - - This is a reference implementation. You are free to copy, modify, or - redistribute. - - This code should be minified before deployment. - See http://javascript.crockford.com/jsmin.html - - USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO - NOT CONTROL. -*/ - -/*jslint evil: true */ - -/*global JSON */ - -/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", call, - charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes, - getUTCMonth, getUTCSeconds, hasOwnProperty, join, lastIndex, length, - parse, propertyIsEnumerable, prototype, push, replace, slice, stringify, - test, toJSON, toString -*/ - -if (!this.JSON) { - -// Create a JSON object only if one does not already exist. We create the -// object in a closure to avoid creating global variables. - - JSON = function () { - - function f(n) { - // Format integers to have at least two digits. - return n < 10 ? '0' + n : n; - } - - Date.prototype.toJSON = function (key) { - - return this.getUTCFullYear() + '-' + - f(this.getUTCMonth() + 1) + '-' + - f(this.getUTCDate()) + 'T' + - f(this.getUTCHours()) + ':' + - f(this.getUTCMinutes()) + ':' + - f(this.getUTCSeconds()) + 'Z'; - }; - - String.prototype.toJSON = - Number.prototype.toJSON = - Boolean.prototype.toJSON = function (key) { - return this.valueOf(); - }; - - var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, - gap, - indent, - meta = { // table of character substitutions - '\b': '\\b', - '\t': '\\t', - '\n': '\\n', - '\f': '\\f', - '\r': '\\r', - '"' : '\\"', - '\\': '\\\\' - }, - rep; - - - function quote(string) { - -// If the string contains no control characters, no quote characters, and no -// backslash characters, then we can safely slap some quotes around it. -// Otherwise we must also replace the offending characters with safe escape -// sequences. - - escapeable.lastIndex = 0; - return escapeable.test(string) ? - '"' + string.replace(escapeable, function (a) { - var c = meta[a]; - if (typeof c === 'string') { - return c; - } - return '\\u' + ('0000' + - (+(a.charCodeAt(0))).toString(16)).slice(-4); - }) + '"' : - '"' + string + '"'; - } - - - function str(key, holder) { - -// Produce a string from holder[key]. - - var i, // The loop counter. - k, // The member key. - v, // The member value. - length, - mind = gap, - partial, - value = holder[key]; - -// If the value has a toJSON method, call it to obtain a replacement value. - - if (value && typeof value === 'object' && - typeof value.toJSON === 'function') { - value = value.toJSON(key); - } - -// If we were called with a replacer function, then call the replacer to -// obtain a replacement value. - - if (typeof rep === 'function') { - value = rep.call(holder, key, value); - } - -// What happens next depends on the value's type. - - switch (typeof value) { - case 'string': - return quote(value); - - case 'number': - -// JSON numbers must be finite. Encode non-finite numbers as null. - - return isFinite(value) ? String(value) : 'null'; - - case 'boolean': - case 'null': - -// If the value is a boolean or null, convert it to a string. Note: -// typeof null does not produce 'null'. The case is included here in -// the remote chance that this gets fixed someday. - - return String(value); - -// If the type is 'object', we might be dealing with an object or an array or -// null. - - case 'object': - -// Due to a specification blunder in ECMAScript, typeof null is 'object', -// so watch out for that case. - - if (!value) { - return 'null'; - } - -// Make an array to hold the partial results of stringifying this object value. - - gap += indent; - partial = []; - -// If the object has a dontEnum length property, we'll treat it as an array. - - if (typeof value.length === 'number' && - !(value.propertyIsEnumerable('length'))) { - -// The object is an array. Stringify every element. Use null as a placeholder -// for non-JSON values. - - length = value.length; - for (i = 0; i < length; i += 1) { - partial[i] = str(i, value) || 'null'; - } - -// Join all of the elements together, separated with commas, and wrap them in -// brackets. - - v = partial.length === 0 ? '[]' : - gap ? '[\n' + gap + - partial.join(',\n' + gap) + '\n' + - mind + ']' : - '[' + partial.join(',') + ']'; - gap = mind; - return v; - } - -// If the replacer is an array, use it to select the members to be stringified. - - if (rep && typeof rep === 'object') { - length = rep.length; - for (i = 0; i < length; i += 1) { - k = rep[i]; - if (typeof k === 'string') { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } else { - -// Otherwise, iterate through all of the keys in the object. - - for (k in value) { - if (Object.hasOwnProperty.call(value, k)) { - v = str(k, value); - if (v) { - partial.push(quote(k) + (gap ? ': ' : ':') + v); - } - } - } - } - -// Join all of the member texts together, separated with commas, -// and wrap them in braces. - - v = partial.length === 0 ? '{}' : - gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + - mind + '}' : '{' + partial.join(',') + '}'; - gap = mind; - return v; - } - } - -// Return the JSON object containing the stringify and parse methods. - - return { - stringify: function (value, replacer, space) { - -// The stringify method takes a value and an optional replacer, and an optional -// space parameter, and returns a JSON text. The replacer can be a function -// that can replace values, or an array of strings that will select the keys. -// A default replacer method can be provided. Use of the space parameter can -// produce text that is more easily readable. - - var i; - gap = ''; - indent = ''; - -// If the space parameter is a number, make an indent string containing that -// many spaces. - - if (typeof space === 'number') { - for (i = 0; i < space; i += 1) { - indent += ' '; - } - -// If the space parameter is a string, it will be used as the indent string. - - } else if (typeof space === 'string') { - indent = space; - } - -// If there is a replacer, it must be a function or an array. -// Otherwise, throw an error. - - rep = replacer; - if (replacer && typeof replacer !== 'function' && - (typeof replacer !== 'object' || - typeof replacer.length !== 'number')) { - throw new Error('JSON.stringify'); - } - -// Make a fake root object containing our value under the key of ''. -// Return the result of stringifying the value. - - return str('', {'': value}); - }, - - - parse: function (text, reviver) { - -// The parse method takes a text and an optional reviver function, and returns -// a JavaScript value if the text is a valid JSON text. - - var j; - - function walk(holder, key) { - -// The walk method is used to recursively walk the resulting structure so -// that modifications can be made. - - var k, v, value = holder[key]; - if (value && typeof value === 'object') { - for (k in value) { - if (Object.hasOwnProperty.call(value, k)) { - v = walk(value, k); - if (v !== undefined) { - value[k] = v; - } else { - delete value[k]; - } - } - } - } - return reviver.call(holder, key, value); - } - - -// Parsing happens in four stages. In the first stage, we replace certain -// Unicode characters with escape sequences. JavaScript handles many characters -// incorrectly, either silently deleting them, or treating them as line endings. - - cx.lastIndex = 0; - if (cx.test(text)) { - text = text.replace(cx, function (a) { - return '\\u' + ('0000' + - (+(a.charCodeAt(0))).toString(16)).slice(-4); - }); - } - -// In the second stage, we run the text against regular expressions that look -// for non-JSON patterns. We are especially concerned with '()' and 'new' -// because they can cause invocation, and '=' because it can cause mutation. -// But just to be safe, we want to reject all unexpected forms. - -// We split the second stage into 4 regexp operations in order to work around -// crippling inefficiencies in IE's and Safari's regexp engines. First we -// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we -// replace all simple value tokens with ']' characters. Third, we delete all -// open brackets that follow a colon or comma or that begin the text. Finally, -// we look to see that the remaining characters are only whitespace or ']' or -// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. - - if (/^[\],:{}\s]*$/. -test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). -replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). -replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { - -// In the third stage we use the eval function to compile the text into a -// JavaScript structure. The '{' operator is subject to a syntactic ambiguity -// in JavaScript: it can begin a block or an object literal. We wrap the text -// in parens to eliminate the ambiguity. - - j = eval('(' + text + ')'); - -// In the optional fourth stage, we recursively walk the new structure, passing -// each name/value pair to a reviver function for possible transformation. - - return typeof reviver === 'function' ? - walk({'': j}, '') : j; - } - -// If the text is not JSON parseable, then a SyntaxError is thrown. - - throw new SyntaxError('JSON.parse'); - } - }; - }(); -} Modified: xmpp4js-launcher/src/main/webapp/simpleclient.html =================================================================== --- xmpp4js-launcher/src/main/webapp/simpleclient.html 2008-07-25 04:04:22 UTC (rev 747) +++ xmpp4js-launcher/src/main/webapp/simpleclient.html 2008-07-25 04:26:41 UTC (rev 748) @@ -5,7 +5,6 @@ <script type="text/javascript" src="scripts/lib/dom-all.js"></script> <script type="text/javascript" src="scripts/lib/crypto.js"></script> <script type="text/javascript" src="scripts/lib/xmpp4js.js"></script> - <script type="text/javascript" src="scripts/json2.js"></script> <script type="text/javascript" src="scripts/cookies.js"></script> </head> @@ -185,7 +184,7 @@ if( this.con != null && this.con.isConnected() ) { // pause for up to 120 seconds var pauseStruct = this.con.pause( 120 ); - setCookie( "pauseStruct", JSON.stringify(pauseStruct) ); + setCookie( "pauseStruct", Object.toJSON(pauseStruct) ); } }, @@ -196,7 +195,7 @@ onPageLoad: function() { var pauseStruct = getCookie( "pauseStruct" ); if( pauseStruct ) { - pauseStruct = JSON.parse(pauseStruct); + pauseStruct = pauseStruct.evalJSON(); this.init( true ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-25 04:04:15
|
Revision: 747 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=747&view=rev Author: h-iverson Date: 2008-07-25 04:04:22 +0000 (Fri, 25 Jul 2008) Log Message: ----------- added pause/resume functionality Modified Paths: -------------- xmpp4js-launcher/pom.xml xmpp4js-launcher/src/assembler/src.xml xmpp4js-launcher/src/main/webapp/simpleclient.html Added Paths: ----------- xmpp4js-launcher/src/main/javascript/cookies.js xmpp4js-launcher/src/main/javascript/json2.js Modified: xmpp4js-launcher/pom.xml =================================================================== --- xmpp4js-launcher/pom.xml 2008-07-25 03:18:15 UTC (rev 746) +++ xmpp4js-launcher/pom.xml 2008-07-25 04:04:22 UTC (rev 747) @@ -50,10 +50,15 @@ <executions> <execution> <goals> + <goal>compress</goal> <goal>war-package</goal> </goals> </execution> </executions> + <configuration> + <compressor>YahooUI</compressor> + <strip>;;;</strip> + </configuration> </plugin> </plugins> </build> Modified: xmpp4js-launcher/src/assembler/src.xml =================================================================== --- xmpp4js-launcher/src/assembler/src.xml 2008-07-25 03:18:15 UTC (rev 746) +++ xmpp4js-launcher/src/assembler/src.xml 2008-07-25 04:04:22 UTC (rev 747) @@ -3,6 +3,7 @@ <baseDirectory>xmpp4js-launcher</baseDirectory> <formats> <format>zip</format> + <format>dir</format> </formats> <dependencySets> Added: xmpp4js-launcher/src/main/javascript/cookies.js =================================================================== --- xmpp4js-launcher/src/main/javascript/cookies.js (rev 0) +++ xmpp4js-launcher/src/main/javascript/cookies.js 2008-07-25 04:04:22 UTC (rev 747) @@ -0,0 +1,83 @@ +//******************************************************************************************// +// File for cookie related fnctions in JavaScript // +// Author : Manish Hatwalne (http://www.technofundo.com/) // +// Feedback : fee...@te... (for feedback/bugs) // +// Created : 19 August 2001 // +// Functions : // +// (1) setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,szSecure]) // +// (2) getCookie(szName) // +// (3) deleteCookie(szName) // +// // +// Feel free to use/modify the code in this file, but always keep the header intact. // +// And DO NOT re-distribute this file, instead provide a link to the site // +// http://www.technofundo.com/. Thank You. // +// // +//******************************************************************************************// + + + +//****************************************************************************************** +// +// A CGI program uses the following syntax to add cookie information to the HTTP header: +// +// Set-Cookie: name=value +// [;EXPIRES=dateValue] +// [;DOMAIN=domainName] +// [;PATH=pathName] +// [;SECURE] +// +// This function sets a client-side cookie as above. Only first 2 parameters are required +// Rest of the parameters are optional. If no szExpires value is set, cookie is a session cookie. +// +// Prototype : setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,bSecure]) +//****************************************************************************************** + + +function setCookie(szName, szValue, szExpires, szPath, szDomain, bSecure) +{ + var szCookieText = escape(szName) + '=' + escape(szValue); + szCookieText += (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : ''); + szCookieText += (szPath ? '; PATH=' + szPath : ''); + szCookieText += (szDomain ? '; DOMAIN=' + szDomain : ''); + szCookieText += (bSecure ? '; SECURE' : ''); + + document.cookie = szCookieText; +} + +//****************************************************************************************** +// This functions reads & returns the cookie value of the specified cookie (by cookie name) +// +// Prototype : getCookie(szName) +//****************************************************************************************** + +function getCookie(szName) +{ + var szValue = null; + if(document.cookie) //only if exists + { + var arr = document.cookie.split((escape(szName) + '=')); + if(2 <= arr.length) + { + var arr2 = arr[1].split(';'); + szValue = unescape(arr2[0]); + } + } + return szValue; +} + +//****************************************************************************************** +// To delete a cookie, pass name of the cookie to be deleted +// +// Prototype : deleteCookie(szName) +//****************************************************************************************** + +function deleteCookie(szName) +{ + var tmp = getCookie(szName); + if(tmp) + { setCookie(szName,tmp,(new Date(1))); } +} + +//==========================================^-^==============================================// +// This and many more interesting and usefull scripts at http://www.technofundo.com/ // +//==========================================^-^==============================================// \ No newline at end of file Added: xmpp4js-launcher/src/main/javascript/json2.js =================================================================== --- xmpp4js-launcher/src/main/javascript/json2.js (rev 0) +++ xmpp4js-launcher/src/main/javascript/json2.js 2008-07-25 04:04:22 UTC (rev 747) @@ -0,0 +1,475 @@ +/* + http://www.JSON.org/json2.js + 2008-07-15 + + Public Domain. + + NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + + See http://www.JSON.org/js.html + + This file creates a global JSON object containing two methods: stringify + and parse. + + JSON.stringify(value, replacer, space) + value any JavaScript value, usually an object or array. + + replacer an optional parameter that determines how object + values are stringified for objects. It can be a + function or an array. + + space an optional parameter that specifies the indentation + of nested structures. If it is omitted, the text will + be packed without extra whitespace. If it is a number, + it will specify the number of spaces to indent at each + level. If it is a string (such as '\t' or ' '), + it contains the characters used to indent at each level. + + This method produces a JSON text from a JavaScript value. + + When an object value is found, if the object contains a toJSON + method, its toJSON method will be called and the result will be + stringified. A toJSON method does not serialize: it returns the + value represented by the name/value pair that should be serialized, + or undefined if nothing should be serialized. The toJSON method + will be passed the key associated with the value, and this will be + bound to the object holding the key. + + For example, this would serialize Dates as ISO strings. + + Date.prototype.toJSON = function (key) { + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + You can provide an optional replacer method. It will be passed the + key and value of each member, with this bound to the containing + object. The value that is returned from your method will be + serialized. If your method returns undefined, then the member will + be excluded from the serialization. + + If the replacer parameter is an array, then it will be used to + select the members to be serialized. It filters the results such + that only members with keys listed in the replacer array are + stringified. + + Values that do not have JSON representations, such as undefined or + functions, will not be serialized. Such values in objects will be + dropped; in arrays they will be replaced with null. You can use + a replacer function to replace those with JSON values. + JSON.stringify(undefined) returns undefined. + + The optional space parameter produces a stringification of the + value that is filled with line breaks and indentation to make it + easier to read. + + If the space parameter is a non-empty string, then that string will + be used for indentation. If the space parameter is a number, then + the indentation will be that many spaces. + + Example: + + text = JSON.stringify(['e', {pluribus: 'unum'}]); + // text is '["e",{"pluribus":"unum"}]' + + + text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t'); + // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]' + + text = JSON.stringify([new Date()], function (key, value) { + return this[key] instanceof Date ? + 'Date(' + this[key] + ')' : value; + }); + // text is '["Date(---current time---)"]' + + + JSON.parse(text, reviver) + This method parses a JSON text to produce an object or array. + It can throw a SyntaxError exception. + + The optional reviver parameter is a function that can filter and + transform the results. It receives each of the keys and values, + and its return value is used instead of the original value. + If it returns what it received, then the structure is not modified. + If it returns undefined then the member is deleted. + + Example: + + // Parse the text. Values that look like ISO date strings will + // be converted to Date objects. + + myData = JSON.parse(text, function (key, value) { + var a; + if (typeof value === 'string') { + a = +/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value); + if (a) { + return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], + +a[5], +a[6])); + } + } + return value; + }); + + myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) { + var d; + if (typeof value === 'string' && + value.slice(0, 5) === 'Date(' && + value.slice(-1) === ')') { + d = new Date(value.slice(5, -1)); + if (d) { + return d; + } + } + return value; + }); + + + This is a reference implementation. You are free to copy, modify, or + redistribute. + + This code should be minified before deployment. + See http://javascript.crockford.com/jsmin.html + + USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO + NOT CONTROL. +*/ + +/*jslint evil: true */ + +/*global JSON */ + +/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", call, + charCodeAt, getUTCDate, getUTCFullYear, getUTCHours, getUTCMinutes, + getUTCMonth, getUTCSeconds, hasOwnProperty, join, lastIndex, length, + parse, propertyIsEnumerable, prototype, push, replace, slice, stringify, + test, toJSON, toString +*/ + +if (!this.JSON) { + +// Create a JSON object only if one does not already exist. We create the +// object in a closure to avoid creating global variables. + + JSON = function () { + + function f(n) { + // Format integers to have at least two digits. + return n < 10 ? '0' + n : n; + } + + Date.prototype.toJSON = function (key) { + + return this.getUTCFullYear() + '-' + + f(this.getUTCMonth() + 1) + '-' + + f(this.getUTCDate()) + 'T' + + f(this.getUTCHours()) + ':' + + f(this.getUTCMinutes()) + ':' + + f(this.getUTCSeconds()) + 'Z'; + }; + + String.prototype.toJSON = + Number.prototype.toJSON = + Boolean.prototype.toJSON = function (key) { + return this.valueOf(); + }; + + var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + escapeable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, + gap, + indent, + meta = { // table of character substitutions + '\b': '\\b', + '\t': '\\t', + '\n': '\\n', + '\f': '\\f', + '\r': '\\r', + '"' : '\\"', + '\\': '\\\\' + }, + rep; + + + function quote(string) { + +// If the string contains no control characters, no quote characters, and no +// backslash characters, then we can safely slap some quotes around it. +// Otherwise we must also replace the offending characters with safe escape +// sequences. + + escapeable.lastIndex = 0; + return escapeable.test(string) ? + '"' + string.replace(escapeable, function (a) { + var c = meta[a]; + if (typeof c === 'string') { + return c; + } + return '\\u' + ('0000' + + (+(a.charCodeAt(0))).toString(16)).slice(-4); + }) + '"' : + '"' + string + '"'; + } + + + function str(key, holder) { + +// Produce a string from holder[key]. + + var i, // The loop counter. + k, // The member key. + v, // The member value. + length, + mind = gap, + partial, + value = holder[key]; + +// If the value has a toJSON method, call it to obtain a replacement value. + + if (value && typeof value === 'object' && + typeof value.toJSON === 'function') { + value = value.toJSON(key); + } + +// If we were called with a replacer function, then call the replacer to +// obtain a replacement value. + + if (typeof rep === 'function') { + value = rep.call(holder, key, value); + } + +// What happens next depends on the value's type. + + switch (typeof value) { + case 'string': + return quote(value); + + case 'number': + +// JSON numbers must be finite. Encode non-finite numbers as null. + + return isFinite(value) ? String(value) : 'null'; + + case 'boolean': + case 'null': + +// If the value is a boolean or null, convert it to a string. Note: +// typeof null does not produce 'null'. The case is included here in +// the remote chance that this gets fixed someday. + + return String(value); + +// If the type is 'object', we might be dealing with an object or an array or +// null. + + case 'object': + +// Due to a specification blunder in ECMAScript, typeof null is 'object', +// so watch out for that case. + + if (!value) { + return 'null'; + } + +// Make an array to hold the partial results of stringifying this object value. + + gap += indent; + partial = []; + +// If the object has a dontEnum length property, we'll treat it as an array. + + if (typeof value.length === 'number' && + !(value.propertyIsEnumerable('length'))) { + +// The object is an array. Stringify every element. Use null as a placeholder +// for non-JSON values. + + length = value.length; + for (i = 0; i < length; i += 1) { + partial[i] = str(i, value) || 'null'; + } + +// Join all of the elements together, separated with commas, and wrap them in +// brackets. + + v = partial.length === 0 ? '[]' : + gap ? '[\n' + gap + + partial.join(',\n' + gap) + '\n' + + mind + ']' : + '[' + partial.join(',') + ']'; + gap = mind; + return v; + } + +// If the replacer is an array, use it to select the members to be stringified. + + if (rep && typeof rep === 'object') { + length = rep.length; + for (i = 0; i < length; i += 1) { + k = rep[i]; + if (typeof k === 'string') { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } else { + +// Otherwise, iterate through all of the keys in the object. + + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = str(k, value); + if (v) { + partial.push(quote(k) + (gap ? ': ' : ':') + v); + } + } + } + } + +// Join all of the member texts together, separated with commas, +// and wrap them in braces. + + v = partial.length === 0 ? '{}' : + gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + + mind + '}' : '{' + partial.join(',') + '}'; + gap = mind; + return v; + } + } + +// Return the JSON object containing the stringify and parse methods. + + return { + stringify: function (value, replacer, space) { + +// The stringify method takes a value and an optional replacer, and an optional +// space parameter, and returns a JSON text. The replacer can be a function +// that can replace values, or an array of strings that will select the keys. +// A default replacer method can be provided. Use of the space parameter can +// produce text that is more easily readable. + + var i; + gap = ''; + indent = ''; + +// If the space parameter is a number, make an indent string containing that +// many spaces. + + if (typeof space === 'number') { + for (i = 0; i < space; i += 1) { + indent += ' '; + } + +// If the space parameter is a string, it will be used as the indent string. + + } else if (typeof space === 'string') { + indent = space; + } + +// If there is a replacer, it must be a function or an array. +// Otherwise, throw an error. + + rep = replacer; + if (replacer && typeof replacer !== 'function' && + (typeof replacer !== 'object' || + typeof replacer.length !== 'number')) { + throw new Error('JSON.stringify'); + } + +// Make a fake root object containing our value under the key of ''. +// Return the result of stringifying the value. + + return str('', {'': value}); + }, + + + parse: function (text, reviver) { + +// The parse method takes a text and an optional reviver function, and returns +// a JavaScript value if the text is a valid JSON text. + + var j; + + function walk(holder, key) { + +// The walk method is used to recursively walk the resulting structure so +// that modifications can be made. + + var k, v, value = holder[key]; + if (value && typeof value === 'object') { + for (k in value) { + if (Object.hasOwnProperty.call(value, k)) { + v = walk(value, k); + if (v !== undefined) { + value[k] = v; + } else { + delete value[k]; + } + } + } + } + return reviver.call(holder, key, value); + } + + +// Parsing happens in four stages. In the first stage, we replace certain +// Unicode characters with escape sequences. JavaScript handles many characters +// incorrectly, either silently deleting them, or treating them as line endings. + + cx.lastIndex = 0; + if (cx.test(text)) { + text = text.replace(cx, function (a) { + return '\\u' + ('0000' + + (+(a.charCodeAt(0))).toString(16)).slice(-4); + }); + } + +// In the second stage, we run the text against regular expressions that look +// for non-JSON patterns. We are especially concerned with '()' and 'new' +// because they can cause invocation, and '=' because it can cause mutation. +// But just to be safe, we want to reject all unexpected forms. + +// We split the second stage into 4 regexp operations in order to work around +// crippling inefficiencies in IE's and Safari's regexp engines. First we +// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we +// replace all simple value tokens with ']' characters. Third, we delete all +// open brackets that follow a colon or comma or that begin the text. Finally, +// we look to see that the remaining characters are only whitespace or ']' or +// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval. + + if (/^[\],:{}\s]*$/. +test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@'). +replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']'). +replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { + +// In the third stage we use the eval function to compile the text into a +// JavaScript structure. The '{' operator is subject to a syntactic ambiguity +// in JavaScript: it can begin a block or an object literal. We wrap the text +// in parens to eliminate the ambiguity. + + j = eval('(' + text + ')'); + +// In the optional fourth stage, we recursively walk the new structure, passing +// each name/value pair to a reviver function for possible transformation. + + return typeof reviver === 'function' ? + walk({'': j}, '') : j; + } + +// If the text is not JSON parseable, then a SyntaxError is thrown. + + throw new SyntaxError('JSON.parse'); + } + }; + }(); +} Modified: xmpp4js-launcher/src/main/webapp/simpleclient.html =================================================================== --- xmpp4js-launcher/src/main/webapp/simpleclient.html 2008-07-25 03:18:15 UTC (rev 746) +++ xmpp4js-launcher/src/main/webapp/simpleclient.html 2008-07-25 04:04:22 UTC (rev 747) @@ -5,6 +5,8 @@ <script type="text/javascript" src="scripts/lib/dom-all.js"></script> <script type="text/javascript" src="scripts/lib/crypto.js"></script> <script type="text/javascript" src="scripts/lib/xmpp4js.js"></script> + <script type="text/javascript" src="scripts/json2.js"></script> + <script type="text/javascript" src="scripts/cookies.js"></script> </head> <body> @@ -140,20 +142,19 @@ * * @private */ - init: function() { + init: function(isResume) { var stanzaProvider = new Xmpp4Js.Packet.StanzaProvider(); stanzaProvider.registerDefaultProviders(); var transportClasses = {bosh: Xmpp4Js.Transport.BOSH, script: Xmpp4Js.Transport.Script}; - var endpoint = this.loginForm.endpoint.value; - - this.con = new Xmpp4Js.Connection({ + var connectionConfig = { + // FIXME none of this transport stuff should be needed if we plan to resume. transport: { useKeys: true, - clazz: transportClasses[ this.loginForm.transport.value ], - endpoint: endpoint // where your BOSH server is running. + clazz: !isResume ? transportClasses[ this.loginForm.transport.value ] : transportClasses.script , + endpoint: !isResume ? this.loginForm.endpoint.value : "" // where your BOSH server is running. // NOTE: same origin policy means you need some sort of proxt, or a servlet. }, stanzaProvider: stanzaProvider, @@ -162,7 +163,9 @@ error : this.onError, close : this.onClose } - }); + } + + this.con = new Xmpp4Js.Connection(connectionConfig); this.chatManager = Xmpp4Js.Chat.ChatManager.getInstanceFor( this.con ); this.chatManager.setOptions(this.CHAT_OPTIONS); @@ -175,6 +178,36 @@ }, /** + * Pause the session and save it to a cookie when the page is unloaded + * if we are connected. + */ + onPageUnload: function() { + if( this.con != null && this.con.isConnected() ) { + // pause for up to 120 seconds + var pauseStruct = this.con.pause( 120 ); + setCookie( "pauseStruct", JSON.stringify(pauseStruct) ); + } + }, + + /** + * Resume the sesion if there is one persisted. + * TODO error checking if more than 120 seconds have gone by + */ + onPageLoad: function() { + var pauseStruct = getCookie( "pauseStruct" ); + if( pauseStruct ) { + pauseStruct = JSON.parse(pauseStruct); + + this.init( true ); + + this.con.resume( pauseStruct ); + + this.logMessage("Resumed session."); + this.onLoginCompleted(); + } + }, + + /** * This is called when we connect. It performs a login. * @private */ @@ -269,10 +302,15 @@ var client = null; window.onload = function() { client = new SimpleClient(); + client.onPageLoad(); client.logMessage( "Client ready." ); }; +window.onunload = function() { + client.onPageUnload(); +} + --> </script> <style type="text/css"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <h-i...@us...> - 2008-07-25 03:18:06
|
Revision: 746 http://xmpp4js.svn.sourceforge.net/xmpp4js/?rev=746&view=rev Author: h-iverson Date: 2008-07-25 03:18:15 +0000 (Fri, 25 Jul 2008) Log Message: ----------- fixed typos and syntax errors Modified Paths: -------------- trunk/src/site/xdoc/code-samples.xml Modified: trunk/src/site/xdoc/code-samples.xml =================================================================== --- trunk/src/site/xdoc/code-samples.xml 2008-07-25 03:15:00 UTC (rev 745) +++ trunk/src/site/xdoc/code-samples.xml 2008-07-25 03:18:15 UTC (rev 746) @@ -59,23 +59,23 @@ <pre name="code" class="javascript"><![CDATA[ var cm = Xmpp4Js.Chat.ChatManager.getInstanceFor( con ); -cm.chatManager.setOptions({ +cm.setOptions({ ignoreThread: true, // useful for legacy networks (AIM) ignoreResource: true }); -cm.chatManager.on({ +cm.on({ scope : this, chatStarted : onChatStarted, messageReceived : onChatMessageReceived }); function onChatStarted(chat) { - alert( "Chat with "+chat.getParticipant()+" started." + alert( "Chat with "+chat.getParticipant()+" started." ); } function onChatMessageReceived(chat, messagePacket) { - alert( "New message from "+messagePacket.getFrom()+": "+messagePacket.getBody(); + alert( "New message from "+messagePacket.getFrom()+": "+messagePacket.getBody() ); } function sendMessage(to, message) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |