1 dump('entering util/sound.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.sound = function (params) {
8 if (!params) { params = {}; }
10 this.sig = (new Date()).getMinutes() + ':' + (new Date()).getSeconds() + '.' + (new Date()).getMilliseconds()/1000;
11 if (params.sig) { this.sig += ' ' + params.sig; }
13 /* We're going to turn this guy into a singleton, at least for a given window, and look for it in xulG */
14 if (! window.xulG) { window.xulG = {}; }
15 if (window.xulG._sound && !params.reuse_queue_from_this_snd_obj) {
16 dump('SOUND('+this.sig+'): reusing sound from ' + window.xulG._sound.origin + '('+xulG._sound.sig+') for ' + location.pathname + '\n');
17 return window.xulG._sound;
19 dump('SOUND('+this.sig+'): instantiating new sound for ' + location.pathname + '\n');
22 /* So we can queue up sounds and put a pause between them instead of having them trample over each other */
23 /* Limitation: interval only gets set once for a singleton */
24 if (params.interval || params.reuse_queue_from_this_snd_obj) {
26 if (params.reuse_queue_from_this_snd_obj) {
27 this._funcs = params.reuse_queue_from_this_snd_obj._funcs || [];
31 JSAN.use('util.exec');
32 this._exec = new util.exec();
33 var delay = params.interval;
34 if (!delay) { delay = _sound_delay_interval; /* define this in server/skin/custom.js */ }
35 if (!delay) { delay = 2000; }
36 var intervalId = this._exec.timer( this._funcs, delay );
37 dump('SOUND('+this.sig+'): starting timer with intervalId = ' + intervalId + '\n');
40 var SOUNDContractID = "@mozilla.org/sound;1";
41 var SOUNDIID = Components.interfaces.nsISound;
42 this.SOUND = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
43 this.SOUND.init(); // not necessary, but helps avoid delays?
45 this.origin = location.pathname;
47 window.xulG._sound = this;
51 dump('error in util.sound constructor: ' + E + '\n');
56 util.sound.prototype = {
58 'xp_url_init' : function (aURL) {
60 var URLContractID = "@mozilla.org/network/standard-url;1";
61 var URLIID = Components.classes[URLContractID].createInstance( );
62 var URL = URLIID.QueryInterface(Components.interfaces.nsIURL);
68 alert('xp_url_init(): ' + E);
72 'play_url' : function(url) {
74 if (!url) { return; /* sound of silence */ }
78 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
79 var url2 = obj.xp_url_init( data.server + url );
80 if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
83 dump('SOUND('+obj.sig+'): queueing file = ' + url + '\n');
84 obj._funcs.push( function() {
85 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
86 obj.SOUND.play( url2 );
89 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
90 obj.SOUND.play( url2 );
94 try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) {
95 dump('beep(): ' + F + '\n');
97 dump('play_url(): ' + E + '\n');
101 'event' : function event(evt) {
102 var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
103 dump('SOUND('+this.sig+'): key = ' + key + '\n');
104 this.play_url( urls[key] );
107 'special' : function special(e) {
108 var key = 'AUDIO_' + arguments.callee.name + '_' + e;
109 dump('SOUND('+this.sig+'): key = ' + key + '\n');
110 this.play_url( urls[key] );
113 'good' : function good(e){
114 var key = 'AUDIO_' + arguments.callee.name;
115 dump('SOUND('+this.sig+'): key = ' + key + '\n');
116 this.play_url( urls[key] );
119 'bad' : function bad(e){
120 var key = 'AUDIO_' + arguments.callee.name;
121 dump('SOUND('+this.sig+'): key = ' + key + '\n');
122 this.play_url( urls[key] );
125 'horrible' : function horrible(e){
126 var key = 'AUDIO_' + arguments.callee.name;
127 dump('SOUND('+this.sig+'): key = ' + key + '\n');
128 this.play_url( urls[key] );
131 'circ_good' : function circ_good(e){
132 var key = 'AUDIO_' + arguments.callee.name;
133 dump('SOUND('+this.sig+'): key = ' + key + '\n');
134 this.play_url( urls[key] );
137 'circ_bad' : function circ_bad(e){
138 var key = 'AUDIO_' + arguments.callee.name;
139 dump('SOUND('+this.sig+'): key = ' + key + '\n');
140 this.play_url( urls[key] );
144 dump('exiting util/sound.js\n');