Introduction

This is the reference documentation for the Unity Web API (version 0.8). This is a full API reference, a Quickstart guide may be found here.

The Unity API Object

We begin with the toplevel Unity object. If you know which interface you are interested in, jump ahead.

dictionary UnityInitParameters {
   String name;
   String iconUrl;
   Callback onInit;
   optional String domain;
}
interface Unity {
   method init (UnityInitParameters initializationParameters);
   method addAction (String actionName, Callback onActionInvoked);
	
   UnityNotificationInterface Notification;
   UnityMessagingIndicatorInterface MessagingIndicator;
   UnityMusicPlayerInterface MusicPlayer;
   UnityLauncherInterface Launcher;
}
UnityInitParameters dictionary

UnityInitParameters is a specification of a dictionary containing Unity initialization data. Three parameters are required:

There is a fourth optional parameter:

Unity.init method

In order to initialize the interface, a client must call the Unity.init method. Usage of any methods in the Unity interface besides init before intialization occurs will produce no result. It is guaranteed this will not produce an error.

Arguments:

Example code:

function unityReady () {
   // Make use of the Unity API
}
Unity.init ({name: "Fooapp",
             iconUrl: "http://www.ubuntu.com/icon.png",
             onInit: unityReady});      
Unity.addAction method

The Unity.addAction method may be used to add a hierarchy of application actions to be exposed through the Unity HUD.

Arguments:

Example code:

Unity.addAction("/File/Send to/Contact", onSendToContact);
The Unity.Notification interface

The Unity.Notification interface is used for displaying transient notifications to the user. Such notifications should not be urgent, or nececessitate user response.

interface UnityNotificationInterface {
   method showNotification (String summary, String body, optional String iconUrl);
}      
Notification.showNotification method

The showNotification method presents a single notification to the user.

Arguments:

Example code:

Unity.Notification.showNotification("Just so you know", "This is a notification!");     
The Unity.MessagingIndicator interface

The Unity.MessagingIndicator interface has three primary components:

dictionary UnityIndicatorProperties {
   Integer count;
   Date time;
   String iconURI;
   Callback onIndicatorActivated;
}
interface UnityMessagingIndicatorInterface {
   method showIndicator (String name, optional UnityIndicatorProperties indicatorProperties);
   method clearIndicator (String name);

   method addAction (String name, Callback onActionInvoked);
   method onPresenceChanged (Callback onPresenceChanged);
   readonly attribute String presence;
}      
UnityIndicatorProperties dictionary

UnityIndicatorProperties is a specification of Indicator properties to be passed to MessagingIndicator.showIndicator method. Note, the indicatorProperties parameter of this method is optional, and as such all fields of this object are optional:

MessagingIndicator.showIndicator method

The showIndicator method is used to display a single indicator to the user in the messaging menu. An indicator represents a persistent notification of a messaging event and provides means to follow up on this intent.

Arguments:

Example code:

Unity.MessagingIndicator.showIndicator("Inbox", {count: 3});
Unity.MessagingIndicator.showIndicator("Message from Matt", {time: messageTimestamp, 
                                                             iconUrl: mattsAvatar});      
MessagingIndicator.clearIndicator method

The clearIndicator method is used to remove a previously displayed indicator by name, for example in response to the user following up on the assosciated message.

Arguments:

Example code:

Unity.MessagingIndicator.clearIndicator("Message from Matt");
MessagingIndicator.addAction method

The addAction method of the MessagingIndicator interface is used to add an action shortcut to the applications entry in the messaging menu. Note that unlike the Unity.addAction method, this interface does not deal with a hierarchy of actions.

Arguments:

Example code:

Unity.MessagingIndicator.addAction("Compose New Message", onComposeActivated);      
MessagingIndicator.presence attribute

The MessagingIndicator.presence attribute is a readonly string describing the users requested messaging presence. It may take one of four values:

If your application exposes some sort of presence for the user, respecting the users chosen value here is a courtesy.

MessagingIndicator.presenceChanged method

The MessagingIndicator.presenceChanged method is used to receive notifications when the user expresses a request for a new presence state.

Arguments:

Example code:

function presenceChanged () {
   if (Unity.MessagingIndicator.presence == "offline") {
      signUserOut();
   }
}

Unity.MessagingIndicator.onPresenceChanged(presenceChanged);    
The Unity.Launcher interface

The Launcher interface can be used to display small amounts of information to the user through the Launcher icon. Also actions may be added to the Launcher Quicklist, enabling the user to quickly access key application functionality.

 interface UnityLauncherInterface {
   method setCount (Integer count);
   method clearCount ();
	
   method setProgress (Number progress);
   method clearProgress ();

   method setUrgent (Boolean urgnet);

   method addAction (String name, Callback onActionInvoked);
}     
Launcher.setCount method

The setCount method is used to display an integer count on the applications launcher icon. This is appropriate, for example, to indicate a number of unhandled items.

Arguments:

Example code:

Unity.Launcher.setCount(numUnreadMessages);      
Launcher.clearCount method

