Detect Connection Speed and Redirect

This can come in handy if you've made different copies of streaming media files, and want to direct the user to the right copy automatically based on bandwidth.  You could plug this into an asx file and just change the values to the .wma files
This script will detect connection speed and redirect to a page:
low.html if transfer rate less than 80kbps
medium.html if rate is between 81 and 600kbps
high.html if rate is over 600kbps

Do not use the code below! It's just for reference and doesn't have the 35K of binary data.  Get it Here.
Click Here to go to the actual redirect page
Click Here for the main script that also detects activex plugins and will set cookies - Get it Here


<html><head>
<script language = "JavaScript">
// Remove down to "ConnectionSpeed Detection section" if you don't want to use cookies
// If you drop a cookie it can be picked up on return by php or something else
function setCookie(name, value, expire ){
document.cookie = name + "=" + escape(value) + ((expire==null ?
"":(";expires=" + expire.toGMTString())));
// alert('A cookie called '+name+' is now set with value: '+value); //enable to alert user of cookie
}
function getExpireDate(){
var expires = new Date();
expires.setTime((new Date().getTime() + 1000*60*60*24*365));
return expires;
}
// ConnectionSpeed Detection section
var datasize=31468; // Size of data being transferred, in Bytes
var startTime=0;
var endTime=0;
var date=0;
var ctype="";
var textMessage="";
function calcThroughput() {
var diffTimeMilliseconds = endTime - startTime;
var diffTimeSeconds = diffTimeMilliseconds/1000;
var bits = (datasize*8);    // convert Bytes to bits,
var kbits = bits/1024;    // convert bits to kbits
var throughput = kbits/(diffTimeSeconds*100/100);
throughput = throughput * .93; // account for IP packet header overhead - averages about 7%
setCookie("MediaThroughput", throughput, getExpireDate()); // Remove to not use cookie
if (throughput < 600){ctype="medium.html";}
if (throughput < 560){ctype="low.html";}
if (throughput > 600){ctype="high.html";}
textMessage = "Bandwidth: <B>" + ctype + "</B><br>time to load: (sec): <B>" + diffTimeSeconds + "</B><BR>kbits loaded:<B> " + kbits + "</B><BR>Throughput (kbps): <B>" + throughput +"</B>"
document.location = ctype;
}
</script>
<script language = "Javascript">
<!--
A bunch of binary data here in the actual file
-->
</script>
</head><body>
<script language = "Javascript">
date = new Date();
endTime=date.getTime();
calcThroughput();
</script>
</body></html>


Back