Spice up your Flex Builder 2 projects with XMPP, using an newly ported ActionScript 3 version of XIFF
–>If you would like to skip to the Flex demo of the messenger just go here.
A few months ago I started working on a complex RIA that required an instant messenger type component. We decided to use Flex Builder 2 and ActionScript 3 to developer the application. I quickly realized that with ActionScript 3 being so new (in terms of official release) that there was no real standardized way to add the component. So I started exploring different options, weighing the benefits and drawbacks of various technologies. Licensing cost, scalability, reusability, maintenance and standardization were among the main criteria I used to come to an effective solution.
Where I landed was a bit of a hybrid. I decided to utilize Jabber for the textual component of the software.
"Jabber is best known as "the Linux of instant messaging" — an open, secure, ad-free alternative to consumer IM services like AIM, ICQ, MSN, and Yahoo…" from Jabber
Combine this with Flash Media Server for the video chat and you have a solid messaging platform. (FMS integration is out of the scope of this blog but I am sure I will be documenting my experience with it at a later date.)
In order to satisfy the business needs of this project I needed to combine
-the built in Flash XML socket functionality;
-a standardized xml specification called xmpp (Jabber);
-an open source server that supports this specification (Wildfire server in
my case);
-and an open source xmpp api called XIFF.
The only rub, XIFF was currently in beta and written in ActionScript 2.
XIFF is a Flash API for instant messaging and presence using the XMPP protocol. The main developer, Sean Voisen had a solid, object oriented library from which to start an AS3 port.
I decided it made more sense to take an existing well written library and port it than start from scratch. Given that this library is protected by a limited GNU license it also meant I would be giving something back to the Flash community, which, has been an immeasurable asset to me over the years.
I teamed up with a super talented developer, Derrick Grigg and got to work. Let me tell you, converting a large library of AS2 code to AS3 is no small task. The rules for AS3 have definitely changed. All the methods that pulled null results and thus silently failed are silent no more! You’ll quickly see the reason for “try…catch…finally” as there is nothing silent about a failure in AS3. The support for runtime errors is huge and ultimately makes a library like this much more stable. The prototype decoration that solved for multiple inheritance issues… not supported (I say that, knowing full well there is a way to do it… it's just not pretty). AS3 loves using the inheritance chain the way it was intended.
So now that the new AS3 library is (almost) available, here are some summary stats..
Features:
XIFF includes an extension architecture that makes it easy to add functionality for additional protocol extensions, or even your own special-needs extensions. There are quite a few extensions already included in the library, giving it support for the following functionality:
• XML-RPC over XMPP (JEP-0009)
• Multi-user conferencing (JEP-0045)
• Service browsing (JEP-0030)
• XHTML message support (JEP-0071)
Compatibility:
The following are servers that are known to work with XIFF and Flash:
• Wildfire (http://www.jivesoftware.org/wildfire)
• Jive Messenger (http://www.jivesoftware.org)
• Antepo OPN Server (http://www.antepo.com)
• OpenIM 1.2.1 (http://www.open-im.net/en/)
• JabberD 1.4.3 (http://www.jabber.org)
• Jabber, Inc. XCP (http://www.jabber.com)
With the feature and compatibility set, here are some common uses and ideas.
Possible uses:
• Adding instant messaging to your projects. This includes nifty features like presence information, multi-user conferencing support, XHTML message support, Flex data enabled roster handling and so on.
• Live communication of any kind, including live tech support, admin communication, and anything that requires a live response from an admin side.
•Creative advertising… use your imagination.
• The general ability to be able to “push” content to your visitor, rather than depending on them to “request” it.
This library is currently in alpha. As soon as there has been a bit more testing we will move it to beta and release the source. Check out a Flex demo of the messenger here.
//nick

multi-user chat
personal messaging
hi nick, so great to see this port been done! I can only see good things come from such a library!! I’m wondering however if u have any info as to what the status is on the current XIFF beta lib for ActionScript 2. We are building a rather large IM client and wrapping with Northcode’s SWF Studio for the desktop. Although we have managed just fine with the beta and added as we’ve needed (such as photo support for VCards) it would be awesome to know if XIFF will ever come out of beta.
Once again kick-ass job! love it!
Sounds cool.. keep me posted.
I have been in contact with the original authors. I dont want to speak for them but I do not believe any new development is going on currently. That said, the beta build is good, and I only found a few bugs during the port.
There is a developer that did some work called xiffian.
http://xiffian.sourceforge.net
I do not know the status of this but you may want to take a look. I heard he branched and fixed some issues, especially dealing with the Roster class.
//nick
[...] Good news for anyone looking to build XMPP/Jabber-enabled applications in Flex 2.0: Nick Vellof has just completed an inital port of XIFF to Actionscript 3.0. I’ve been in communication with Nick throughout the development process, but he and fellow developer Derrick Grigg have been the ones doing all of the great programming and bug-squashing work. Nick has briefly documented some of the challenges and opportunities that befall porting a large library of code from AS2 to AS3, which believe me is no small task. XIFF 2.0 (the AS2 version) made good use of prototype decoration and the “mix-in” design pattern, not to mention had a complete lack of runtime error checking, just to name a few of the challenges that Nick and Derrick faced. [...]
Hey Nick,
Love this work, was wondering if you could let me know when you will release a beta version for us to checkout!
If I could ask you a few questions, that would be great!
Drop me an email.
Cheers,
Kyle
The core components are actually pretty solid at this point. The problem is, I have not had any time to do any documentation/commenting. The event model has changed from the AS2 version and it would certainly create some confusion.
I hope to finish it up soon… but it is just me working on it and I have a lot going on
I’ll keep you posted!
Looks really fine,
I’m working at the moment on a Instant Messenger with Video / Audio Support for my Thesis at University ( Audio / Video will be done with RED 5, Backend of the System will be done in JBoss Application Server). I have Problems with integrating the XIFF Library in Flex 2 , I always get errors that I have to put the XIFF classes into packages when I put the import commands.
It would be great if you have any Idea how I can solve this problem
ICQ : 95031059
Stay tuned
Jacques
My guess is that you are trying to add the xiff as2 library to a Flex 2 application. To add xiff to a flex 2 app you will need the new xiff version in as3.
As soon as I get time to comment the code I’ll give it out…
If you need an advanced copy I can give it to you but it may be difficult to use with no documentation.
Yep you’re right I was trying that. An advanced Copy would be great! I’m sure FLEX 2.0 will change a lot in the Internet Application Developpment. You can contact me under jacques@putz.lu. Tx snooop
Hello,
It seems to be a very good work !
Can we have the beta version ? I’m working with Xiff but your version seems to be very fast (with direct connection without XML support
).
This sounds like a great project. Need help?
We can help We have an ajax IM, and are doing a lot of flex work right now. Let me know how we might be able to help.
Thanks
michael@friendlytek.com
Hello,
Although new to Jabber & XMPP, I find the XIFF effort to be really a good thing to have, by all means. I would like to know if XIFF will support any generic XMPP-compliant server? in particular the “Sun Java System Instant Messaging” server? can anyone input on this one?
XIFF is based on the standard XMPP protocol. With the new xiff version using a direct socket connection, it should work with any generic xmpp compliant server.
I have personally tested it with the Jabber XCP and Wildfire.
Feel free to load up the demo and put in your own server installation address. Everything should work but the multi-user chat. MUC requires the room to be set up on the server, as with any client. XIFF does allow you to set up a room client side, I just did not implement this feature in the demo.
Velloff,
If XIFF now supports direct socket connection, does this mean that you have implemented a complete AS3 reference to the XMPP’s binary message patterns? Is the intended purpose of this is to make the XIFF library communicate faster with XMPP-based systems than it would before using XMLsocket connections? (I am new to Flex/Flash
A couple of months ago, earlier in this blog, you mentioned that you were working on a webapp that required presence/IM features, and you have decided to go for a back-end built upon a Jabber-based system for handling the issues of presence and instant messaging within the network. This, combined with the optional use of Flash Media server for extending the system’s capabilities to integrate audio/video streaming between users.
I have read in the Flash Media Server manuals that it includes its own back-end and mechanism for managing presence in a network of connected users, as well as providing for instant messaging capabilities. This issue is in particular interest to me, since I need do develop a system that would be more or less similar in its capabilities to the one you’ve described.
Can you share your insight on as to why you have chosen a deployment model that builds upon a Jabber back-end rather than using FMS native presence/IM features?
In addition, do you suppose that integrating Flex Data Services into such a system can provide for additional advantages over the base Jabber/FMS offerings?
Thanks,
Moses Shohet.
Moses,
The purpose of utilizing the socket connection currently was to vastly improve performance. It also helped with compatibility due to the nuances Flash’s XMLSocket imposed that required a hack on the server to function. This is no longer needed and it (presumably) can work with any Jabber server installation.
My particular circumstances required some very robust scalability. While FMS does have presence functionality, I decided a blend of the technologies allowed me to better utilize their strong points.
Presence/Chat
Jabber allowed a wide range of server options at varying licensing costs. XMPP privided a standardized protocol that had a tremendous amount of flexibility. If you needed to tie into other messenger services (ie AOL IM) there are several servers available that make this possible (AOL legal issues aside).
FMS was used to handle the A/V. This proved more cost effective from a scalability perspective due to licensing costs. You could certainly build a chat client using FMS presence/messaging capabilities, and indeed others have. This would work much better for a limited user base as you could do some very specific calculations as to how many machines and licenses you would need.
Flex Data Services is a different story. It’s messaging features are centered around client/server-/client data synchronization. It’s messaging is not tailored for use with this kind of application. Using FDS to do instant messaging would be a bit like using a sledge hammer to drive in a thumb tack (IMO). And at 20k a logical cpu, you could get into some real cost issues quickly.
HTH,
Nick
Nick,
Can the implementation of direct socket connection traverse Firewall / NAT where the XML Socket implementation can’t?
Thanks,
Moses.
No, as they are both using a port that is potentially blocked by the firewall. Http binding is what can allow comm over port 80. Will be adding that support to XIFF…
when is the new as3 code shareable here?
I need to try to build a im client quick in flash 9.
Hi Nick
Was wondering if you would release the code for the demo ?
do you need help docuementing the classes.
I can build a uml model of the design if you like that can be shared as xml or html. I am determined to get as3 version of XIFF.
I am still working on the event structure of my code.
Actually, that is exactly what is incomplete at this point. I’ll email Sean, who has agreed to work on documentation, but is super slammed. I’ll put him in touch with you to see if that will work.
As a side note, I think we should use ASDocs to document the code. It has worked really well on other large scale AS3 projects I have done.
cool i spoke with we he refered me to you.
I will try him too.
Hello Velloff,
I am anxiously waiting and I would like to know when will the ‘XIFF Library’
be available and will you provide examples to show how one can utilize it?
Thanks heaps
Kind Regards,
Will
XIFF beta AS3 is available.
Check out http://www.igniterealtime.org/projects/xiff/index.jsp
No documentation yet, but I presume they are being worked on.
hey nick,
wonderful example!
is there any way you could open source the example? it would help a great deal in understanding how to use the underlying APIs of XIFF on AS3
best, karthik
Velloff — Hey, it is a cool app. Wondering did you get a chance to work on HTTP Binding?
Thats really awesome!
I just had trouble connecting to a DJABBERD server (www.danga.com/djabberd/) … got a strange auth error
Where can I download the library?
I am also very interested in checking out the Flex Build 2 library. Thanks for all of the effort. Let me know I can be of any help from Illinois!
- Taskin
Simply fantastic work!!!
Thank you so much!!!!!
It’s exactly what I needed for a new project I’m currently working on.
Only one thing though, if you could open source the demo you provided you would be my god.
Thanks again!!!
Daniel Neri
Hello! Help solve the problem.
Very often try to enter the site, but says that the password is not correct.
Regrettably use of remembering. Give like to be?
Thank you!
The public repository location is here:
http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/
Thanks for all the good work. I was wondering about the http binding support mentioned above. I don’t see it in the beta1 code, but maybe I’m looking in the wrong place?
Thanks again.
Hi Nick,
Thanks so much for this, great work. A couple of questions:
1) Do you have any timeframe for when HTTP binding support will be available?
2) The compatability section in the XIF readme, does not include Wildfire. This page however, does include Wildfire as a compatable server. Has support been dropped or is this just a documentation oversight?
Regards
Rob
Wildfire and Openfire are both supported.
The HTTP binding timeframe is still up in the air. I will need it for an upcoming chat client for my current venture. A very safe estimate would be that it would be available by the end of the year.
I wish I have more time to focus on XIFF.
Hi. Is the source code available? I can comment it.. seriously, i could definately use it for a project I started working on with solid financing, and I will be more than happy to help you comment it in exchange for the source code!
If you could.. you would be a life saver. I chose OpenFire / XIFF cause I thought from what I had read that there was a AS3 version out, and now I realize there is no such thing..
thanks!
Martin
Hello Nick,
Just wanted to know if through the use of the new XIFF library in a flex2 application, can the Jabber server really push messages directly to the flash client or is there some polling mechanism which is in use?
Nick,
I have come across a JMS/XMPP bridge (http://activemq.apache.org/xmpp.html) and it occurred to me that together with the new XIFF library it might be empolyed to create Flex2 XIFF clietns that could tie into JMS architectures thus enabling message-oriented server-side Java EE applications to push data into Flex2 clients for the achieving the realtime effect. From your professional point of view and experience with XIFF and XMPP, do you think this direction is viable for achieving what I have mentioned above?
Moses,
XIFF is extremely flexible and allows you to create any custom extensions. I don’t see any reason what you are suggesting would not work.
Hi, this seems very nice but why won’t you release the source code for the demo so we can start developing? I have my own jabber server since yesterday which I want to use to replace text chat on my site and can’t wait to get my hands on it
greetings from belgium
Hi,
I recently downloaded 2.0.0-beta4 with the intension of using it within a Flex 2 project. When I set up the folders within my project, I realised that none of the actionscript files had package definitions and some of the syntax was in ActionScript 2. For example some of the functions return values are set up with :Void instead of :void. As I understood it, the XIFF API was meant to be in ActionScript 3. Have I downloaded the wrong release???
If anyone can push me in the right direction, it would be greatly appreciated.
Cheers
The library you should check out is here:
http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/
[...] Nick Velloff’s blog post and AS3 XMPP client – full working example with source code [...]
I use openfire as a server, and have a acount, in spark, i use this acount to login for MSN, Google talk and ICQ.
Now I login in XIFF client, but I get no buddies until I login in Spark.
Could you tell me how I solve this problem.
I there any news of this beta moving to production?
any word on when the source will be released?
I released it some time ago… hth
http://www.velloff.com/?p=38
Any plans of the AS3 XIFF version moving out of the svn into a compiled swc? If so, what is the timeline?
I also am not sure where to submit fixes so since it’s such a small fix I’ll send it here. I changed line 623 on XMPPconnection.as from:
var resultAuth:Array = resultIQ.getAllExtensionsByNS(AuthExtension.NS)[0];
to:
var resultAuth:AuthExtension = resultIQ.getAllExtensionsByNS(AuthExtension.NS)[0];
The Array casting was throwing an invalid cast error when doing an anonymous login
Thanks for the fix.
If you would like a compiled version of XIFF, check out the latest version into flex here:
http://svn.jivesoftware.org/svn/repos/xiff/trunk/
then look in your bin directory once it has compiled… you will see a file call XIFF.swc. This is your compiled code, and can be included in any project.
Thx. I used the Build Project once I imported the project into Flex Builder. I used http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/ instead though.