For Developers: Writing IM Plug-ins for izuz.net Web IMs

We are very pleased to annouce our newly IM plugin API for our potential developers.

http://izuz.net/ is providing web IM (instant messenging) services for our users. Currently, the web IM services include web Google Talk (Gtalk), web Windows Live Messenger (MSN), web Yahoo! Messenger (YMsg), AOL Instant Messenger (AIM). More services may be added later.

To illustrate our web IM plugin API, we will develop a plugin to export all contact emails.

The final plugin codes:

javascript:p=new net.izuz.gtalk.MainWindow.IMPluginAdapter();p.dealRoster=function(w, e){log(e.email);return false;}; net.izuz.gtalk.MainWindow.addIMPlugin(p);

How to use this web IM plugin

  1. Logout your web IM
  2. Copy the above line of codes (in fact, it is a link), and paste it into the browser’s address bar and press <Enter> to run the JavaScript code
  3. Login your web IM
  4. After all your contacts are listed, there will be a new link anchor generated inside the page named “Open System Console”. Click it will bring you a window with all your contacts’ email.
    If you can not find the link, copy
    javascript:ClazzLoader.loadClass(‘org.eclipse.swt.widgets.Console’,function(){$wt.widgets.Console.openConsole();});
    And paste it into address bar and <Enter> will also bring you a window with all your contacts’ email.

IM Plugin Development Details

In fact, the above plugin contains following lines:

var plugin = new net.izuz.gtalk.MainWindow.IMPluginAdapter ();
plugin.dealRoster = function (mw, evt) {
log (evt.email);
return false;
};
net.izuz.gtalk.MainWindow.addIMPlugin (plugin);

First, all plugins should be an instance of net.izuz.gtalk.MainWindow.IMPluginAdapter. Here is the its Java source (You are not required as a Java expert. But we think giving its source will help you to get a better understanding) :

public static class IMPluginAdapter implements IMPluginable {
public boolean dealLogin(MainWindow mw, DuplicateLoginEvent dle) {
return false;
}
public boolean dealTyping(MainWindow mw, TypingEvent ts) {
return false;
}
public boolean dealMessage(MainWindow mw, MessageEvent ms) {
return false;
}
public boolean dealRoster(MainWindow mw, RosterEvent rs) {
return false;
}
}

And you can override its methods to fulfill your job. The above plugin overrides its dealRoster method, which is about contacts’ information. To override a method using JavaScript is quite an easy job:

plugin.dealRoster = function (mw, evt) {
log (evt.email);
return false;
};

In the above codes, we use log() method to print email into console window. log() method is provided by Java2Script core library. For more information about Java2Script, please visit http://j2s.sourceforge.net/ .

And finally, you add the plugin to our web IM system by net.izuz.gtalk.MainWindow.addIMPlugin (plugin); And you can remove it later by net.izuz.gtalk.MainWindow.removeIMPlugin(plugin);

More about IMPluginAdapter’s Method

net.izuz.gtalk.MainWindow.IMPluginAdapter.dealLogin(MainWindow, DuplicateLoginEvent)
net.izuz.gtalk.MainWindow.IMPluginAdapter.dealMessage(MainWindow, MessageEvent)
net.izuz.gtalk.MainWindow.IMPluginAdapter.dealRoster(MainWindow, RosterEvent)
net.izuz.gtalk.MainWindow.IMPluginAdapter.dealTyping(MainWindow, TypingEvent)

These methods all have two parameters. The first parameter is the messenger window itself. You can do anything you want by using this MainWindow object. We will provide more information this instance in later articles.

The second parameter is about data passing back from web IM servers. There are four events. Here are their data structures:

iz.z.event.DuplicateLoginEvent
iz.z.event.DuplicateLoginEvent.beQuiet // always be true, if there is such a event

iz.z.event.MessageEvent
iz.z.event.MessageEvent.body // message in plain text
iz.z.event.MessageEvent.from // email of sender
iz.z.event.MessageEvent.thread // an ID to mark the chatting session
iz.z.event.MessageEvent.to // email of receiver

iz.z.event.RosterEvent
iz.z.event.RosterEvent.avatar // user’s avatar picture hash
iz.z.event.RosterEvent.confirmed // already a registered user or not
iz.z.event.RosterEvent.email
iz.z.event.RosterEvent.id
iz.z.event.RosterEvent.mode // available, away, idle, busy, offline
iz.z.event.RosterEvent.name
iz.z.event.RosterEvent.status // customized status message

iz.z.event.TypingEvent
iz.z.event.TypingEvent.from // email of sender
iz.z.event.TypingEvent.typing // is typing or not

So, you already can develop some interesting plug-ins to collect your messages and your contacts information.

We would like to hear your feedback for more APIs.

This entry was posted in Developer and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *