Page 1 of 1

Make browser blink when there is a new chat message

PostPosted: Fri Jan 13, 2012 5:57 pm
by rmelino
Hi,

Love subsonic--one suggestion...

When chatting, make the browser icon blink when there is a new chat message. It is difficult to carry on a chat while doing other things on your computer because you never know when someone has posted a new message without going to the actual webpage to check

Re: Make browser blink when there is a new chat message

PostPosted: Sun Jan 15, 2012 3:58 am
by ytechie
Here is how to make the browser title blink when a new chat message arrives:

We are going to edit right.jsp. Here is the part that we are going to edit:

Code: Select all
<c:if test="${model.showChat}">
    <script type="text/javascript">

        var revision = 0;
       
        startGetMessagesTimer();

        function startGetMessagesTimer() {
            chatService.getMessages(revision, getMessagesCallback);
            setTimeout("startGetMessagesTimer()", 10000);
        }

        function addMessage() {
            chatService.addMessage($("message").value);
            dwr.util.setValue("message", null);
            setTimeout("startGetMessagesTimer()", 500);
        }
       
       
        function getMessagesCallback(messages) {

            if (messages == null) {
                return;
            }
           
            revision = messages.revision;

            // Delete all the rows except for the "pattern" row
            dwr.util.removeAllRows("chatlog", { filter:function(div) {
                return (div.id != "pattern");
            }});

We are going to add a function, and change an existing function.

First, add this function:

Code: Select all
function blinkTitle() {
   if (blink && msgLength > 0) {
      top.document.title = "New Message!";
      setTimeout("top.document.title = 'Subsonic'",1500);
      setTimeout("blinkTitle()",3000);
   }
}

Next, we need to edit the function getMessagesCallback(). Add these variables right after "var revision = 0;" like this:

Code: Select all
<c:if test="${model.showChat}">
    <script type="text/javascript">

        var revision = 0;
        var revision2 = 0;
        var blink = 0;
        var msgLength = 0;
       
        startGetMessagesTimer();

Now add "msgLength = messages.messages.length;" one line after "function getMessagesCallback(messages) {".

Now, we are going to add this code:
Code: Select all
if (revision2 != revision) {
   revision2 = revision;
   if (messages.messages.length > 0 && !blink) {
      blink = 1;
      blinkTitle();
   } else {
     blink = 0;
   }
   var frames = top.window.frames;
   for (var i = 0; i < 5; i++) {
         frames[i].addEventListener('focus', function() {
           top.right.blink = 0;
           top.document.title = 'Subsonic';
   }); }
}

right after this code:

Code: Select all
function getMessagesCallback(messages) {

   msgLength = messages.messages.length;

      if (messages == null) {
         return;
      }

Also, we have to add "revision2=revision" to the textbox so that it looks like this:

Code: Select all
<input class="text" id="message" value="<fmt:message key="main.message"/>" style="width:90%" onclick="select()" onkeypress="dwr.util.onReturn(event, addMessage); revision2=revision;"/>

Some things may be a little weird because we are working with focusing 5 frames. Sometimes you just have to click in any frame (besides for the right frame sometimes :? ) to get the blinking to stop.

Hope this helps! :D

Re: Make browser blink when there is a new chat message

PostPosted: Fri Apr 20, 2012 9:25 am
by viktorz
Is this code on php or java?
астигматизм69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69o69oк444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444к444
radeon 6990

Re: Make browser blink when there is a new chat message

PostPosted: Fri Apr 20, 2012 1:53 pm
by ytechie
This is all javascript. It's neither php nor java.