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
Can you expand on how to “check out into flex”? Do I just check out of the SVN into a bare flex project? What about all the default stuff flexbuilder adds by default? Maybe someone out there just has one already built that I can work with?
Once I have this swc file can someone give a basic example of how it is called in my flex app? Do I just import it at the top of my mxml? I’m doing my first AIR app and need a little shove in the right direction. A little sample would go a long way.
Thanks in advance. Anthony
check out the svn with something like:
http://tortoisesvn.net/downloads
The goto:
http://svn.igniterealtime.org/svn/repos/xiff/branches/xiff_as3_flexlib_beta1/
in that tool checkout everything from that directory. Inside of FlexBuilder select File>>Import from the menu. Expand General and select Existing Projects into Workspace. Select the directory you exported into. Once created, right click on the project root and select Build Project. Your swc will be in the bin directory. Any other project can add the swc to it’s compile in the Flex Build Path (Library Tab) of the project’s properties.
–or–
Just use a SVN plugin in eclipse (Subclipse will work) to check it out, and it will create a Flex library project that will produce your swc.
Using SWC files in your projects:
http://livedocs.adobe.com/flex/201/html/projects_035_32.html
hth,
nick
Also, try checking out this version:
http://svn.jivesoftware.org/svn/repos/xiff/trunk/
I think there have been some tweaks/bug fixes to this.
Hi Nick,
Previous posts suggest HTTP binding support would be implemented in XIFF by the end of last year. Looking at the code it appears as if it hasn’t, is this still on the cards? If so when do anticipate it will be available?
Regards
Rob
Thanks again for making such a great effort on this.
Rob,
Unfortunately I have not had the time to add HTTP binding support. I don’t think I’ll have time for some time to work on it. I had hoped someone would pick up on this, as it would be a really great feature….
Hi Nick,
What exactly would be involved in adding HTTP binding support? Feel free to respond directly to my email address.
Also, it appears xiff is dependant on the Flex 3 SDK because of the Base64Encoder.insertNewLines() call in the Plain class. I found this a little surprising, given the Flex 3 SDK is still in Beta. Was this a conscious choice or has this call slipped in under the radar?
Regards
Rob
Hi! excellent article! could you pass me some more info regarding FMS integration? Or any article i could check on my own in order to realise how to do it? Thanks in advance!!
Sebas.
Hi vellof, I´ve just realised that this library does not work in Flash CS3? It seems to use arraycollection which is AS2 or AS3 for flex. Is there a way to replace it ad make it available for Flash CS3? Thanks in advance!
yes this was an oversight on my part. it seemed the natural solution to replace the “decorated” array in the AS2 version that provided the addition events when the data changes. it would seem one could do a very simple class that extends array but provides the events xiff needs to know when the data changes… that would probably be the most simple solution.
Thanks for your response regarding the array, anyway, Flex is not a problem at all.
I was also wondering if you could give me a hint about how you were able to stream from FMIS via XIFF. Did you uses XMlStream from the FMIS? Thanks in advace!
I mean, as I understood, you stream audio and video through the jabber server? Or the FMS is only used to stream from flex to flex? i am asking because I am looking the way to stream from a Flash app to a client with jabber but built in another technology. Did you managed to do that?
Thanks in advance!
[...] together as in instant messenger. Should be simple enough — I had a working prototype with a similar library by Nick Velloff. So I decided to try to simply write some login code (and get a nice sound on my Pidgen IM client). [...]
Hi Nick:
Great work.
Could u please give me a test server location to test this demo.
Thanks
HI,I check out xiff lib for svn trunk. But get Erros while building the project.
Line 461 of XIFF_AS3_GUI.xml _roster.updateContact(buddySelector2.selectedItem.jid, null, groupSelector.selectedLabel); the third parement is String type,but need Array type.
Help me ,thanks. Or could you give me the newest source of this project ..Thanks very much..
my MSN:zt2620zt@163.com
Awesome items!! Give us the full lowdown along with loads of pictures when you get back.
great !!!
does “as2″ changing to “as3″ complete?
[...] Ent :: DataGrid Tip: Row Background Color Peter Ent :: Writing Flex 2 Components Code Libraries AS3 XIFF Implementation :: Add Jabber IM to your app! FZip :: Parses Zip [...]
Hi,
i am trying to use xiff3 beta1 as the infrastructure to a web jabber client.
yet, when working with Socket, in case where more than 1 message arrive at the same time (i use a simple for loop in a java test client with Smack to send the messages), then the it seems that the socket in the xiff client does not throw events on the all the incoming messages. usually it stops responding after the second one.
I found out that when shortening the part of code that handle the message, the client succeeds receiving more messages, but still some are lost…
i checked it against both openfire 3.4.1 and 3.5.2.
(tests with XMPPBOSHConnection goes just fine)
[...] AS3 XIFF Implementation :: Add Jabber IM to your app! [...]
[...] Ent :: DataGrid Tip: Row Background Color Peter Ent :: Writing Flex 2 Components Code Libraries AS3 XIFF Implementation :: Add Jabber IM to your app! FZip :: Parses Zip [...]
May I know where can i download xiff.swc? Or any detail instructions to complie it from XIFF?
BTW the link http://svn.jivesoftware.org/svn/repos/xiff/trunk/ is unreachable
I really want to know more about this topic.