librelist archives

« back to archive

Fwd: Requirement : Play a sound only when browser window is not in focus and a new message arrives.

Fwd: Requirement : Play a sound only when browser window is not in focus and a new message arrives.

From:
Gauri Padbidri
Date:
2015-02-10 @ 15:03
---------- Forwarded message ----------
From: Gauri Padbidri <gauri.padbidri@gmail.com>
Date: Tue, Feb 10, 2015 at 8:26 PM
Subject: Requirement : Play a sound only when browser window is not in
focus and a new message arrives.
To: conversejs@librelist.com


Hi There,

I am new to ConverseJS Development. ConverseJS initialize() will set
DEFAULT settings just once...I want to achieve the following : *Play a
sound ONLY when browser window is not in focus and a new message arrives.* Is
there an option where I can ADD attributes like *play_sounds* to *true* when
some event is triggered like we have in jQuery as follows :

$('#datePickerId').datepicker('option', 'minDate', '3');

For now my current code is as follows :

converse.listen.on('message', function (messageXML) {

            if(false === document.hasFocus()){
                console.log("Window is NOT in FOCUS");
                converse.initialize({
                    play_sounds: true
                });

            }
        });

But this is as good as setting play_sounds for all my messages...Is there a
way I can TOGGLE play sounds to ON and OFF based on Window focus...Which
API other than the initialize () helps us SET options additionally ?

Any help would be great. Thanks !

Best Regards,
Gauri Padbidri

Re: [conversejs] Fwd: Requirement : Play a sound only when browser window is not in focus and a new message arrives.

From:
Jc Brand
Date:
2015-02-11 @ 14:15
On Tue, Feb 10, 2015 at 08:33:10PM +0530, Gauri Padbidri wrote:
>    Hi There,
> 
>    I am new to ConverseJS Development.

Welcome :)

>    ConverseJS initialize() will set
>    DEFAULT settings just once...I want to achieve the following : Play a
>    sound ONLY when browser window is not in focus and a new message
>    arrives. Is there an option where I can ADD attributes
>    like play_sounds to true when some event is triggered like we have in
>    jQuery as follows :
> 
>  $('#datePickerId').datepicker('option', 'minDate', '3');
> 
>    For now my current code is as follows :
> 
>  converse.listen.on('message', function (messageXML) {
> 
>              if(false === document.hasFocus()){
>                  console.log("Window is NOT in FOCUS");
>                  converse.initialize({
>                      play_sounds: true
>                  });
> 
>              }
>          });
> 
>    But this is as good as setting play_sounds for all my messages...Is there
>    a way I can TOGGLE play sounds to ON and OFF based on Window focus...Which
>    API other than the initialize () helps us SET options additionally ?
> 
>    Any help would be great. Thanks !

Such an API option didn't exist, but I think it would be useful so I 
quickly created
it:


https://github.com/jcbrand/converse.js/commit/b31261f6fd053aa6eca2643a38e8f341b22eaa85

Regards
JC