Skype Java Programming Using JSkype News!
Wei Li
beichuang@yahoo.com
Created: 2005-04-09
(Last updated: 2005-10-10)
Now should work with Skype Client 1.4 :)
1. Introduction
This document intends to give a practical guide on how to use Java language to access the Skype API which is originally targeted at C/C++ programmers. This guide is based on JSkype – a JNI implementation to enable Java clients to use the Skype API. JSkype is provided by Bart Lamot and now is evolving into an open source (LGPL license) project namly Java to Skype API (JSA), accessible at http://jsa.sourceforge.net. The new project plans to provide new interface to support all parts of the API but require no knowledge of the original Skype API itself which means some abstract layers (probably some classes hierarchy) will be composed to encapsulate and hide the actual calls of Skype API.
Unfortunately, there is no new release existing (as by 2005-04-09) at its new home site and the only available version is still on its previous site http://www.lamot.net/jskype. It would have been nice if more instructions had been available on its original site, as it is actually still working well if you setup it correctly by yourself (almost like hacking), although the new site has disclaimed the validity of the old implementation.
2. Installation
The rest of this guide gives you step-to-step instructions on how to setup the JSkype according to my experience which should save your time for at least half a day!
http://www.lamot.net/jskype/JSkype.zip
http://www.dll-files.com/dllindex/dll-files.shtml?msvcrtd
http://www.dsv.su.se/~liwei/JSkype/JSkype.zip.
3. Running the JSkype Example
If you have Java 2 Platform (JDK/JRE) v1.4.2 or later installed, then after the installation steps above, you only need to run the batch file JSkypeExample.bat which has the content of:
REM set path = .\jre\bin,%path%
java -classpath .;jskype.jar;swt.jar net.lamot.java.jskype.swtclient.swtChatWindow
If no Java installed, you need to extract the JRE.zip to your JSkype directory and then uncomment the first line in the batch file as:
set path = .\jre\bin,%path%
java -classpath .;jskype.jar;swt.jar net.lamot.java.jskype.swtclient.swtChatWindow
You will then see a Skype warning window
Click OK button to continue, and fill in some command in the text box then click Send.
And on the prompt window you will see lines like:
Basically, this example works as a Java version of SkypeTracer or the msgapitest example in the official Skype API. You can test it with more Skype API command e.g., Call, SET AUDIO_IN etc.
4. Building Your Java Application Using JSkype
This section should be the most exciting part which gives you some idea how to use the JSkype in your Java program. The following code example resembles the action above to illustrate how to send text message to a Skype user with name “theptcompany”.
// import the JSkype packages
import net.lamot.java.jskype.general.AbstractMessenger;
import net.lamot.java.jskype.general.MessageListenerInterface;
import net.lamot.java.jskype.windows.Messenger;
import java.lang.Thread;
import java.lang.Exception;
/** the MessageListenerInterface interface defines a method onMessageReceived suppose to be called when notifications are received from run-time Skype Client */
public class JSkypeTest implements MessageListenerInterface {
// declare a messenger object to be used to send Skype commands
private AbstractMessenger msgr = null;
/** Creates a new instance of JSkypeTest */
public JSkypeTest() {
msgr = new Messenger();
msgr.addListener(this);
msgr.initialize();
try {
// pause 6 seconds to wait for the initialization of JSkype
Thread.sleep(6000);
// send the Skype API text command
msgr.sendMessage("Message theptcompany hello from JSkypeTest" );
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new JSkypeTest();
}
public void onMessageReceived(String str) {
// we simply just print out if any notifications arrive through JSkype
System.out.println(str);
}
}
The code above can be compiled and run with the batch file JSTest.bat which has the content of:
javac -classpath .;JSkype.jar JSkypeTest.java
java -classpath .;JSkype.jar JSkypeTest
However, if you are using the original JSkype package, you will soon notice that the method onMessageReceived is never called. It means your Java program will not receive any information from the JSkype, which in turn means you can only send command to the it but not possible to receive any feedback from the runtime Skype client to determine e.g., whether your Text Message has been sent successfully to the receiver. The fact is simply because there is a bug in the original JSkype package and good thing is that everyone is able to fix it due to its open source nature.
I have fixed such bug during this writing. So if you run the JSkype example shipped with this gude, you should see the Skype notifications print out not only in the Dos Prompt Window but also in the application GUI. Now you are able to utilize the Skype feedback in your application to conduct more interesting behaviors, e.g., to play a greeting message when your buddies calling in and then record their voice message.
5. Summary
The JSkype gives a simple way to hook your Java application with Skype, and you are able to make more use of the Skype network for your development. However, the Java Native Interface JSkype is rather simple but reasonably robust, although some methods such as destroy, seem not have been implemented yet, that is why you have to call system.exit() to force your application close. If you cannot wait the new version release from the JSA project, you should look into the source code and complete it by your own. There is a big advantage with this current release – simplicity.
Finally, enjoy your coding!
About the Author:
I am a PhD student at Department of Computer and Systems Sciences, Swedish Royal Institute of Technology (DSV/KTH). My research area is Ubiquitous and Context Aware Computing. I like to play with different electronic gadgets (especially wireless ones), like the smart phones and various sensors, which is an obviously a bonus of working in ubiquitous computing areaJ. And one lesson I learned is to keep questioning why after knowing how, there may always be better solution!
I am currently involved in the project Adaptive and Context Aware System (ACAS) and we are constructing a Personal Context Aware System in which the Personal Communication plays an important part. Our project homepage is: http://psi.verkstad.net/acas/
I usually use Java and C/C++, and sometimes other languages like Delphi, VB, C# etc when needed or unavoidable. Generally, I am open to programming languages as I found the right decision is totally dependant on the task requirements such as the device platform, available library and more importantly your time.
This guide is devoted as a part of the Book “Learning Skype’s Plug-In Architecture” by Bill Campbell at theptcompany. It has been a great honor to be invited to participate in this book and a great time working with such a knowledgeable and warm-hearted editor.
Last, but not least, most thanks should go to Bart Lamot who made JSkype freely available with open source. Here what I did is just some complementary work like an evangelistJ.
* As reported recently, the previous JSkype did not
work with the new Skype clients (v1.4 and above), as the original C++ example
still works with the new versions, it should be able to make it work again
(there must be some bugs in the original JSkype implementation hidden before).
Now I have fixed it. However, for an alternative solution, you can also try another Java Skype library or here, which uses IBM’s Bridge2Java to
enable Java access to MS COM component (ActiveS).
Or you can still use your old Skype client (e.g., v1.3.0.57) to test with the previous JSkype; however, without the access to the later new functions.