diff options
author | Hiroshi Ichikawa <gimite@gmail.com> | 2011-08-07 13:58:00 +0900 |
---|---|---|
committer | Hiroshi Ichikawa <gimite@gmail.com> | 2011-08-07 13:58:00 +0900 |
commit | b6501bec56bbc52c3dc20ac0dcbf3d734dd741ce (patch) | |
tree | 7c7f21fada98ec245e0b789d7ca80c83a105f1c7 | |
parent | a71f371861dc0c19002ae7ecf8ce6dd60bc5f259 (diff) | |
parent | 8cb0574ce8dc693e5f142ab4de147c58844cea5b (diff) | |
download | web-socket-js-b6501bec56bbc52c3dc20ac0dcbf3d734dd741ce.tar.gz |
Merging, renaming WebSocketLogger to WEB_SOCKET_LOGGER and making window.console as default logger.
-rw-r--r-- | web_socket.js | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/web_socket.js b/web_socket.js index 8507468..7c18745 100644 --- a/web_socket.js +++ b/web_socket.js @@ -4,21 +4,26 @@ // Reference: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol (function() { - + if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) return; - - var console = window.console; - if (!console || !console.log || !console.error) { - console = {log: function(){ }, error: function(){ }}; + + var logger; + if (window.WEB_SOCKET_LOGGER) { + logger = WEB_SOCKET_LOGGER; + } else if (window.console && window.console.log && window.console.error) { + // In some environment, console is defined but console.log or console.error is missing. + logger = window.console; + } else { + logger = {log: function(){ }, error: function(){ }}; } // swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash. if (!swfobject.getFlashPlayerVersion().major >= 10) { - console.error("Flash Player >= 10.0.0 is required."); + logger.error("Flash Player >= 10.0.0 is required."); return; } if (location.protocol == "file:") { - console.error( + logger.error( "WARNING: web-socket-js doesn't work in file:///... URL " + "unless you set Flash Security Settings properly. " + "Open the page via Web server i.e. http://..."); @@ -223,7 +228,7 @@ window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation; } if (!window.WEB_SOCKET_SWF_LOCATION) { - console.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf"); + logger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf"); return; } if (!window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR && @@ -231,7 +236,7 @@ WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) { var swfHost = RegExp.$1; if (location.host != swfHost) { - console.error( + logger.error( "[WebSocket] You must host HTML and WebSocketMain.swf in the same host " + "('" + location.host + "' != '" + swfHost + "'). " + "See also 'How to host HTML file and SWF file in different domains' section " + @@ -272,7 +277,7 @@ null, function(e) { if (!e.success) { - console.error("[WebSocket] swfobject.embedSWF failed"); + logger.error("[WebSocket] swfobject.embedSWF failed"); } }); }; @@ -309,7 +314,7 @@ WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]); } } catch (e) { - console.error(e); + logger.error(e); } }, 0); return true; @@ -317,12 +322,12 @@ // Called by Flash. WebSocket.__log = function(message) { - console.log(decodeURIComponent(message)); + logger.log(decodeURIComponent(message)); }; // Called by Flash. WebSocket.__error = function(message) { - console.error(decodeURIComponent(message)); + logger.error(decodeURIComponent(message)); }; WebSocket.__addTask = function(task) { |