1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix bandwidth bug, config item interval to float.

This commit is contained in:
winlin 2014-07-12 22:22:56 +08:00
parent d8ed7cc968
commit 3a1b3dd142
5 changed files with 60 additions and 38 deletions

View file

@ -41,6 +41,7 @@
}
function on_start_bandwidth_test() {
$("#div_container").remove();
$("#progress_bar").removeClass("bar-danger");
var div_container = $("<div/>");
$(div_container).attr("id", "div_container");
@ -68,6 +69,9 @@
", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip
);
}
bandwidth.on_error = function(code) {
$("#progress_bar").addClass("bar-danger");
}
bandwidth.render(url);
}
function on_stop_bandwidth_test() {

View file

@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) {
// the callback set data.
this.percent = 0;
this.status = "";
this.report = "";
this.server = "";
this.completed = false;
}
/**
* user can set some callback, then start the bandwidth.
@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) {
this.stop();
SrsBandwidth.__bandwidths.push(this);
// the callback set data.
this.percent = 0;
this.status = "";
this.server = "";
this.completed = false;
if (url) {
this.stream_url = url;
}
@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s
}
SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) {
}
SrsBandwidth.prototype.on_error = function(code) {
}
function __srs_find_bandwidth(id) {
for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) {
var bandwidth = SrsBandwidth.__bandwidths[i];
@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) {
var status = "";
switch(code){
case "NetConnection.Connect.Failed":
if (bandwidth.completed) {
return;
}
bandwidth.on_error(code);
status = "连接服务器失败!";
break;
case "NetConnection.Connect.Rejected":
status = "服务器拒绝连接!";
if (bandwidth.completed) {
return;
}
bandwidth.completed = true;
bandwidth.on_update_progress(100);
bandwidth.on_error(code);
status = "服务器拒绝连接,测速过于频繁!";
break;
case "NetConnection.Connect.Success":
status = "连接服务器成功!";
break;
case "NetConnection.Connect.Closed":
if (bandwidth.report) {
if (bandwidth.completed) {
return;
}
bandwidth.on_error(code);
status = "连接已断开!";
break;
case "srs.bwtc.play.start":
status = "开始测试下行带宽";
break;
case "srs.bwtc.play.stop":
bandwidth.completed = true;
status = "下行带宽测试完毕," + data + "kbps开始测试上行带宽。";
break;
default:
@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl
var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps"
+ " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒";
bandwidth.report = status;
bandwidth.status = status;
bandwidth.on_update_status(status);
bandwidth.on_complete(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time);