What are some working options for handling server and browser events?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What are some working options for handling server and browser events?

spierepf
I am looking for a grails plugin that is being actively developed and that works for handing events. I've tried:

https://github.com/smaldini/grails-events-push

but I cannot get an event generated by the client to be recognized on the server:

https://github.com/smaldini/grails-events-push/issues/56
http://stackoverflow.com/questions/21707061/how-do-i-send-an-event-from-the-browser-to-the-server-using-grails

I've also looked at:

https://bitbucket.org/bgoetzmann/grails-atmosphere-plugin

but there doesn't appear to be any active development.

What plugin should I be looking at?

Peter.
Reply | Threaded
Open this post in threaded view
|

Re: What are some working options for handling server and browser events?

longwa
Events-push version 1.0.M7 works, but the latest snapshot (using Reactor) does not seem to work for us.

I do remember the configuration being a bit tricky, but we (did) have a working event-push implementation that we used for Notifications, Progress Bars, etc. on the client side. It's actually quite nice. I haven't been able to get it working in Grails 2.3. If you are using 2.2, you should still be good.

I know Stephane is working on a release version for events-push in the near future, I'm hoping that will clear things up.

TLDR; events-push is what you want, just needs a little TLC right now.

-Aaron


On Wed, Feb 12, 2014 at 8:44 PM, spierepf <[hidden email]> wrote:
I am looking for a grails plugin that is being actively developed and that
works for handing events. I've tried:

https://github.com/smaldini/grails-events-push

but I cannot get an event generated by the client to be recognized on the
server:

https://github.com/smaldini/grails-events-push/issues/56
http://stackoverflow.com/questions/21707061/how-do-i-send-an-event-from-the-browser-to-the-server-using-grails

I've also looked at:

https://bitbucket.org/bgoetzmann/grails-atmosphere-plugin

but there doesn't appear to be any active development.

What plugin should I be looking at?

Peter.



--
View this message in context: http://grails.1312388.n4.nabble.com/What-are-some-working-options-for-handling-server-and-browser-events-tp4654068.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: What are some working options for handling server and browser events?

Ken Siprell
You can try my plugin (http://www.grails.org/plugins/atmosphere-meteor, https://github.com/kensiprell/grails-atmosphere-meteor) for the Atmosphere framework although it doesn't implement an events bus. It looks like a simple Jabber server implementation; however, it's easily extended on the backend. It works with Grails 2.3.5, Tomcat 7.0.50, and Jetty 8. You can get a general idea of how it works by cloning and running the sample app (https://github.com/kensiprell/grails-atmosphere-meteor-sample). I originally started out using only jQuery on the client side in a private app and quickly ended up in callback hell. I've spent the past several weeks learning Angularjs and converting my private app, and it is much easier.

Imagine a page with traditional chat input and output elements, an element that lists notifications from the backend, an element that lists your friends, and a few elements for advertising. You login (Spring Security) and start a start a chat session with an online friend.

First off, doing backend to backend and backend to client is trivial although you'll have to roll your own code for handling the responses on the client. Using notifications from the scenario above, I have a Notification domain class, a NotificationController, a NotificationService, and a NotificationHandler that extends HttpServlet. The client uses an angular controller, NotificationCtrl, that subscribes to "/atmosphere/notification/joeblow" (assuming your User.username == "joeblow") that handles the JavaScript onMessage events from Atmosphere. For example, a friend of yours logs in and the backend sends the friend's online status, which can be sent from basically anywhere (controller, service, src, etc.):
def data = [
    type: "FRIEND_PRESENCE",
    username: Friend.username,
    online: true
]
Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class, "/atmosphere/notification/joeblow")
broadcaster.broadcast(data as JSON)

NotificationCtrl on the client receives the onMessage event and reacts to the data.type value doing:
$rootScope.$broadcast('FRIEND_PRESENCE', {
    username: message.username,
    online: message.online
});


We have a listener in the Angularjs FriendCtrl controller that updates the model, for example changing the friend's status icon and enabling the "click to start a chat session" button:
$scope.$on('FRIEND_PRESENCE', function (event, message) {
    var index = utils.getArrayIndex($scope.friends, 'username', message.username);
    $scope.friends[index]['online'] = message.online;
    $scope.$apply();
});

