So i always wanted some real-time way of letting my users know what’s up. Coming from the request-cycle world, this means a lot of queueing and storing and retrieving. Just for clarification, this is also again a Beginner Howto for using Liftweb’s amazing Comet capabilities.
To get started, simply start integrating Gritter into your project. It’s a jQuery Growl-Style notification plugin which has nice visuals. Kudos to jboesch!
Anyway, once you’ve got the .js and .css included, let’s start by adding the NotificationMessage:
This simply gives you the opportunity to call .toJsCmd to make it render with all the options provided.
Here is the NotificationCenter:
This is pretty straight forward. It sends out notifications it received from various backend-actors to all registered clients.
The receiving CometActor is dispatching, if the Message has a customer assigned (Long), and if the User this CometActor belongs to is a Member of the provided Customer-ID, then it will be shown. If no Customer-ID is supplied, it will be shown on all clients. So you have some kind of Broadcast-Feature. This also means, that your User-Model needs some sort of “customer”-Field, but feel free to adapt! :)
To implement it, simply use something like this:
(The Users.isLoggedIn is something of mine, so ignore it if you don’t have something similar.)
Now we need some way to send messages, since we don’t have an Actor messaging us yet, so i’ve created a little snippet:
and a form:
which should help you get started.
If you’re lucky and everything works right, you should see something like this:
So i hope this helps some of you newbies out there get started!