@@ -388,9 +388,6 @@ def get_detection_html(user_agent)
388
388
<%= js_misc_addons_detect %>
389
389
<%= js_ie_addons_detect if os.match(OperatingSystems::Match::WINDOWS) and client == HttpClients::IE %>
390
390
391
- var flash_version = "";
392
- var do_flash_loop = true;
393
-
394
391
function objToQuery(obj) {
395
392
var q = [];
396
393
for (var key in obj) {
@@ -410,11 +407,19 @@ def get_detection_html(user_agent)
410
407
});
411
408
}
412
409
410
+ var flashVersion = "";
411
+ var doFlashLoop = true;
412
+ var maxTimeout = null;
413
+
413
414
function setFlashVersion(ver) {
414
415
console.log('called! :) ' + ver)
415
- flash_version = ver
416
- do_flash_loop = false
417
- console.log('flash version after set_version: ' + flash_version)
416
+ flashVersion = ver
417
+ doFlashLoop = false
418
+ if (maxTimeout != null) {
419
+ clearTimeout(maxTimeout);
420
+ maxTimeout = null
421
+ }
422
+ console.log('flash version after set_version: ' + flashVersion)
418
423
return;
419
424
}
420
425
@@ -483,23 +488,25 @@ def get_detection_html(user_agent)
483
488
<% end %>
484
489
485
490
if (d["flash"] != null && (d["flash"].match(/[\\ d]+.[\\ d]+.[\\ d]+.[\\ d]+/)) == null) {
486
- alert('flash detection!')
487
- // Load SWF for accurate Flash detection
488
- // This SWF needs to send the Flash version info as a POST request to BES sort of like this:
491
+ alert('flash detection!');
489
492
var flashObject = createFlashObject('<%=get_resource.chomp("/")%>/<%=@flash_swf%>', {width: 1, height: 1}, {allowScriptAccess: 'always', Play: 'True'});
490
493
494
+ // After 5s stop waiting and use the version retrieved with JS
495
+ maxTimeout = setTimeout(function(){ doFlashLoop = false }, 5000);
496
+
497
+ // Check every 100 ms
491
498
(function loop(){
492
- console.log('loop: ' + flash_version )
499
+ console.log('loop: ' + flashVersion )
493
500
setTimeout(function(){
494
- if (do_flash_loop ) {
501
+ if (doFlashLoop ) {
495
502
loop()
496
503
}
497
- console.log('finally: ' + flash_version )
498
- if (!isEmpty(flash_version )) {
499
- d["flash"] = flash_version
504
+ console.log('finally: ' + flashVersion )
505
+ if (!isEmpty(flashVersion )) {
506
+ d["flash"] = flashVersion
500
507
}
501
508
sendInfo(d)
502
- }, 1000 );
509
+ }, 100 );
503
510
})();
504
511
505
512
document.body.appendChild(flashObject)
@@ -573,7 +580,7 @@ def on_request_uri(cli, request)
573
580
vprint_status ( "Sending SWF used for Flash detection" )
574
581
swf = load_swf_detection
575
582
send_response ( cli , swf , { 'Content-Type' => 'application/x-shockwave-flash' , 'Cache-Control' => 'no-cache, no-store' , 'Pragma' => 'no-cache' } )
576
-
583
+
577
584
when /#{ @info_receiver_page } /
578
585
#
579
586
# The detection code will hit this if Javascript is enabled
0 commit comments