Second, client to server is just as easy although once again you'll have to roll your own code.

Click a button (https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L39) that triggers a subscribe call (https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L200).

Click an "event" button (https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L40) that triggers the "event" on the backend (https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L210).

Handle the "event" on the backend (https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/controllers/org/grails/plugins/atmosphere_meteor_sample/AtmosphereTestController.groovy#L14).

It's not as elegant as Stephane's plugin, but it works for me. I plan on githubbing a sample app with Angularjs as soon as I have time, which should eliminate the explaining I've done here.

I hope I haven't overwhelmed you.

Ken
Reply | Threaded
Open this post in threaded view
|

Re: What are some working options for handling server and browser events?

smaldini
Ken option is awesome, and much more dedicated than me - My issue is I have really hard schedule these days by working on Reactor and especially the coming 1.1 features and I still have consulting stuff to deliver. I try to look after people with whom I could sync with on the latest reactor features to implement in the plugin the grails way.


On Fri, Feb 14, 2014 at 8:32 AM, Ken Siprell <[hidden email]> wrote:
You can try my plugin (http://www.grails.org/plugins/atmosphere-meteor,
https://github.com/kensiprell/grails-atmosphere-meteor) for the Atmosphere
framework although it doesn't implement an events bus. It looks like a
simple Jabber server implementation; however, it's easily extended on the
backend. It works with Grails 2.3.5, Tomcat 7.0.50, and Jetty 8. You can get
a general idea of how it works by cloning and running the sample app
(https://github.com/kensiprell/grails-atmosphere-meteor-sample). I
originally started out using only jQuery on the client side in a private app
and quickly ended up in callback hell. I've spent the past several weeks
learning Angularjs and converting my private app, and it is much easier.

Imagine a page with traditional chat input and output elements, an element
that lists notifications from the backend, an element that lists your
friends, and a few elements for advertising. You login (Spring Security) and
start a start a chat session with an online friend.

First off, doing backend to backend and backend to client is trivial
although you'll have to roll your own code for handling the responses on the
client. Using notifications from the scenario above, I have a Notification
domain class, a NotificationController, a NotificationService, and a
NotificationHandler that extends HttpServlet. The client uses an angular
controller, NotificationCtrl, that subscribes to
"/atmosphere/notification/joeblow" (assuming your User.username ==
"joeblow") that handles the JavaScript onMessage events from Atmosphere. For
example, a friend of yours logs in and the backend sends the friend's online
status, which can be sent from basically anywhere (controller, service, src,
etc.):
def data = [
    type: "FRIEND_PRESENCE",
    username: Friend.username,
    online: true
]
Broadcaster broadcaster =
BroadcasterFactory.getDefault().lookup(DefaultBroadcaster.class,
"/atmosphere/notification/joeblow")
broadcaster.broadcast(data as JSON)

NotificationCtrl on the client receives the onMessage event and reacts to
the data.type value doing:
$rootScope.$broadcast('FRIEND_PRESENCE', {
    username: message.username,
    online: message.online
});


We have a listener in the Angularjs FriendCtrl controller that updates the
model, for example changing the friend's status icon and enabling the "click
to start a chat session" button:
$scope.$on('FRIEND_PRESENCE', function (event, message) {
    var index = utils.getArrayIndex($scope.friends, 'username',
message.username);
    $scope.friends[index]['online'] = message.online;
    $scope.$apply();
});

Second, client to server is just as easy although once again you'll have to
roll your own code.

Click a button
(https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L39)
that triggers a subscribe call
(https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L200).

Click an "event" button
(https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L40)
that triggers the "event" on the backend
(https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/views/atmosphereTest/index.gsp#L210).

Handle the "event" on the backend
(https://github.com/kensiprell/grails-atmosphere-meteor-sample/blob/master/grails-app/controllers/org/grails/plugins/atmosphere_meteor_sample/AtmosphereTestController.groovy#L14).

It's not as elegant as Stephane's plugin, but it works for me. I plan on
githubbing a sample app with Angularjs as soon as I have time, which should
eliminate the explaining I've done here.

I hope I haven't overwhelmed you.

Ken




--
View this message in context: http://grails.1312388.n4.nabble.com/What-are-some-working-options-for-handling-server-and-browser-events-tp4654068p4654114.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email





--
Stéphane
--