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 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
41 var SOUNDContractID = "@mozilla.org/sound;1";
42 var SOUNDIID = Components.interfaces.nsISound;
43 this.SOUND = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
44 this.SOUND.init(); // not necessary, but helps avoid delays?
46 this.origin = location.pathname;
48 window.xulG._sound = this;
52 dump('error in util.sound constructor: ' + E + '\n');
57 util.sound.prototype = {
59 'xp_url_init' : function (aURL) {
61 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
62 var URLContractID = "@mozilla.org/network/standard-url;1";
63 var URLIID = Components.classes[URLContractID].createInstance( );
64 var URL = URLIID.QueryInterface(Components.interfaces.nsIURL);
70 alert('xp_url_init(): ' + E);
74 'play_url' : function(url) {
76 if (!url) { return; /* sound of silence */ }
80 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
81 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
82 var url2 = obj.xp_url_init( data.server + url );
83 if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
86 dump('SOUND('+obj.sig+'): queueing file = ' + url + '\n');
87 obj._funcs.push( function() {
88 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
89 obj.SOUND.play( url2 );
92 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
93 obj.SOUND.play( url2 );
97 try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) {
98 dump('beep(): ' + F + '\n');
100 dump('play_url(): ' + E + '\n');
104 'event' : function event(evt) {
105 var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
106 dump('SOUND('+this.sig+'): key = ' + key + '\n');
107 this.play_url( urls[key] );
110 'special' : function special(e) {
111 var key = 'AUDIO_' + arguments.callee.name + '_' + e;
112 dump('SOUND('+this.sig+'): key = ' + key + '\n');
113 this.play_url( urls[key] );
116 'good' : function good(e){
117 var key = 'AUDIO_' + arguments.callee.name;
118 dump('SOUND('+this.sig+'): key = ' + key + '\n');
119 this.play_url( urls[key] );
122 'bad' : function bad(e){
123 var key = 'AUDIO_' + arguments.callee.name;
124 dump('SOUND('+this.sig+'): key = ' + key + '\n');
125 this.play_url( urls[key] );
128 'horrible' : function horrible(e){
129 var key = 'AUDIO_' + arguments.callee.name;
130 dump('SOUND('+this.sig+'): key = ' + key + '\n');
131 this.play_url( urls[key] );
134 'circ_good' : function circ_good(e){
135 var key = 'AUDIO_' + arguments.callee.name;
136 dump('SOUND('+this.sig+'): key = ' + key + '\n');
137 this.play_url( urls[key] );
140 'circ_bad' : function circ_bad(e){
141 var key = 'AUDIO_' + arguments.callee.name;
142 dump('SOUND('+this.sig+'): key = ' + key + '\n');
143 this.play_url( urls[key] );
147 dump('exiting util/sound.js\n');