diff options
author | Stephen Leavitt <stephen.leavitt@gmail.com> | 2010-08-22 02:40:02 +0000 |
---|---|---|
committer | Stephen Leavitt <stephen.leavitt@gmail.com> | 2010-08-22 02:40:02 +0000 |
commit | a14b46e634877959a1e18e3a5dedef36b9c8a925 (patch) | |
tree | 616008da7024c3d93415dbde77211f4f3423d140 /web_socket.js | |
parent | 3340f4242a6beefb39effaffaf7cae2785d5cb0b (diff) | |
download | web-socket-js-a14b46e634877959a1e18e3a5dedef36b9c8a925.tar.gz |
Better handling of Flash Lite and Flash on Android devices by distinguishing between Flash and Flash Lite prior to loading the web-socket-js SWF.
Diffstat (limited to 'web_socket.js')
-rw-r--r--[-rwxr-xr-x] | web_socket.js | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/web_socket.js b/web_socket.js index 3d07a09..67479f6 100755..100644 --- a/web_socket.js +++ b/web_socket.js @@ -294,6 +294,32 @@ WebSocket.__tasks = []; WebSocket.__initialize = function() { + var getBrowserInfo = function() { + var bInfo = { + platform: '', + plugins: {} + }; + if (window.navigator) { + if (window.navigator.userAgent) { + var userAgent = window.navigator.userAgent; + if (userAgent.match(/Android/i)) bInfo.platform = 'android'; + } + if (window.navigator.plugins) { + var plugins = window.navigator.plugins, plugin = undefined; + for (var i = 0, j = plugins.length; i < j; i++) { + plugin = plugins.item(i); + if (plugin.name) { + if (plugin.name.match(/Shockwave Flash/i)) { + bInfo.plugins.flash = true; + // If there's a better way to detect Flash Lite before loading a SWF, I'd like to know. + if (plugin.filename && plugin.filename.match(/flashlite/i)) bInfo.plugins.flash_lite = true; + } + } + } + } + } + return bInfo; + }; if (WebSocket.__swfLocation) { // For backword compatibility. window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation; @@ -304,18 +330,40 @@ } var container = document.createElement("div"); container.id = "webSocketContainer"; - // Puts the Flash out of the window. Note that we cannot use display: none or visibility: hidden - // here because it prevents Flash from loading at least in IE. container.style.position = "absolute"; - container.style.left = "-100px"; - container.style.top = "-100px"; + var browserInfo = getBrowserInfo(); + var left = '', top = '', height = '', width = ''; + // Attempt to handle Flash Lite differently + if (browserInfo.plugins.flash_lite) { + // Define and handle different platforms using Flash Lite as necessary. + switch (browserInfo.platform) { + case 'android': + default: + // Handle Flash Lite slightly differently. + // Plugin must be visible to run, so make it as small as possible. + left = "0px"; + top = "0px"; + height = "1"; + width = "1"; + break; + } + } else { + // Puts the Flash out of the window. Note that we cannot use display: none or visibility: hidden + // here because it prevents Flash from loading at least in IE. + left = "-100px"; + top = "-100px"; + height = "8"; + width = "8"; + } + container.style.left = left; + container.style.top = top; var holder = document.createElement("div"); holder.id = "webSocketFlash"; container.appendChild(holder); document.body.appendChild(container); swfobject.embedSWF( - WEB_SOCKET_SWF_LOCATION, "webSocketFlash", "8", "8", "9.0.0", - null, {bridgeName: "webSocket"}, null, null, + WEB_SOCKET_SWF_LOCATION, "webSocketFlash", width, height, "9.0.0", + null, {bridgeName: "webSocket"}, {hasPriority: true}, null, function(e) { if (!e.success) console.error("[WebSocket] swfobject.embedSWF failed"); } |