diff options
Diffstat (limited to 'chat/js/chat.js')
-rw-r--r-- | chat/js/chat.js | 153 |
1 files changed, 88 insertions, 65 deletions
diff --git a/chat/js/chat.js b/chat/js/chat.js index 7776d3c..c24075f 100644 --- a/chat/js/chat.js +++ b/chat/js/chat.js @@ -90,21 +90,20 @@ var ajaxChat = { DOMbuffer: null, DOMbufferRowClass: null, inUrlBBCode: null, - debug: null, flashSounds: null, + debug: null, 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'; this.DOMbufferRowClass = 'rowOdd'; this.inUrlBBCode = false; - this.flashSounds = true; this.initConfig(config); this.initDirectories(); if(initSettings) { @@ -113,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(); } @@ -128,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']; @@ -147,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; @@ -203,6 +202,7 @@ var ajaxChat = { this.unusedSettings[key] = value; } else { this.settings[key] = value; + } } } @@ -264,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(); @@ -307,7 +306,14 @@ var ajaxChat = { if(this.dom['inputField'] && this.settings['autoFocus']) { this.dom['inputField'].focus(); } - this.loadAudioInterface(); + this.checkFlashSounds(); + + if (this.socketServerEnabled || this.flashSounds) { + this.loadFlashInterface(); + } else { + this.initializeHTML5Sounds(); + } + this.startChatUpdate(); }, @@ -411,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'; @@ -437,8 +442,44 @@ var ajaxChat = { this.makeRequest(requestUrl,'GET',null); }, - loadAudioInterface: function() { + loadFlashInterface: function() { + 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'); @@ -449,29 +490,7 @@ var ajaxChat = { this.flashSounds = false; } } else { - this.flashSounds = !!this.settings['audioBackend']; - } - - if(this.flashSounds) { - 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); - } else { - this.loadSounds(); + this.flashSounds = this.settings['audioBackend'] == 1; } }, @@ -484,7 +503,7 @@ var ajaxChat = { this.socketTimerRate = (this.inactiveTimeout-1)*60*1000; this.socketConnect(); } - this.loadSounds(); + this.loadFlashSounds(); this.initializeCustomFlashInterface(); }, @@ -625,7 +644,7 @@ var ajaxChat = { } this.soundTransform.setVolume(volume); } catch(e) { - this.debugMessage('setAudioVolume', e); + this.debugMessage('setAudioVolumeFlash', e); } } else { try { @@ -639,12 +658,35 @@ var ajaxChat = { } }, - loadSounds: function() { + 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 { this.setAudioVolume(this.settings['audioVolume']); - this.sounds = new Object(); - var sound,urlRequest; + this.sounds = {}; for(var key in this.soundFiles) { sound = FABridge.ajaxChat.create('flash.media.Sound'); sound.addEventListener('complete', this.soundLoadCompleteHandler); @@ -654,26 +696,7 @@ var ajaxChat = { 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); + this.debugMessage('loadFlashSounds', e); } } }, |