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'); this._exec = new util.exec(); var intervalId = this._exec.timer( this._funcs, params.interval || 500 );
32 dump('SOUND('+this.sig+'): starting timer with intervalId = ' + intervalId + '\n');
35 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
36 var SOUNDContractID = "@mozilla.org/sound;1";
37 var SOUNDIID = Components.interfaces.nsISound;
38 this.SOUND = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
39 this.SOUND.init(); // not necessary, but helps avoid delays?
41 this.origin = location.pathname;
43 window.xulG._sound = this;
47 dump('error in util.sound constructor: ' + E + '\n');
52 util.sound.prototype = {
54 'xp_url_init' : function (aURL) {
56 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
57 var URLContractID = "@mozilla.org/network/standard-url;1";
58 var URLIID = Components.classes[URLContractID].createInstance( );
59 var URL = URLIID.QueryInterface(Components.interfaces.nsIURL);
65 alert('xp_url_init(): ' + E);
69 'play_url' : function(url) {
71 if (!url) { return; /* sound of silence */ }
75 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
76 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
77 var url2 = obj.xp_url_init( data.server + url );
78 if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
81 dump('SOUND('+obj.sig+'): queueing file = ' + url + '\n');
82 obj._funcs.push( function() {
83 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
84 obj.SOUND.play( url2 );
87 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
88 obj.SOUND.play( url2 );
92 try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) {
93 dump('beep(): ' + F + '\n');
95 dump('play_url(): ' + E + '\n');
99 'event' : function event(evt) {
100 var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
101 dump('SOUND('+this.sig+'): key = ' + key + '\n');
102 this.play_url( urls[key] );
105 'good' : function good(e){
106 var key = 'AUDIO_' + arguments.callee.name;
107 dump('SOUND('+this.sig+'): key = ' + key + '\n');
108 this.play_url( urls[key] );
111 'bad' : function bad(e){
112 var key = 'AUDIO_' + arguments.callee.name;
113 dump('SOUND('+this.sig+'): key = ' + key + '\n');
114 this.play_url( urls[key] );
117 'horrible' : function horrible(e){
118 var key = 'AUDIO_' + arguments.callee.name;
119 dump('SOUND('+this.sig+'): key = ' + key + '\n');
120 this.play_url( urls[key] );
123 'circ_good' : function circ_good(e){
124 var key = 'AUDIO_' + arguments.callee.name;
125 dump('SOUND('+this.sig+'): key = ' + key + '\n');
126 this.play_url( urls[key] );
129 'circ_bad' : function circ_bad(e){
130 var key = 'AUDIO_' + arguments.callee.name;
131 dump('SOUND('+this.sig+'): key = ' + key + '\n');
132 this.play_url( urls[key] );
136 dump('exiting util/sound.js\n');