Activate your free membership today | Log-in

Monday, February 11th, 2008

JSJaC: JavaScript Jabber Client Library

Category: JavaScript, Library

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

or handle presence:

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

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

Related Content:

  • A
    Jabbim ( Jabber client )...
  • PYD
    Jabbim ( Jabber client ) dynamic...
  • JavaScript Learning Guide
    This SearchDomino.com guide introduces you to JavaScript in a Notes/Domino environment, explains best practices and pitfalls to avoid and provides...
  • Ajax library light as a feather
    Feather Ajax is a new JavaScript library for building rich client user interfaces on Web pages. The script is said to weigh in at less than 1KB and is...
  • Ajax powers Rich Client Faces
    Rich Client Faces is a JavaServerFaces library that provides a component set for building Web applications. RC Faces use Ajax technologies and an...

Posted by Dion Almaer at 7:58 am
4 Comments

++++-
4.5 rating from 29 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.