|
||
The Droplets Platform Dripline is a mechanism for delivering a variety of client-side desktop alerts, regardless of whether the Droplets application is currently on or off. This document is intended as an introduction for programmers who wish to write Dripline alerts into their Droplets, and presents the essential steps in integrating a dripline into your Droplet. More detailed information on working with the Dripline class can be found in our API documentation for both Java and C++. There are four essential steps in using a dripline in your Droplets:
1. Get a Dripline within your Application class Within your Application (Java) or TDsApplication (C++) class, call the Application's getDripline() method, which has no arguments. So if we have named our application "App", the code would look like this:
Every Droplet that features a Dripline must include a start() method in the Application/TDsApplication class that registers at least one Dripline Channel within it (multiple Channels may be registered if necessary). There is no need to destroy this channel later. So if you have created a Dripline instance called "dripline", your registration would take the following form:
The Dripline class API documentation gives full details on the purpose of each of these arguments. The majority of them are text to be presented in various circumstances, while the driplineChannelPollingUrl is the URL which the Droplet will poll for alerts whenever the application is offline (more on that in the final section). The first argument, driplineChannelId, deserves special notice. If you use more than one dripline alert in a single application, it is important that each much have a unique Channel ID; you should assign it a name that's guaranteed to be both unique and human-readable. At this point you may also want to get a Channel Token via a call to the Dripline's channelToken method. A Channel Token is a string value that is placed on the client-side computer, and can be used only in conjunction with a Dripline; this allows you to place the time and date of the end-user's last application session and based on this determine in your application logic whether or not a desktop alert is appropriate. In order to get a Channel Token, make the following call immediately after registerChannel:
The first string argument should be identical to the first argument of your registerChannel call, while the second should be the exact text to be contained in the client-side token. Once the Channel Token has been created, you can pass it to the client-side in your application logic in order to determine whether a desktop alert is necessary. Consult the Droplet SDK API Reference for details.
The only remaining task is to use the Droplets API to place desktop alerts into your program logic as appropriate. The API has full details on this, and it is a fairly straightforward task. If you wish, for example, to send an icon to the client-side system tray whenever an end-user has new mail, you simply call the Dripline's alertWithIcon method and pass it the appropriate information:
One note on the second argument, alertIcon. This argument informs the Droplets Client of the icon's location. If the alertIcon string begins with "http:/", the Droplets Client treats the string as a URL address and attempts to fetch the icon there; otherwise, the icon is fetched from the application's imagejar.
In order to replace the static icon with the animated "New Mail" icon, you now create an event listener (or other polling mechanism) to listen on the database for new email messages; and a method that is called whenever that event is triggered, which should include the following line:
The arguments to this method are explained in detail in the API documents for the Dripline class. Once this step has been accomplished, you will then need to register for an event listener that waits for the end-user to read their new mail and then calls a readNewMail() method in response; within this method, you reinstate the initial, static icon by re-calling showIcon(). If your Droplets application includes alerts to the desktop that run even when the application is closed, you will also have to write a small Web page with CGI logic (ASP, Perl or the like) that will reside on your deployment's Web server (its default location is DropletConfig/apps/[application name]/dripline; full deployment details are provided in Deploying the Web server). This is necessary because there is no notion of a server session when a user is not logged in, and no information about them currently stored in the Droplets Server. The alert therefore has to use persistent data, generally from a database. Your CGI script will perform this function when the application is closed; it is defined as an argument when you first call dripline.registerChannel(). This CGI will be called by the client-side polling agent at regular intervals as determined by your program logic. Each time it is polled, it receives: AlertChannelID A string uniquely identifying a particular channel. A single Droplets application may use more than one channel for different purposes. Each channel ID needs to be unique among channel ids from a specific server. For that reason, we recommend including the application name in the ID, as well as descriptive text. For instance, "Email-NewMail". AlertChannelToken The Channel Token is a string assigned by the Droplets application and may be used for whatever purpose the developer sees fit. For instance, it could contain the user ID associated with this dripline request, or the time at which the application was last closed, so that the alert logic can distinguish between new information and old.
1. Check the Droplets UI Server's associated database, and altering its own parameters based on what it finds.
2. Return a series of plaintext name/value pairs via an HTTP Post.
Full deployment details for both the CGI script and all aspects of the Dripline can be found within Deploying the Web server.
|