1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
function cConnexion() {
this.ImgTest = null;
this.TxtSrc = "/externe/img/test_connexion.png";
this.nbOctetImg = 147456;
this.DelaiMax = 10000;
this.TimerDebut = 0;
this.TimerFin = 0;
this.debit = 0;
this.niveau = -1;
this.mTest = function () {
this.ImgTest = new Image();
this.TimerDebut = new Date();
this.ImgTest.src = this.TxtSrc + "?dummy=" + this.TimerDebut;
this.TimerDebut = this.TimerDebut.getTime();
this.mVerif();
}
this.mVerif = function () {
this.TimerFin = new Date();
this.TimerFin = this.TimerFin.getTime();
if (this.ImgTest.complete) {
this.debit = this.nbOctetImg / (this.TimerFin - this.TimerDebut);
if (this.debit > 0 && this.debit <= 6) this.niveau = 2;
if (this.debit > 6 && this.debit <= 20) this.niveau = 3;
if (this.debit > 20 && this.debit <= 500) this.niveau = 4;
if (this.debit > 500) this.niveau = 5;
}
else {
if (this.TimerFin - this.TimerDebut > this.DelaiMax) {
//fin
this.niveau = 1;
}
else {
var Me = this;
window.setTimeout(function () { Me.mVerif(); }, 20);
}
}
}
} |
Partager