It would have been cool if I could have just attached the modified XMPPConnection class, but here’'s what I changed (new code is in blue):
line 493: protected function socketReceivedData( ev:DataEvent ):void
I commented out the Regular Expression search for the opening tag and added a straightforward search for opening/closing tags from the as3xmpp library:
// parseXML is more strict in AS3 so we must check for the presence of flash:stream
// the unterminated tag should be in the first string of xml data retured from the server
/*
if (!_expireTagSearch) {
var pattern:RegExp = new RegExp("<flash:stream");
var resultObj:Object = pattern.exec(ev.data);
if (resultObj != null) // stop searching for unterminated node
{
ev.data = ev.data.concat("</flash:stream>");
_expireTagSearch = true;
}
}
*/
if(ev.data.indexOf("<flash:stream") > -1)
{
ev.data += “</flash:stream>”;
}
else if(ev.data.indexOf("<stream:stream") > -1)
{
ev.data += “</stream:stream>”;
}
else if(ev.data.indexOf("</flash:stream>") > -1)
{
ev.data = “<flash:stream xmlns:flash=’‘http://www.jabber.com/streams/flash’’>” + ev.data;
}
else if(ev.data.indexOf("</stream:stream>") > -1)
{
ev.data = “<stream:stream xmlns:flash=’‘http://etherx.jabber.org/streams’’>” + ev.data;
}
This took care of handling closing the stream properly, but I also needed to re-connect to the server properly. I moved the socket initialization code in the constructor into it’'s own method:
private function initializeSocket():void
{
// Create the socket
socket = new XMLSocket();
socket.addEventListener(Event.CONNECT,socketConnected);
socket.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
socket.addEventListener(Event.CLOSE,socketClosed);
socket.addEventListener(DataEvent.DATA,socketReceivedData);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
}
line 242: public function connect( streamType:String = “terminatedStandard” ):Boolean
I added two lines to the connect method, one to clear out any IQ packets from the old connection (may or may not be necessary) as well as initialize the socket.
active = false;
loggedIn = false;
pendingIQs = new Object(); initializeSocket();
Obviously there could be some more thorough testing/optimization done to this code, but this seemed to fix my issues without any noticeable side effects.
file:///C:/Project%20Files/xiff/trunk/src/org/jivesoftware/xiff/core/XMPPConnect ion.as