The clearCount method clears a previously set launcher count value, causing the icon to return to its default state.

Example code:

Unity.Launcher.clearCount();
Launcher.setProgress method

The setProgress method is used to display a floating point progress on the applications launcher icon. This is appropriate, for example, to display progress with a lengthy file transfer.

Arguments:

Example code:

Unity.Launcher.setProgress(numUnreadMessages);      
Launcher.clearProgress method

The clearProgress method clears a previously set launcher progress value, causing the icon to return to its default state.

Example code:

Unity.Launcher.clearProgress();
Launcher.setUrgent method

The Launcher.setUrgent method sets the urgent state of the Launcher. This is used to communicate that the application is requesting the users attention. The urgent state will automatically be cleared by Unity when the user reponds to the application, or after a timeout.

Arguments:

Example Code:

Unity.Launcher.setUrgent(true); 
Launcher.addAction method

The Launcher.addAction method may be used to add Quicklist actions to the Applications launcher icon. The interface and functionality are similar to the MessagingIndicator.addAction interface, but the Launcher is suitable for more general actions. Quicklist actions may for example be useful to quickly jump to specific categories of an applications views.

Arguments:

Example code:

Unity.Launcher.addAction ("Science", onScienceAction);
Unity.Launcher.addAction ("Sports", onSportsAction);
Unity.Launcher.addAction ("Entertainment", onEntertainmentAction);
The Unity.MusicPlayer interface

The Unity.MusicPlayer interface is suitable for applications which play back audio or video content. It is possible both to export metadata about the currently playing media (for quick viewing by the user), and hook in to the Unity Media Controls: allowing your users to control the media with the same interface used for native applications.

enumeration UnityPlaybackState {
   Playing,
   Paused
}

dictionary UnityTrackMetadata {
   String title;

   optional String album;
   optional String artist;

   optional String artLocation;
}

interface UnityMusicPlayerInterface {
   method setTrack (UnityTrackMetadata trackMetadata);

   method onPrevious (Callback onPreviousCallback);
   method onNext (Callback onNextCallback);
   method onPlayPause (Callback onPlayPauseCallback);

   readwrite attribute UnityPlaybackState playbackState;

   readwrite attribute Boolean canGoNext;
   readwrite attribute Boolean canGoPrev;
   readwrite attribute Boolean canPlay;
   readwrite attribute Boolean canPause;
}	      
UnityPlaybackState enumeration

The UnityPlaybackState enumeration is used to indicate the current status of Media playback.

Values:

UnityTrackMetadata dictionary

The UnityTrackMetadata dictionary specifies properties to represent the metadata of a single track (to be displayed in the Unity Sound Menu). A single property is mandatory:

There are three optional properties:

MusicPlayer.setTrack method

The setTrack method is used to expose metadata of the current media assosciated with your application. This will be represented in the Unity Sound menu, allowing users to at a glance find important media information.

Arguments:

Example code:

var trackInfo = {title: "Synchronous Grabs on my Heart",
                 album: "Love in the key of Compiz",
                 artist: "Sam Spilsbury"};

Unity.MusicPlayer.setTrack (trackInfo);
MusicPlayer.onNext method

The onNext method is used to register a callback to be invoked when the user activates the "Next" action in the Unity Media Controls.

Arguments:

Example code:

Unity.MusicPlayer.onNext(onNextTrack);
MusicPlayer.onPrevious method

The onPrevious method is used to register a callback to be invoked when the user activates the "Previous" action in the Unity Media Controls.

Arguments:

Example code:

Unity.MusicPlayer.onPrevious(onPreviousTrack);
MusicPlayer.onPlayPause method

The onPlayPause method is used to register a callback to be invoked when the user activates the "PlayPause" action in the Unity Media Controls.

Arguments:

Example code:

Unity.MusicPlayer.onPlayPause(onPlayPauseTrack);
canGoNext attribute

The canGoNext attribute is used to indicate (through a boolean value), whether the 'Next' action is currently a valid action by the user. This for example, may not be true while playing the last track of a media collection.

Example code:

Unity.MusicPlayer.canGoNext = false;
canGoPrevious attribute

The canGoPrevious attribute is used to indicate (through a boolean value), whether the 'Previous' action is currently a valid action by the user. This for example, may not be true while playing the first track of a media collection.

Example code:

Unity.MusicPlayer.canGoPrevious = false;
canPlay attribute

The canPlay attribute is used to indicate (through a boolean value), whether the 'Play' action is currently a valid action by the user. This for example, may not be true while media content is still buffering.

Example code:

Unity.MusicPlayer.canPlay = false;
canPause attribute

The canPause attribute is used to indicate (through a boolean value), whether the 'Pause' action is currently a valid action by the user. This for example, may not be true during an advertisement.

Example code:

Unity.MusicPlayer.canPause = false;
Appendix A: URI Schemes

This appendix describes the particular format of URI parameters in the Unity Webapps API. Several URI schemes are supported: