This may serve as a rough guide for working with Jabber and Firefox. Right now I believe the only option for doing so – unless you want to build your own Jabber client – is to build upon SamePlace. SamePlace is a great extension, and even though it’s relatively new, I wish I discovered it sooner. Since installing it my browser has basically been my desktop. The interface is really nice and you can use it with a bunch of instant messaging services.
Firstly, if you have never built a Firefox extension, use the wizard. I went through hell doing my Hello World extension using Mozilla’s instructions. Also, the Hello World example is a far cry from making an extension that has even the most limited functionality. Ted’s extension wizard gives you the framework and outlines the components perfectly.
Secondly, this may be common knowledge to JavaScript pros, but as someone who is relatively new to JavaScript, I discovered quite quickly that event listeners are my friends. Mozilla’s documentation was the best I found for a high level description of their purpose and parameters, and adding browser event listeners will add robustness to your extension.
With Jabber you trigger events on channels. You need one channel per event type and direction. Channels exist for incoming and outgoing messages, presence, and listening for iq packets, among others. According to SamePlace creator Massimiliano Mirra, “<iq>’s are used when you have to carry out a ‘conversation’ with a server or other entity following a predefined sequence, such as updating your profile or requesting a roster (contact list). With iq events you listen to those packets, although you’d usually not set a listener for them and instead use the one-time listener given as third argument to send(), as in:
XMPP.send(account, <iq to=”some-entity”>…</iq>, function(reply) {
alert(reply.stanza) })
Remember that since your Jabber Firefox extension lives only on the client, events that affect both clients (chat partners) should be handled by both directions – ‘in’ and ‘out’ – of an event type. This means that if you are processing the text of a message in the same way for the sender and receiver, you must have two channels and two events – message ‘in’ and message ‘out.’
Play around with these ideas to get a feel for developing for Jabber. Also, don’t forget to download ChattyTime, a very exciting and brand new extension by Andrea Dulko and I. Thanks!