[Xmpp4js-commit] SF.net SVN: xmpp4js:[752] trunk/src/main/javascript/transport/Script.js
Status: Beta
Brought to you by:
h-iverson
|
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.
|