This chat system is not for the faint of heart. There is no official support at this time and it is something that you
have to tinker with. With all of this said, make sure that you have mp3 versions of the sounds available. These are the changes I found from the default code downloaded and what I have running. This currently works for me. If there are other changes that you've done since the default, that I can't help with as I don't know what you may or may not have done.
So, here's the basic changes in a patch format version ( negative sign means remove and plus sign means add)
--- AJAX-Chat-0.8.8-phpbb3.1/chat/js/chat.js
+++ Modified/chat/js/chat.js
@@ -90,6 +90,7 @@
DOMbuffer: null,
DOMbufferRowClass: null,
inUrlBBCode: null,
+ flashSounds: null,
debug: null,
init: function(config, lang, initSettings, initStyle, initialize, initializeFunction, finalizeFunction) {
@@ -97,7 +98,7 @@
this.usersList = [];
this.userNamesList = [];
this.userMenuCounter = 0;
- this.lastID = 0;
+ this.lastID = 0;
this.localID = 0;
this.lang = lang;
this.requestStatus = 'ok';
@@ -305,7 +306,14 @@
if(this.dom['inputField'] && this.settings['autoFocus']) {
this.dom['inputField'].focus();
}
- this.loadFlashInterface();
+ this.checkFlashSounds();
+
+ if (this.socketServerEnabled || this.flashSounds) {
+ this.loadFlashInterface();
+ } else {
+ this.initializeHTML5Sounds();
+ }
+
this.startChatUpdate();
},
@@ -436,24 +444,54 @@
},
loadFlashInterface: function() {
- if(this.dom['flashInterfaceContainer']) {
- this.updateDOM(
- 'flashInterfaceContainer',
- '<object id="ajaxChatFlashInterface" style="position:absolute; left:-100px;" '
- +'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
- +'codebase="'
- + window.location.protocol
- +'height="1" width="1">'
- +'<param name="flashvars" value="bridgeName=ajaxChat"/>'
- +'<param name="src" value="'+this.dirs['flash']+'FABridge.swf"/>'
- +'<embed name="ajaxChatFlashInterface" type="application/x-shockwave-flash" pluginspage="'
- + window.location.protocol
- +'src="'+this.dirs['flash']+'FABridge.swf" height="1" width="1" flashvars="bridgeName=ajaxChat"/>'
- +'</object>'
- );
- FABridge.addInitializationCallback('ajaxChat', this.flashInterfaceLoadCompleteHandler);
+ if(!this.dom['flashInterfaceContainer'] || this.dom['flashInterfaceContainer'].flashLoaded) {
+ return;
+ }
+
+ this.updateDOM(
+ 'flashInterfaceContainer',
+ '<object id="ajaxChatFlashInterface" style="position:absolute; left:-100px;" '
+ +'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '
+ +'codebase="'
+ + window.location.protocol
+ +'height="1" width="1">'
+ +'<param name="flashvars" value="bridgeName=ajaxChat"/>'
+ +'<param name="src" value="'+this.dirs['flash']+'FABridge.swf"/>'
+ +'<embed name="ajaxChatFlashInterface" type="application/x-shockwave-flash" pluginspage="'
+ + window.location.protocol
+ +'src="'+this.dirs['flash']+'FABridge.swf" height="1" width="1" flashvars="bridgeName=ajaxChat"/>'
+ +'</object>'
+ );
+ FABridge.addInitializationCallback('ajaxChat', this.flashInterfaceLoadCompleteHandler);
+ this.dom['flashInterfaceContainer'].flashLoaded = true;
+ },
+
+ setAudioBackend: function(audioBackend) {
+ this.setSetting('audioBackend', audioBackend);
+ this.checkFlashSounds();
+ if(this.flashSounds) {
+ this.loadFlashInterface();
+ } else {
+ this.initializeHTML5Sounds();
+ }
+ },
+
+ checkFlashSounds: function() {
+ if(this.settings['audioBackend'] < 0) {
+ // autodetect if flash is supported, and default to flash.
+ if(navigator.appVersion.indexOf("MSIE") != -1) {
+ try {
+ flash = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
+ } catch(e) {
+ this.flashSounds = false;
+ }
+ } else if((navigator.plugins && !navigator.plugins["Shockwave Flash"]) || (navigator.mimeTypes && !navigator.mimeTypes['application/x-shockwave-flash'])) {
+ this.flashSounds = false;
+ }
+ } else {
+ this.flashSounds = this.settings['audioBackend'] == 1;
}
},
@@ -466,7 +504,7 @@
this.socketTimerRate = (this.inactiveTimeout-1)*60*1000;
this.socketConnect();
}
- this.loadSounds();
+ this.loadFlashSounds();
this.initializeCustomFlashInterface();
},
@@ -600,32 +638,67 @@
volume = 1.0;
}
this.settings['audioVolume'] = volume;
+ if(this.flashSounds) {
+ try {
+ if(!this.soundTransform) {
+ this.soundTransform = FABridge.ajaxChat.create('flash.media.SoundTransform');
+ }
+ this.soundTransform.setVolume(volume);
+ } catch(e) {
+ this.debugMessage('setAudioVolumeFlash', e);
+ }
+ } else {
+ try {
+ for(var key in this.soundFiles) {
+ this.sounds[key].volume = volume;
+ }
+ } catch(e) {
+ this.debugMessage('setAudioVolume', e);
+ }
+ }
+ }
+ },
+
+ initializeHTML5Sounds: function() {
+ var audio, mo3, ogg;
+ try {
+ audio = document.createElement('audio');
+ mp3 = !!(audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, ''));
+ ogg = !!(audio.canPlayType && audio.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, ''));
+ this.sounds = [];
+ if(mp3) {
+ format = ".mp3";
+ } else if(ogg) {
+ format = ".ogg";
+ } else {
+ format = ".wav";
+ }
+ for(var key in this.soundFiles) {
+ this.sounds[key] = new Audio(this.dirs['sounds']+key+format);
+ }
+ this.setAudioVolume(this.settings['audioVolume']);
+ } catch(e) {
+ this.debugMessage('initializeHTML5Sounds', e);
+ }
+ },
+
+ loadFlashSounds: function() {
+ var sound, urlRequest;
+ if(this.flashSounds) {
try {
- if(!this.soundTransform) {
- this.soundTransform = FABridge.ajaxChat.create('flash.media.SoundTransform');
- }
- this.soundTransform.setVolume(volume);
+ this.setAudioVolume(this.settings['audioVolume']);
+ this.sounds = {};
+ for(var key in this.soundFiles) {
+ sound = FABridge.ajaxChat.create('flash.media.Sound');
+ sound.addEventListener('complete', this.soundLoadCompleteHandler);
+ sound.addEventListener('ioError', this.soundIOErrorHandler);
+ urlRequest = FABridge.ajaxChat.create('flash.net.URLRequest');
+ urlRequest.setUrl(this.dirs['sounds']+this.soundFiles[key]);
+ sound.load(urlRequest);
+ }
} catch(e) {
- this.debugMessage('setAudioVolume', e);
- }
- }
- },
-
- loadSounds: function() {
- try {
- this.setAudioVolume(this.settings['audioVolume']);
- this.sounds = {};
- var sound,urlRequest;
- for(var key in this.soundFiles) {
- sound = FABridge.ajaxChat.create('flash.media.Sound');
- sound.addEventListener('complete', this.soundLoadCompleteHandler);
- sound.addEventListener('ioError', this.soundIOErrorHandler);
- urlRequest = FABridge.ajaxChat.create('flash.net.URLRequest');
- urlRequest.setUrl(this.dirs['sounds']+this.soundFiles[key]);
- sound.load(urlRequest);
- }
- } catch(e) {
- this.debugMessage('loadSounds', e);
+ this.debugMessage('loadFlashSounds', e);
+ }
}
},
@@ -652,14 +725,23 @@
playSound: function(soundID) {
if(this.sounds && this.sounds[soundID]) {
- try {
- // play() parameters are
- // startTime:Number (default = 0),
- // loops:int (default = 0) and
- // sndTransform:SoundTransform (default = null)
- return this.sounds[soundID].play(0, 0, this.soundTransform);
- } catch(e) {
- this.debugMessage('playSound', e);
+ if(this.flashSounds) {
+ try {
+ // play() parameters are
+ // startTime:Number (default = 0),
+ // loops:int (default = 0) and
+ // sndTransform:SoundTransform (default = null)
+ return this.sounds[soundID].play(0, 0, this.soundTransform);
+ } catch(e) {
+ this.debugMessage('playSound', e);
+ }
+ } else {
+ try {
+ this.sounds[soundID].currentTime = 0;
+ return this.sounds[soundID].play();
+ } catch(e) {
+ this.debugMessage('playSound', e);
+ }
}
}
return null;