Getting Started with JSkype

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:

  1. Download and install Skype.
  2. Download jskype.jar and jskype.dll from here. For the curious, source code and another test program that lets you send and monitor messages is also available here.
  3. A simple example of a NetBeans Swing project that uses JSkype is here.
  4. Add jskype.jar and jskype.dll to your classpath. In NetBeans, you can put these in your project folder and add the jar file to the libraries used in the project.
  5. In your java file, add imports:
    import net.lamot.java.jskype.general.AbstractMessenger;
    import net.lamot.java.jskype.general.MessageListenerInterface;
    import net.lamot.java.jskype.windows.Messenger;
  6. Create a class which implements MessageListenerInterface and make sure you create a method onMessageReceived(String message).
  7. Instantiate a messenger:
    private AbstractMessenger msgr = new Messenger();
  8. In your constructor, initialize the messenger:
    msgr.addListener(this);
    msgr.initialize();
  9. When you want to send a command, use msgr.sendMessage(String);
  10. When a message comes from the Skype API the method onMessageReceived(String message) of your class will be called.

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);
   }
   
 }
 

Commands

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.

Acknowledgments

The code and instructions are based on Bart Lamont's JSkype and Wei Li's updates. Lauren Wilcox converted this to the Swing Example.