How To Resume Atmosphere Connection When User Cancel Closing Browser Window - gwt

Our application is using atmosphere as the comet implementation,we want to implement the functionality that user can choose to stay within the site after browser window is closing by prompting the user "Are you sure" dialogbox .
To be specific, the problem originate from the fact that when user is trying to close browser window, when the confirm dialogbox is showing, the disconnect event is fired to atmosphere server no matter what user is going to choose.
We are using atmosphere for GWT, and we tried using the resumeOnBroadcast on resource option ,but with no luck.
And we also tried to intercept the closing event before it fired, also failed.
So can somebody help, thx a lot.

Take a look at the onClose(AtmosphereResponse) request handler.
var socket = $.atmosphere;
var request = new $.atmosphere.AtmosphereRequest();
request.onClose(response){
//handle the close here
}
var subSocket = socket.subscribe(request);
subSocket.push(data);
This is documented here. This is on the client side.

Related

Connecting to Strophe.js in Angular 6

I have connected to Strophe.js by placing the Strophe.js files in assets and Connection is successful. But after connecting to it, UI is getting hanged. Can any one please help
what means hanged? Strophe.js does't block the process.
i remeber connect like this(not exact code):
var callback = function(condition){
// according to condition decide if connected or not
// and if connected, UI: form login panel to main panel(include friends list and so on)
}
Strophe.connection(jid, password, callback);
and there is no reason UI hanged. you may use broswer debug tool to follow your code and find out where it hanged

How can I clear a UISession?

From this link I saw that For every instance of a RAP UI, a separate UISession is created. That means that when a user accesses an entry point, that’s a new UISession. When the user reloads the page in the browser, that’s also a new UISession.
And in my application when the browser is refreshed (usually by hitting F5 or close browser and open again) and from MAT (Memory Analyzer Tool) report I see that something call UISessionImpl is created as much as the time browser refreshed. That means new UISession is created but the old sessions is still there.
So my question is "How can I clear session every time the browser refresh?".
EDIT
My code:
RWT.getUISession(myDisplay).exec(new Runnable() {
#Override
public void run() {
RWT.getRequest().getSession().setMaxInactiveInterval(1);
}
});
Have a look at this link:
https://wiki.eclipse.org/RAP/FAQ#How_do_I_get_notified_when_the_browser_window.2Ftab_is_closed.3F
"In most recent browsers, the UI session is automatically destroyed when the client's browser window/tab is closed. For older browsers, the HTTP session timeout is used to detect whether the user has left the application."
"Note that when using the RAP launcher, by default a HTTP session never expires. To change the timeout value, adjust the setting on the "Main" tab."
The link you refere to writes about RAP 2.0, maybe you need to update to the latest version 2.3.
You can reduce session timeout value like this:
RWT.getRequest().getSession().setMaxInactiveInterval(...);
To clear the session on refresh, maybe you can do:
RWT.getRequest().getSession().setMaxInactiveInterval(0);

Real time model events in Sails.js 0.10-rc5

I've been playing around with building some realtime functionality using Sails.js version 0.10-rc5 (currently the #beta release).
To accomplish anything, i've been following the sweet SailsCast tutorial on this subject (sailsCast link)
It talks about subscribing to a model via a 'subscribe' action within the model's controller. Then listening to it at the client side, waiting for the server to emit messages. Quite straightforward, although I do not seem to receive any messages.
I'm trying to do this to get real-time updates on anything that changes in my User models, or if new ones get created.. So I can display login status etc. in real time. Pretty much exactly the stuff that's explained in the sailsCast.
In my terminal i'll get two things worth noticing, of which the first is the following:
debug: Deprecated: `Model.subscribe(socket, null, ...)`
debug: See http://links.sailsjs.org/docs/config/pubsub
debug: (⌘ + double-click to open link from terminal)
debug: Please use instance rooms instead (or raw sails.sockets.*() methods.)
It seems like the 'subscribe' method has been deprecated. Could anybody tell me if that's correct, and tell me how to fix this? I've been checking out the reference to the documentation in the debug message, although it just points me to the global documentation page. I've been searching for an answer elsewhere, but haven't found anything useful.
The second message I'm getting is:
warn: You are trying to render a view (_session/new), but Sails doesn't support rendering views over Socket.io... yet!
You might consider serving your HTML view normally, then fetching data with sockets in your client-side JavaScript.
If you didn't intend to serve a view here, you might look into content-negotiation
to handle AJAX/socket requests explictly, instead of `res.redirect()`/`res.view()`.
Now, i'm quite sure this is because I have an 'isAuthenticated' policy added to all of my controllers and actions. When a user is not authenticated, it'll redirect to a session/new page. Somebody must log in to be able to use the application. When I remove the 'isAuthenticated' policy from the 'subscribed' action, the warnings disappear. Although that means anyone will get updates via sockets (when I get it to work), even when they're logged out. - I don't really feel like people just sitting at the login screen, fishing out the real time messages which are intended only for users who are logged in.
Can anyone help me getting the real time updates to work? I'd really appreciate!
As far as the socket messages not being received, the issue is that you're following a tutorial for v0.9.x, but you're using a beta version of Sails in which PubSub has gone through some changes. That's covered in this answer about the "create" events not being received.
Your second issue isn't about sockets at all; you'll just need to reconsider your architecture a bit. If you want to to use socket requests to sign users in, then you'll have to be more careful about redirecting them because, as the message states, you can't render a view over a socket. Technically you could send a bunch of HTML back to the client over a socket, and replace your current page with it, but that's not very good practice. What you can do instead is, in your isAuthenticated policy, check whether the request is happening via sockets (using req.isSocket) and if so, send back a message that the front end can interpret to mean, "you should redirect to the login page now". Something like:
module.exports = function (req, res, next) {
if ([your auth logic here]) {
return next();
}
else {
if (req.isSocket) {
return res.json({status: 403, redirectTo: "/session/new"});
} else {
return res.redirect("/session/new");
}
}
}

grails+spring-security-facebook listen to login success event

im a newbie both in spring security and spring-security-facebook and in an app that we are building we have to couple them.Everything is working well i will need to know the way to listen to the facebook login success event. is there some one that already did a stuff that impose him to catch the facebook event success?? I need that because in the begining of the app (before adding the spring -security-Facebook plugin ); we have a special behaviour attached to the "grails.plugins.springsecurity.onInteractiveAuthenticationSuccessEvent" event (configured in the config.groovy file) and we have to execute the same special behaviour when the user connect with facebook account. Is there an event (extending springsecurity kinds of events) that we have to listen to?
any idea ??
Ps: when searching for solution we found a way to catch the FB js Events and work around to reach what we want as result but we would as possible to want to not go that way ....
The problem with it that current Spring Security Facebook authenticates user on each request (by listening to FB cookie, transparently), so you'll get this event on each request. Probably it's not what you want, right? It the same as having a filter on each request.
Btw, you can handle situation when user login into your app first time, but implementing onCreate(user, token) or afterCreate(user, token) in service FacebookAuthService (you have to create such service at this case)
Example:
File grails-app/services/FacebookAuthService.groovy:
class FacebookAuthService {
void afterCreate(def user, def token) {
log.info("New user!") //or any code there
}
}

Opening an email client on clicking a button

I am designing an app in which i need open an email client on clicking a button. The email client should be opened with pre defined subject,'to' address and from address of the user. Is there a way to attain this??? Plz provide me the solution and code if possible...
If you want to open the existing BlackBerry messages application use the Invoke class with the appropriate MessageArguments e.g.
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(MessageArguments.ARG_NEW, <to address>, <subject>, <body>);
I don't know of a way to change the from address.