Solved

Implenting "idle" chat status

Posted on 2011-02-22
7
245 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
  • 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
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.…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now