diff options
author | Philip Nicolcev <frugen@gmail.com> | 2016-05-01 13:44:31 -0400 |
---|---|---|
committer | Philip Nicolcev <frugen@gmail.com> | 2016-05-01 13:44:31 -0400 |
commit | 270decf52425bc78f96e28b968715b47430615a8 (patch) | |
tree | 01755f60081fb83058bb61db134348000c7a9e8e | |
parent | 1e3d92b1d414fc418734ffa50748525e8c959a1a (diff) | |
parent | 6ff277ff3f553ed64a9d9d4f0728b5ba145ab419 (diff) | |
download | AJAX-Chat-270decf52425bc78f96e28b968715b47430615a8.zip AJAX-Chat-270decf52425bc78f96e28b968715b47430615a8.tar.gz AJAX-Chat-270decf52425bc78f96e28b968715b47430615a8.tar.bz2 |
Merge branch 'jamrial-html5audio'
-rw-r--r-- | chat/changelog.txt | 3 | ||||
-rw-r--r-- | chat/js/chat.js | 203 | ||||
-rw-r--r-- | chat/js/config.js | 4 | ||||
-rw-r--r-- | chat/lib/template/loggedIn.html | 16 | ||||
-rw-r--r-- | chat/sounds/sound_1.ogg | bin | 0 -> 14591 bytes | |||
-rw-r--r-- | chat/sounds/sound_1.wav | bin | 0 -> 244270 bytes | |||
-rw-r--r-- | chat/sounds/sound_2.ogg | bin | 0 -> 17965 bytes | |||
-rw-r--r-- | chat/sounds/sound_2.wav | bin | 0 -> 221230 bytes | |||
-rw-r--r-- | chat/sounds/sound_3.ogg | bin | 0 -> 37569 bytes | |||
-rw-r--r-- | chat/sounds/sound_3.wav | bin | 0 -> 373294 bytes | |||
-rw-r--r-- | chat/sounds/sound_4.ogg | bin | 0 -> 40321 bytes | |||
-rw-r--r-- | chat/sounds/sound_4.wav | bin | 0 -> 576046 bytes | |||
-rw-r--r-- | chat/sounds/sound_5.ogg | bin | 0 -> 28273 bytes | |||
-rw-r--r-- | chat/sounds/sound_5.wav | bin | 0 -> 364078 bytes | |||
-rw-r--r-- | chat/sounds/sound_6.ogg | bin | 0 -> 6732 bytes | |||
-rw-r--r-- | chat/sounds/sound_6.wav | bin | 0 -> 46126 bytes |
16 files changed, 164 insertions, 62 deletions
diff --git a/chat/changelog.txt b/chat/changelog.txt index 714f705..cde0e76 100644 --- a/chat/changelog.txt +++ b/chat/changelog.txt @@ -873,6 +873,9 @@ Misc: Version 0.8.9 (??.??.2016) ------------------------------- +New Features: +- Added HTML5 audio support. - thanks to Jamrial. + Bugfixes: - French translation typo fixed. - thanks to Excale. diff --git a/chat/js/chat.js b/chat/js/chat.js index 7b79f14..c24075f 100644 --- a/chat/js/chat.js +++ b/chat/js/chat.js @@ -90,14 +90,15 @@ var ajaxChat = { DOMbuffer: null, DOMbufferRowClass: null, inUrlBBCode: null, + flashSounds: null, debug: null, - - init: function(config, lang, initSettings, initStyle, initialize, initializeFunction, finalizeFunction) { + + init: function(config, lang, initSettings, initStyle, initialize, initializeFunction, finalizeFunction) { this.httpRequest = {}; this.usersList = []; this.userNamesList = []; this.userMenuCounter = 0; - this.lastID = 0; + this.lastID = 0; this.localID = 0; this.lang = lang; this.requestStatus = 'ok'; @@ -111,8 +112,8 @@ var ajaxChat = { if(initStyle) { this.initStyle(); } - this.initializeFunction = initializeFunction; - this.finalizeFunction = finalizeFunction; + this.initializeFunction = initializeFunction; + this.finalizeFunction = finalizeFunction; if(initialize) { this.setLoadHandler(); } @@ -126,17 +127,17 @@ var ajaxChat = { this.baseURL = config['baseURL']; this.regExpMediaUrl = config['regExpMediaUrl']; this.startChatOnLoad = config['startChatOnLoad']; - this.domIDs = config['domIDs']; + this.domIDs = config['domIDs']; this.settings = config['settings']; this.nonPersistentSettings = config['nonPersistentSettings']; - this.bbCodeTags = config['bbCodeTags']; - this.colorCodes = config['colorCodes']; + this.bbCodeTags = config['bbCodeTags']; + this.colorCodes = config['colorCodes']; this.emoticonCodes = config['emoticonCodes']; this.emoticonFiles = config['emoticonFiles']; - this.soundFiles = config['soundFiles']; + this.soundFiles = config['soundFiles']; this.sessionName = config['sessionName']; this.cookieExpiration = config['cookieExpiration']; - this.cookiePath = config['cookiePath']; + this.cookiePath = config['cookiePath']; this.cookieDomain = config['cookieDomain']; this.cookieSecure = config['cookieSecure']; this.chatBotName = config['chatBotName']; @@ -145,13 +146,13 @@ var ajaxChat = { this.inactiveTimeout = Math.max(config['inactiveTimeout'],2); this.privateChannelDiff = config['privateChannelDiff']; this.privateMessageDiff = config['privateMessageDiff']; - this.showChannelMessages = config['showChannelMessages']; + this.showChannelMessages = config['showChannelMessages']; this.messageTextMaxLength = config['messageTextMaxLength']; - this.socketServerEnabled = config['socketServerEnabled']; + this.socketServerEnabled = config['socketServerEnabled']; this.socketServerHost = config['socketServerHost']; this.socketServerPort = config['socketServerPort']; this.socketServerChatID = config['socketServerChatID']; - this.debug = config['debug']; + this.debug = config['debug']; this.DOMbuffering = false; this.DOMbuffer = ""; this.retryTimerDelay = (this.inactiveTimeout*6000 - this.timerRate)/4 + this.timerRate; @@ -201,6 +202,7 @@ var ajaxChat = { this.unusedSettings[key] = value; } else { this.settings[key] = value; + } } } @@ -262,7 +264,6 @@ var ajaxChat = { this.initializeSettings(); this.setSelectedStyle(); this.customInitialize(); - // preload the Alert icon (it can't display if there's no connection unless it's cached!) this.setStatus('retrying'); if(typeof this.initializeFunction === 'function') { this.initializeFunction(); @@ -305,7 +306,14 @@ var ajaxChat = { 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(); }, @@ -409,7 +417,6 @@ var ajaxChat = { } }, - startChatUpdate: function() { // Start the chat update and retrieve current user and channel info and set the login channel: var infos = 'userID,userName,userRole,channelID,channelName'; @@ -436,24 +443,54 @@ var ajaxChat = { }, 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 - +'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' - +'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 - +'//www.macromedia.com/go/getflashplayer" ' - +'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 + +'//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' + +'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 + +'//www.macromedia.com/go/getflashplayer" ' + +'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 +503,7 @@ var ajaxChat = { this.socketTimerRate = (this.inactiveTimeout-1)*60*1000; this.socketConnect(); } - this.loadSounds(); + this.loadFlashSounds(); this.initializeCustomFlashInterface(); }, @@ -600,32 +637,67 @@ 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('setAudioVolumeFlash', 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() { + initializeHTML5Sounds: function() { + var audio, mo3, ogg; try { - this.setAudioVolume(this.settings['audioVolume']); - this.sounds = {}; - var sound,urlRequest; + 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) { - 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); + this.sounds[key] = new Audio(this.dirs['sounds']+key+format); } + this.setAudioVolume(this.settings['audioVolume']); } catch(e) { - this.debugMessage('loadSounds', e); + this.debugMessage('initializeHTML5Sounds', e); + } + }, + + loadFlashSounds: function() { + var sound, urlRequest; + if(this.flashSounds) { + try { + 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('loadFlashSounds', e); + } } }, @@ -652,14 +724,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 +3102,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..6ed113c 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.setAudioBackend(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 Binary files differnew file mode 100644 index 0000000..dac86b5 --- /dev/null +++ b/chat/sounds/sound_1.ogg diff --git a/chat/sounds/sound_1.wav b/chat/sounds/sound_1.wav Binary files differnew file mode 100644 index 0000000..a6d0f2c --- /dev/null +++ b/chat/sounds/sound_1.wav diff --git a/chat/sounds/sound_2.ogg b/chat/sounds/sound_2.ogg Binary files differnew file mode 100644 index 0000000..39855bb --- /dev/null +++ b/chat/sounds/sound_2.ogg diff --git a/chat/sounds/sound_2.wav b/chat/sounds/sound_2.wav Binary files differnew file mode 100644 index 0000000..e738636 --- /dev/null +++ b/chat/sounds/sound_2.wav diff --git a/chat/sounds/sound_3.ogg b/chat/sounds/sound_3.ogg Binary files differnew file mode 100644 index 0000000..488f6db --- /dev/null +++ b/chat/sounds/sound_3.ogg diff --git a/chat/sounds/sound_3.wav b/chat/sounds/sound_3.wav Binary files differnew file mode 100644 index 0000000..bcf98ab --- /dev/null +++ b/chat/sounds/sound_3.wav diff --git a/chat/sounds/sound_4.ogg b/chat/sounds/sound_4.ogg Binary files differnew file mode 100644 index 0000000..d6b24bd --- /dev/null +++ b/chat/sounds/sound_4.ogg diff --git a/chat/sounds/sound_4.wav b/chat/sounds/sound_4.wav Binary files differnew file mode 100644 index 0000000..bf12af0 --- /dev/null +++ b/chat/sounds/sound_4.wav diff --git a/chat/sounds/sound_5.ogg b/chat/sounds/sound_5.ogg Binary files differnew file mode 100644 index 0000000..f11d00e --- /dev/null +++ b/chat/sounds/sound_5.ogg diff --git a/chat/sounds/sound_5.wav b/chat/sounds/sound_5.wav Binary files differnew file mode 100644 index 0000000..8e38496 --- /dev/null +++ b/chat/sounds/sound_5.wav diff --git a/chat/sounds/sound_6.ogg b/chat/sounds/sound_6.ogg Binary files differnew file mode 100644 index 0000000..f7a4573 --- /dev/null +++ b/chat/sounds/sound_6.ogg diff --git a/chat/sounds/sound_6.wav b/chat/sounds/sound_6.wav Binary files differnew file mode 100644 index 0000000..7ade110 --- /dev/null +++ b/chat/sounds/sound_6.wav |