In this assignment, you will be providing your own user interface to Skype by sending and receiving commands based on the Skype API. These commands will be exchanged using JSkype. JSkype is a JNI implementation (released under the LGPL) which enables Java clients to use the Skype API. To use this with your own program, you will need to follow the following steps:
As an example, you can try out the following code (noting that you should not put your thread to sleep if this were a Swing program):
/* * JSkypeExample.java * for CSW4170 - Spring 2006 * * Created on April 2, 2006, * Sean White - swhite [at] cs.columbia.edu * * * Requires JSkype.jar and JSkype.dll to run * This is a simple example of using the JSkype interface. */
package jskypeexample;
// 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;
/**
*
* @author swhite
*/
public class JSkypeExample implements MessageListenerInterface {
// create a messenger which we'll use for sending messages
private AbstractMessenger msgr = null;
/** Creates a new instance of JSkypeExample */
public JSkypeExample() {
msgr = new Messenger();
msgr.addListener(this);
msgr.initialize();
try {
// This number may vary on your system depending on the amount
// of time required to initialize the msgr.
Thread.sleep(1000);
// send the Skype API text command
msgr.sendMessage("Message seanmwhite Hello from UI Student");
msgr.sendMessage("SEARCH FRIENDS");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new JSkypeExample();
}
public void onMessageReceived(String str) {
// This is where you will handle all strings that are returned.
System.out.println(str);
}
}
Interaction with JSkype is normally based on sending a command and receiving a response. However, there will be some messages received from Skype which are not initiated by a command. For instance, you may be notified when a new friend logs on.
Descriptions of some common commands are here.
Full documentation for the Skype API 2.0 can be found here.
The code and instructions are based on Bart Lamont's JSkype and Wei Li's updates. Lauren Wilcox converted this to the Swing Example.