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) {
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) {
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');
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?
37 this.origin = location.pathname;
39 window.xulG._sound = this;
43 dump('error in util.sound constructor: ' + E + '\n');
48 util.sound.prototype = {
50 'xp_url_init' : function (aURL) {
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);
61 alert('xp_url_init(): ' + E);
65 'play_url' : function(url) {
67 if (!url) { return; /* sound of silence */ }
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') {
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 );
83 dump('SOUND('+obj.sig+'): playing file = ' + url + '\n');
84 obj.SOUND.play( url2 );
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');
91 dump('play_url(): ' + E + '\n');
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] );
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] );
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] );
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] );
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] );
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] );
132 dump('exiting util/sound.js\n');