summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Nicolcev <frugen@gmail.com>2016-04-30 19:42:53 -0400
committerPhilip Nicolcev <frugen@gmail.com>2016-04-30 19:42:53 -0400
commit04bda5d8566480217978a1c8388d72e1db3e0fa6 (patch)
tree177558a18c33b79b7194dbaf43d37c0b2da6763e
parent1e3d92b1d414fc418734ffa50748525e8c959a1a (diff)
parent1d15e34d05058f102bd70211e4a59900f46e2932 (diff)
downloadAJAX-Chat-04bda5d8566480217978a1c8388d72e1db3e0fa6.zip
AJAX-Chat-04bda5d8566480217978a1c8388d72e1db3e0fa6.tar.gz
AJAX-Chat-04bda5d8566480217978a1c8388d72e1db3e0fa6.tar.bz2
Merge branch 'html5audio' of https://github.com/jamrial/AJAX-Chat into jamrial-html5audio
Conflicts: chat/js/chat.js chat/lib/template/loggedIn.html
-rw-r--r--chat/js/chat.js123
-rw-r--r--chat/js/config.js4
-rw-r--r--chat/lib/template/loggedIn.html16
-rw-r--r--chat/sounds/sound_1.oggbin0 -> 14591 bytes
-rw-r--r--chat/sounds/sound_1.wavbin0 -> 244270 bytes
-rw-r--r--chat/sounds/sound_2.oggbin0 -> 17965 bytes
-rw-r--r--chat/sounds/sound_2.wavbin0 -> 221230 bytes
-rw-r--r--chat/sounds/sound_3.oggbin0 -> 37569 bytes
-rw-r--r--chat/sounds/sound_3.wavbin0 -> 373294 bytes
-rw-r--r--chat/sounds/sound_4.oggbin0 -> 40321 bytes
-rw-r--r--chat/sounds/sound_4.wavbin0 -> 576046 bytes
-rw-r--r--chat/sounds/sound_5.oggbin0 -> 28273 bytes
-rw-r--r--chat/sounds/sound_5.wavbin0 -> 364078 bytes
-rw-r--r--chat/sounds/sound_6.oggbin0 -> 6732 bytes
-rw-r--r--chat/sounds/sound_6.wavbin0 -> 46126 bytes
15 files changed, 109 insertions, 34 deletions
diff --git a/chat/js/chat.js b/chat/js/chat.js
index 7b79f14..aa73a85 100644
--- a/chat/js/chat.js
+++ b/chat/js/chat.js
@@ -91,8 +91,9 @@ var ajaxChat = {
DOMbufferRowClass: null,
inUrlBBCode: null,
debug: null,
-
- init: function(config, lang, initSettings, initStyle, initialize, initializeFunction, finalizeFunction) {
+ flashSounds: null,
+
+ init: function(config, lang, initSettings, initStyle, initialize, initializeFunction, finalizeFunction) {
this.httpRequest = {};
this.usersList = [];
this.userNamesList = [];
@@ -103,6 +104,7 @@ var ajaxChat = {
this.requestStatus = 'ok';
this.DOMbufferRowClass = 'rowOdd';
this.inUrlBBCode = false;
+ this.flashSounds = true;
this.initConfig(config);
this.initDirectories();
if(initSettings) {
@@ -305,7 +307,7 @@ var ajaxChat = {
if(this.dom['inputField'] && this.settings['autoFocus']) {
this.dom['inputField'].focus();
}
- this.loadFlashInterface();
+ this.loadAudioInterface();
this.startChatUpdate();
},
@@ -435,8 +437,21 @@ var ajaxChat = {
this.makeRequest(requestUrl,'GET',null);
},
- loadFlashInterface: function() {
- if(this.dom['flashInterfaceContainer']) {
+ loadAudioInterface: function() {
+ if(this.settings['audioBackend'] < 0) {
+ 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'];
+
+ if(this.flashSounds) {
this.updateDOM(
'flashInterfaceContainer',
'<object id="ajaxChatFlashInterface" style="position:absolute; left:-100px;" '
@@ -454,6 +469,8 @@ var ajaxChat = {
+'</object>'
);
FABridge.addInitializationCallback('ajaxChat', this.flashInterfaceLoadCompleteHandler);
+ } else {
+ this.loadSounds();
}
},
@@ -600,32 +617,63 @@ var ajaxChat = {
volume = 1.0;
}
this.settings['audioVolume'] = volume;
- try {
- if(!this.soundTransform) {
- this.soundTransform = FABridge.ajaxChat.create('flash.media.SoundTransform');
+ if(this.flashSounds) {
+ try {
+ if(!this.soundTransform) {
+ this.soundTransform = FABridge.ajaxChat.create('flash.media.SoundTransform');
+ }
+ this.soundTransform.setVolume(volume);
+ } catch(e) {
+ this.debugMessage('setAudioVolume', e);
+ }
+ } else {
+ try {
+ for(var key in this.soundFiles) {
+ this.sounds[key].volume = volume;
+ }
+ } catch(e) {
+ this.debugMessage('setAudioVolume', e);
}
- this.soundTransform.setVolume(volume);
- } 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);
+ if(this.flashSounds) {
+ try {
+ this.setAudioVolume(this.settings['audioVolume']);
+ this.sounds = new Object();
+ 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);
+ }
+ } else {
+ try {
+ var audio = document.createElement('audio');
+ var mp3 = !!(audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, ''));
+ var ogg = !!(audio.canPlayType && audio.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, ''));
+ this.sounds = new Array();
+ 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('loadSounds', e);
}
- } catch(e) {
- this.debugMessage('loadSounds', e);
}
},
@@ -652,14 +700,23 @@ var ajaxChat = {
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;
@@ -3021,4 +3078,4 @@ var ajaxChat = {
}
}
-}; \ No newline at end of file
+};
diff --git a/chat/js/config.js b/chat/js/config.js
index 3a57189..7b2b43f 100644
--- a/chat/js/config.js
+++ b/chat/js/config.js
@@ -85,6 +85,8 @@ var ajaxChatConfig = {
// Defines if sounds are played:
audio: true,
+ // Defines the audio backend:
+ audioBackend: -1,
// Defines the sound volume (0.0 = mute, 1.0 = max):
audioVolume: 1.0,
@@ -253,4 +255,4 @@ var ajaxChatConfig = {
// Debug allows console logging or alerts on caught errors - false/0 = no debug, true/1/2 = console log, 2 = alerts
debug: false
-}; \ No newline at end of file
+};
diff --git a/chat/lib/template/loggedIn.html b/chat/lib/template/loggedIn.html
index b7118ce..7cc7d16 100644
--- a/chat/lib/template/loggedIn.html
+++ b/chat/lib/template/loggedIn.html
@@ -149,6 +149,12 @@
document.getElementById('maxWordLengthSetting').value = ajaxChat.getSetting('maxWordLength');
document.getElementById('dateFormatSetting').value = ajaxChat.getSetting('dateFormat');
document.getElementById('persistFontColorSetting').checked = ajaxChat.getSetting('persistFontColor');
+ for(var i=0; i<document.getElementById('audioBackendSetting').options.length; i++) {
+ if(document.getElementById('audioBackendSetting').options[i].value == ajaxChat.getSetting('audioBackend')) {
+ document.getElementById('audioBackendSetting').options[i].selected = true;
+ break;
+ }
+ }
for(var i=0; i<document.getElementById('audioVolumeSetting').options.length; i++) {
if(document.getElementById('audioVolumeSetting').options[i].value == ajaxChat.getSetting('audioVolume')) {
document.getElementById('audioVolumeSetting').options[i].selected = true;
@@ -355,6 +361,16 @@
<dd><input type="checkbox" id="persistFontColorSetting" onclick="ajaxChat.setPersistFontColor(this.checked);"/></dd>
</dl>
<dl>
+ <dt><label for="audioBackendSetting">[LANG]settingsAudioVolume[/LANG]</label></dt>
+ <dd>
+ <select id="audioBackendSetting" onchange="ajaxChat.setSetting('audioBackend', this.options[this.selectedIndex].value);">
+ <option value="-1">Auto</option>
+ <option value="1">Flash</option>
+ <option value="0">HTML5</option>
+ </select>
+ </dd>
+ </dl>
+ <dl>
<dt><label for="audioVolumeSetting">[LANG]settingsAudioVolume[/LANG]</label></dt>
<dd>
<select class="left" id="audioVolumeSetting" onchange="ajaxChat.setAudioVolume(this.options[this.selectedIndex].value);">
diff --git a/chat/sounds/sound_1.ogg b/chat/sounds/sound_1.ogg
new file mode 100644
index 0000000..dac86b5
--- /dev/null
+++ b/chat/sounds/sound_1.ogg
Binary files differ
diff --git a/chat/sounds/sound_1.wav b/chat/sounds/sound_1.wav
new file mode 100644
index 0000000..a6d0f2c
--- /dev/null
+++ b/chat/sounds/sound_1.wav
Binary files differ
diff --git a/chat/sounds/sound_2.ogg b/chat/sounds/sound_2.ogg
new file mode 100644
index 0000000..39855bb
--- /dev/null
+++ b/chat/sounds/sound_2.ogg
Binary files differ
diff --git a/chat/sounds/sound_2.wav b/chat/sounds/sound_2.wav
new file mode 100644
index 0000000..e738636
--- /dev/null
+++ b/chat/sounds/sound_2.wav
Binary files differ
diff --git a/chat/sounds/sound_3.ogg b/chat/sounds/sound_3.ogg
new file mode 100644
index 0000000..488f6db
--- /dev/null
+++ b/chat/sounds/sound_3.ogg
Binary files differ
diff --git a/chat/sounds/sound_3.wav b/chat/sounds/sound_3.wav
new file mode 100644
index 0000000..bcf98ab
--- /dev/null
+++ b/chat/sounds/sound_3.wav
Binary files differ
diff --git a/chat/sounds/sound_4.ogg b/chat/sounds/sound_4.ogg
new file mode 100644
index 0000000..d6b24bd
--- /dev/null
+++ b/chat/sounds/sound_4.ogg
Binary files differ
diff --git a/chat/sounds/sound_4.wav b/chat/sounds/sound_4.wav
new file mode 100644
index 0000000..bf12af0
--- /dev/null
+++ b/chat/sounds/sound_4.wav
Binary files differ
diff --git a/chat/sounds/sound_5.ogg b/chat/sounds/sound_5.ogg
new file mode 100644
index 0000000..f11d00e
--- /dev/null
+++ b/chat/sounds/sound_5.ogg
Binary files differ
diff --git a/chat/sounds/sound_5.wav b/chat/sounds/sound_5.wav
new file mode 100644
index 0000000..8e38496
--- /dev/null
+++ b/chat/sounds/sound_5.wav
Binary files differ
diff --git a/chat/sounds/sound_6.ogg b/chat/sounds/sound_6.ogg
new file mode 100644
index 0000000..f7a4573
--- /dev/null
+++ b/chat/sounds/sound_6.ogg
Binary files differ
diff --git a/chat/sounds/sound_6.wav b/chat/sounds/sound_6.wav
new file mode 100644
index 0000000..7ade110
--- /dev/null
+++ b/chat/sounds/sound_6.wav
Binary files differ