?
Solved

Implenting "idle" chat status

Posted on 2011-02-22
7
Medium Priority
?
255 Views
Last Modified: 2012-05-11
Hello,

I am implementing a chat script like gmail.

I want to display user's chat status as "idle" when they are navigate away from  the tab for a long time.
Does anyone have an idea for implementing it?

Thanks and Regards
0
Comment
Question by:jacobbbc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 34953295
Are you using AJAX to make your chat app?
0
 

Author Comment

by:jacobbbc
ID: 34958428
Hi

It is an ajax+php application. I have already written an ajax function to update the user status as "idle" in database. But I am not sure about when I need to call this fuction?

Thanks and Regards
0
 
LVL 14

Expert Comment

by:EMB01
ID: 34960761
Well, without seeing your code it would be hard to write something useful, but the "idle status" function would look similar to your "check messages" function.  You would run the function when you run your checkmessages function in your JS file.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:jacobbbc
ID: 34969091
Hello,

Ok Fine.I have one more question..

How can we identify if a person leaves the browser for a long time?

Thanks and regards
0
 
LVL 14

Expert Comment

by:EMB01
ID: 34969663
Do you mean minimizes the window, closes the window, doesn't move the mouse, doesn't enter any data, or some other condition?
0
 

Author Comment

by:jacobbbc
ID: 34985845
Hello,
 
We would like to include the following conditions to recognize the idle status.

1.minimizes the window for a specific period
2.doesn't move the mouse within a time limit
3.doesn't enter any data  within a time limit.

Do you have any suggestions?

We just want to execute some functions while closing the browser. How can we identify browser close event?

Thanks and regards
0
 
LVL 14

Accepted Solution

by:
EMB01 earned 2000 total points
ID: 34987344
To check when a window is minimized:

function detectMinMax(){
      if(!isMin&&((window.screenLeft&&window.screenLeft==-32000)||(window.screenX&&window.screenX==-32000))){
            // window has just been minimized!
            isMin = true;
      } else if(isMin&&((window.screenLeft&&window.screenLeft!=-32000)||(window.screenX&&window.screenX!=-32000))){
            // window has just been unminized!
            isMin = false;
      }
}

Ref.  http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_21553336.html

To check whether or not the mouse is moved:

function doSomething(e) {
      var posx = 0;
      var posy = 0;
      if (!e) var e = window.event;
      if (e.pageX || e.pageY)       {
            posx = e.pageX;
            posy = e.pageY;
      }
      else if (e.clientX || e.clientY)       {
            posx = e.clientX + document.body.scrollLeft
                  + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop
                  + document.documentElement.scrollTop;
      }
      // posx and posy contain the mouse position relative to the document
      // Do something with this information
      
}

Ref.  http://www.quirksmode.org/js/events_properties.html

To check whether or not a key has been pressed (jQuery, since jQuery will make most, if not all, of these tasks easier):

var timeout; $('input[type=text]').keypress(function() {
     if(timeout) {
         clearTimeout(timeout);         timeout = null;    
     }      
     timeout = setTimeout(myFunction, 5000)
})

Ref.  http://stackoverflow.com/questions/693849/call-a-javascript-function-after-5-sec-of-last-key-press

To do something before the browser is closed (also, using jQuery):

$(window).unload( function () {
     jQuery.get("someurl")
} );

Ref.  http://stackoverflow.com/questions/653976/call-url-before-closing-of-browser-window

I can't really help you with every single item since there are so many, so it's probably best to open up another question if you need help with these individually.  Thanks for understanding, I hope this is what you're looking for.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question