Skype API For Mac PDF Print E-mail
Sunday, 06 April 2008

One easy way to implement communications between two applications over the internet is to piggy-back onto an instant messenger. Skype allows you to do this (through its AP2AP protocol) as well as access a whole load of other features through its API.

This can be done on the Mac platform through either AppleScript calls (this is easiest but lacks any way of allowing Skype to send updates of events asynchronously) or through the Skype framework.

This REALbasic code provides access to the functions and call-back events in the framework, and also implements an example class to illustrate using the Skype API to access the user's buddy list and online status information. The Skype framework must be downloaded from Skype's developer site here, and should be either bundled into the completed app or installed in the appropriate "Frameworks" folder.

The commands and responses used in the command strings are documented in the Skype API Reference.

The Skype project file consists of the following elements:

Module – Skype

This module contains the code for interfacing with Skype through the framework. This consists of the following public classes:

Initialise - This sets up the Skype connection object or delegate. Accepts a parameter of the application name as a string, and returns nothing. The name you specify is the one that the Skype application will use to authorise against your connection. You should not include version information.

  • Running - This returns a boolean to indicate if Skype is running.
  • SetDelegate - This registers the delegate (set up above) with Skype.
  • Connect - This connects the application to Skype.
  • SendCommand - This accepts a string parameter which is sent to Skype as a command string. A string is returned containing any result returned from Skype.
  • RemoveDelegate - This removes the application information from Skype and is not normally used.
  • Disconnect - This disconnects the application from the Skype API.
  • AddListener - This adds a SkypeMessageReceiver based instance (see below) to be notified of any events from Skype.
  • AttachStatus  - This integer property contains the status returned following the attempt to connect. This is set by the AttachResponse call-back from Skype and may not be set immediately after the call to Connect.

Interface – SkypeMessageReceiver

This class interface implements four methods called by asynchronous messages returned from Skype. All classes which use the Skype API should implement this interface and should be registered with the Skype module using the AddListener method. The methods defined by the interface are:

  • SkypeAPIConnected - When the connection to Skype is established.
  • SkypeAvailable - The Skype application became available.
  • SkypeUnavailable - Skype became unavailable (was quit).
  • SkypeNotificationReceived - This passes a string parameter containing a command message from Skype.

Example Class - SkypeTest

This class simply implements a single event handler which is passes on any notification messages from the Skype API.

Example Class - Skype User List

This class uses the API to build and maintain a dictionary (called Users) which contains a list of all the user's Skype contacts, together with their full name, display name and online status. These values are stored as dictionaries within the main dictionary, with the user id as the key. The other keys are "FULLNAME", "DISPLAYNAME" and "ONLINESTATUS". This is kept updated using the Skype notifications, and other dictionary values may be added by these notifications (explore this by browsing using the debugger).

Window - Window1

This window uses the SkypeTest class to display the notification messages sent by the Skype API. Skype messages can also be sent with the responses being included in the edit field. Note the Open and Close methods which are used for attaching and detaching to the Skype API. 

Last Updated ( Thursday, 22 May 2008 )
 
Next >