Make browser blink when there is a new chat message

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Make browser blink when there is a new chat message

Postby rmelino » Fri Jan 13, 2012 5:57 pm

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
rmelino
 
Posts: 1
Joined: Fri Jan 13, 2012 5:55 pm

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

Postby ytechie » Sun Jan 15, 2012 3:58 am

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
User avatar
ytechie
 
Posts: 547
Joined: Sun Dec 12, 2010 5:05 am
Location: Manhattan, New York

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

Postby viktorz » Fri Apr 20, 2012 9:25 am

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
Last edited by viktorz on Sat Mar 03, 2018 5:14 am, edited 3 times in total.
viktorz
 
Posts: 1
Joined: Fri Apr 20, 2012 9:24 am

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

Postby ytechie » Fri Apr 20, 2012 1:53 pm

This is all javascript. It's neither php nor java.
User avatar
ytechie
 
Posts: 547
Joined: Sun Dec 12, 2010 5:05 am
Location: Manhattan, New York


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 14 guests