Monday, February 11th, 2008

JSJaC: JavaScript Jabber Client Library

Category: JavaScript, Library

JSJaC is a JavaScript Jabber Client Library that was built “to ease implementation of web based jabber clients. For communication with a jabber server it needs to support either HTTP Polling or HTTP Binding.”

To use the library you can check out examples to see how you can do things like send a message:

javascript

  1. function sendMsg(aForm) {
  2.   if (aForm.msg.value == '' || aForm.sendTo.value == '')
  3.     return false;  
  4.  
  5.   if (aForm.sendTo.value.indexOf('@') == -1)
  6.     aForm.sendTo.value += '@' + con.domain;
  7.  
  8.   try {
  9.     var aMsg = new JSJaCMessage();
  10.     aMsg.setTo(new JSJaCJID(aForm.sendTo.value));
  11.     aMsg.setBody(aForm.msg.value);
  12.     con.send(aMsg);
  13.  
  14.     aForm.msg.value = '';
  15.  
  16.     return false;
  17.   } catch (e) {
  18.     html = "<div class='msg error''>Error: "+e.message+"</div>";
  19.     document.getElementById('iResp').innerHTML += html;
  20.     document.getElementById('iResp').lastChild.scrollIntoView();
  21.     return false;
  22.   }
  23. }

or handle presence:

javascript

  1. function handlePresence(aJSJaCPacket) {
  2.   var html = '<div class="msg">';
  3.   if (!aJSJaCPacket.getType() && !aJSJaCPacket.getShow())
  4.     html += '<b>'+aJSJaCPacket.getFromJID()+' has become available.</b>';
  5.   else {
  6.     html += '<b>'+aJSJaCPacket.getFromJID()+' has set his presence to ';
  7.     if (aJSJaCPacket.getType())
  8.       html += aJSJaCPacket.getType() + '.</b>';
  9.     else
  10.       html += aJSJaCPacket.getShow() + '.';
  11.     if (aJSJaCPacket.getStatus())
  12.       html += ' ('+aJSJaCPacket.getStatus().htmlEnc()+')';
  13.   }
  14.  html += '</div>';
  15.  
  16.   document.getElementById('iResp').innerHTML += html;
  17.   document.getElementById('iResp').lastChild.scrollIntoView();
  18. }

Since Jabber (XMPP) is taking over the world, it may be a nice tool in the toolbox.

Posted by Dion Almaer at 7:58 am
4 Comments

++++-
4.2 rating from 39 votes

4 Comments »

Comments feed TrackBack URI

It seems, that everything can be done by JavaScript :)

Comment by Gaku — February 11, 2008

Prototype window class demo client:

http://jabbermania.blogspot.com/2007/06/jsjabber-educational-client-in.html

Ext.JS version maybe coming soon :) Anyone interested? (I need to wrap jsjac into an ext-style API, it’s nearly done, but I’m curious if anyone needs it)

Comment by Adam Nemeth — February 11, 2008

Hey Adam, I’d love to see it in detail and get to chat with you :)

I tried to reach you on your blog, but it’s kinda difficult since it’s in hungarian.

I hope to hear from you ;)

Comment by rameen — February 11, 2008

Hi rameen,

you can reach me at the username aadaam at google’s well-known mail service. (Ajaxian-style spamprotection :)

Comment by Adam Nemeth — February 12, 2008

Leave a comment

You must be logged in to post a comment.