]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/chrome/content/util/sound.js
change the params for sound constructor and add debug info
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / util / sound.js
1 dump('entering util/sound.js\n');
2
3 if (typeof util == 'undefined') util = {};
4 util.sound = function (params) {
5
6     try {
7
8         if (!params) { params = {}; }
9
10         this.sig = (new Date()).getMinutes() + ':' + (new Date()).getSeconds() + '.' + (new Date()).getMilliseconds()/1000;
11         if (params.sig) { this.sig += ' ' + params.sig; }
12
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) { 
16             dump('SOUND('+this.sig+'): reusing sound from ' + window.xulG._sound.origin + '('+xulG._sound.sig+') for ' + location.pathname + '\n');
17             return window.xulG._sound; 
18         } else {
19             dump('SOUND('+this.sig+'): instantiating new sound for ' + location.pathname + '\n');
20         }
21
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) {
25             this._queue = true;
26             this._funcs = params.queue || [];
27             JSAN.use('util.exec'); this._exec = new util.exec(); var intervalId = this._exec.timer( this._funcs, params.interval );
28             dump('SOUND('+this.sig+'): starting timer with intervalId = ' + intervalId + '\n');
29         }
30
31         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
32         var SOUNDContractID = "@mozilla.org/sound;1";
33         var SOUNDIID        = Components.interfaces.nsISound;
34         this.SOUND          = Components.classes[SOUNDContractID].createInstance(SOUNDIID);
35         this.SOUND.init(); // not necessary, but helps avoid delays?
36
37         this.origin = location.pathname;
38
39         window.xulG._sound = this;
40         return this;
41
42     } catch(E) {
43         dump('error in util.sound constructor: ' + E + '\n');
44         return this;
45     }
46 };
47
48 util.sound.prototype = {
49
50     'xp_url_init' : function (aURL) {
51         try {
52             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
53             var URLContractID   = "@mozilla.org/network/standard-url;1";
54             var URLIID          = Components.classes[URLContractID].createInstance( );
55             var URL             = URLIID.QueryInterface(Components.interfaces.nsIURL);
56             if (aURL) {
57                 URL.spec = aURL;
58             }
59             return URL;
60         } catch(E) {
61             alert('xp_url_init(): ' + E);
62         }
63     },
64
65     'play_url' : function(url) {
66
67         if (!url) { return; /* sound of silence */ }
68
69         var obj = this;
70         try {
71             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
72             JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
73             var url2 = obj.xp_url_init( data.server + url );
74             if (typeof data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') {
75
76                 if (obj._queue) {
77                     dump('SOUND('+obj.sig+'): queueing file = ' + url + '\n');
78                     obj._funcs.push( function() { 
79                         dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
80                         obj.SOUND.play( url2 ); 
81                     } );
82                 } else {
83                     dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
84                     obj.SOUND.play( url2 );
85                 }
86             }
87         } catch(E) {
88             try { if (data.no_sound == 'undefined' || data.no_sound == false || data.no_sound == 'false') obj.SOUND.beep(); } catch(F) { 
89                 dump('beep(): ' + F + '\n');
90             }
91             dump('play_url(): ' + E + '\n');
92         }
93     },
94
95     'event' : function event(evt) {
96         var key = 'AUDIO_' + arguments.callee.name + '_' + evt.textcode;
97         dump('SOUND('+this.sig+'): key = ' + key + '\n');
98         this.play_url( urls[key] );
99     },
100
101     'good' : function good(e){
102         var key = 'AUDIO_' + arguments.callee.name;
103         dump('SOUND('+this.sig+'): key = ' + key + '\n');
104         this.play_url( urls[key] );
105     },
106
107     'bad' : function bad(e){
108         var key = 'AUDIO_' + arguments.callee.name;
109         dump('SOUND('+this.sig+'): key = ' + key + '\n');
110         this.play_url( urls[key] );
111     },
112
113     'horrible' : function horrible(e){
114         var key = 'AUDIO_' + arguments.callee.name;
115         dump('SOUND('+this.sig+'): key = ' + key + '\n');
116         this.play_url( urls[key] );
117     },
118
119     'circ_good' : function circ_good(e){
120         var key = 'AUDIO_' + arguments.callee.name;
121         dump('SOUND('+this.sig+'): key = ' + key + '\n');
122         this.play_url( urls[key] );
123     },
124
125     'circ_bad' : function circ_bad(e){
126         var key = 'AUDIO_' + arguments.callee.name;
127         dump('SOUND('+this.sig+'): key = ' + key + '\n');
128         this.play_url( urls[key] );
129     }
130 }
131
132 dump('exiting util/sound.js\n');