diff options
author | Joel Martin <github@martintribe.org> | 2011-08-29 10:49:15 -0500 |
---|---|---|
committer | Joel Martin <github@martintribe.org> | 2011-08-29 10:49:15 -0500 |
commit | 4be643b29c1146b085e6688d4850e935a165da09 (patch) | |
tree | 23265e91f68553f07ea5c2ec31059e94bf807f57 /web_socket.js | |
parent | fa9e686e386a7a774bfd3ad50cbbb526603cd399 (diff) | |
parent | ed0622a890de811eb6d766d5c5a9a62d726f0593 (diff) | |
download | web-socket-js-4be643b29c1146b085e6688d4850e935a165da09.tar.gz |
Merge remote branch 'gimite/master' into hybi-08
Conflicts:
WebSocketMain.swf
WebSocketMainInsecure.zip
Diffstat (limited to 'web_socket.js')
-rw-r--r-- | web_socket.js | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/web_socket.js b/web_socket.js index 1cf0249..8503cc2 100644 --- a/web_socket.js +++ b/web_socket.js @@ -5,19 +5,25 @@ (function() { - if (window.WebSocket) return; - - var console = window.console; - if (!console || !console.log || !console.error) { - console = {log: function(){ }, error: function(){ }}; + if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) return; + + 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(){ }}; } - if (!swfobject.hasFlashPlayerVersion("10.0.0")) { - console.error("Flash Player >= 10.0.0 is required."); + // swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash. + if (swfobject.getFlashPlayerVersion().major < 10) { + 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://..."); @@ -222,9 +228,22 @@ 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 && + !WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) && + WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) { + var swfHost = RegExp.$1; + if (location.host != swfHost) { + 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 " + + "in README.md. If you use WebSocketMainInsecure.swf, you can suppress this message " + + "by WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;"); + } + } var container = document.createElement("div"); container.id = "webSocketContainer"; // Hides Flash box. We cannot use display: none or visibility: hidden because it prevents @@ -258,7 +277,7 @@ null, function(e) { if (!e.success) { - console.error("[WebSocket] swfobject.embedSWF failed"); + logger.error("[WebSocket] swfobject.embedSWF failed"); } }); }; @@ -295,7 +314,7 @@ WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]); } } catch (e) { - console.error(e); + logger.error(e); } }, 0); return true; @@ -303,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) { |