Today i implemented gmail chat window , not an ajax chat with a chat server, but its client side implementation.
Here you can see the demo: http://www.sajithmr.com/gtalk/
Take this link in a new tab or window, and take any other website without closing it.
After 3 seconds , (Consider it as a new chat message arrived situation) you can see the google chat notification sound , and title changing. (I didn’t get the actual gtalk notification sound, so i used windows notify.wav file )
You know google (gmail) implemented its sound notification is via swf object. Here me too done the same.
I wrote two function to check whether the browser is in focus or not.
Here is the functions:
function lostFocus() { document.title = 'Sajith M.R Says...'; state = 'nonfocus'; played = 0 ; changeColorRed(); alterTitle(); } function gotFocus() { document.title = 'Gmail Inbox(1)'; state = 'focus'; played = 0 ; }
The alterTitle() function calls in 3 seconds setTimeOut manner.
function alterTitle() { if(state 'nonfocus') { if ( document.title 'Gmail Inbox(1)') { if(played == 0) { soundManager.play('notify'); played = 1; } document.title = 'Sajith M.R Says...'; } else document.title = 'Gmail Inbox(1)'; setTimeout("alterTitle()",3000); } }
The soundmanager.js file handles the swf flash object and sound triggering.
These three simple scripts together created this demo:http://www.sajithmr.com/gtalk/
If you want the whole source code , mail me: admin@sajithmr.com
Comment Please …
Regards
Sajith.M.R
http://www.sajith.name