正在显示
5 个修改的文件
包含
60 行增加
和
38 行删除
| @@ -41,6 +41,7 @@ | @@ -41,6 +41,7 @@ | ||
| 41 | } | 41 | } |
| 42 | function on_start_bandwidth_test() { | 42 | function on_start_bandwidth_test() { |
| 43 | $("#div_container").remove(); | 43 | $("#div_container").remove(); |
| 44 | + $("#progress_bar").removeClass("bar-danger"); | ||
| 44 | 45 | ||
| 45 | var div_container = $("<div/>"); | 46 | var div_container = $("<div/>"); |
| 46 | $(div_container).attr("id", "div_container"); | 47 | $(div_container).attr("id", "div_container"); |
| @@ -68,6 +69,9 @@ | @@ -68,6 +69,9 @@ | ||
| 68 | ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip | 69 | ", srs_id:" + srs_id + ", srs_pid:" + srs_pid + ", ip:" + srs_server_ip |
| 69 | ); | 70 | ); |
| 70 | } | 71 | } |
| 72 | + bandwidth.on_error = function(code) { | ||
| 73 | + $("#progress_bar").addClass("bar-danger"); | ||
| 74 | + } | ||
| 71 | bandwidth.render(url); | 75 | bandwidth.render(url); |
| 72 | } | 76 | } |
| 73 | function on_stop_bandwidth_test() { | 77 | function on_stop_bandwidth_test() { |
| @@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) { | @@ -49,8 +49,8 @@ function SrsBandwidth(container, width, height, private_object) { | ||
| 49 | // the callback set data. | 49 | // the callback set data. |
| 50 | this.percent = 0; | 50 | this.percent = 0; |
| 51 | this.status = ""; | 51 | this.status = ""; |
| 52 | - this.report = ""; | ||
| 53 | this.server = ""; | 52 | this.server = ""; |
| 53 | + this.completed = false; | ||
| 54 | } | 54 | } |
| 55 | /** | 55 | /** |
| 56 | * user can set some callback, then start the bandwidth. | 56 | * user can set some callback, then start the bandwidth. |
| @@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) { | @@ -106,6 +106,12 @@ SrsBandwidth.prototype.check_bandwidth = function(url) { | ||
| 106 | this.stop(); | 106 | this.stop(); |
| 107 | SrsBandwidth.__bandwidths.push(this); | 107 | SrsBandwidth.__bandwidths.push(this); |
| 108 | 108 | ||
| 109 | + // the callback set data. | ||
| 110 | + this.percent = 0; | ||
| 111 | + this.status = ""; | ||
| 112 | + this.server = ""; | ||
| 113 | + this.completed = false; | ||
| 114 | + | ||
| 109 | if (url) { | 115 | if (url) { |
| 110 | this.stream_url = url; | 116 | this.stream_url = url; |
| 111 | } | 117 | } |
| @@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s | @@ -136,6 +142,8 @@ SrsBandwidth.prototype.on_srs_info = function(srs_server, srs_primary_authors, s | ||
| 136 | } | 142 | } |
| 137 | SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) { | 143 | SrsBandwidth.prototype.on_complete = function(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time) { |
| 138 | } | 144 | } |
| 145 | +SrsBandwidth.prototype.on_error = function(code) { | ||
| 146 | +} | ||
| 139 | function __srs_find_bandwidth(id) { | 147 | function __srs_find_bandwidth(id) { |
| 140 | for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) { | 148 | for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) { |
| 141 | var bandwidth = SrsBandwidth.__bandwidths[i]; | 149 | var bandwidth = SrsBandwidth.__bandwidths[i]; |
| @@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) { | @@ -164,24 +172,36 @@ function __srs_on_update_status(id, code, data) { | ||
| 164 | var status = ""; | 172 | var status = ""; |
| 165 | switch(code){ | 173 | switch(code){ |
| 166 | case "NetConnection.Connect.Failed": | 174 | case "NetConnection.Connect.Failed": |
| 175 | + if (bandwidth.completed) { | ||
| 176 | + return; | ||
| 177 | + } | ||
| 178 | + bandwidth.on_error(code); | ||
| 167 | status = "连接服务器失败!"; | 179 | status = "连接服务器失败!"; |
| 168 | break; | 180 | break; |
| 169 | case "NetConnection.Connect.Rejected": | 181 | case "NetConnection.Connect.Rejected": |
| 170 | - status = "服务器拒绝连接!"; | 182 | + if (bandwidth.completed) { |
| 183 | + return; | ||
| 184 | + } | ||
| 185 | + bandwidth.completed = true; | ||
| 186 | + bandwidth.on_update_progress(100); | ||
| 187 | + bandwidth.on_error(code); | ||
| 188 | + status = "服务器拒绝连接,测速过于频繁!"; | ||
| 171 | break; | 189 | break; |
| 172 | case "NetConnection.Connect.Success": | 190 | case "NetConnection.Connect.Success": |
| 173 | status = "连接服务器成功!"; | 191 | status = "连接服务器成功!"; |
| 174 | break; | 192 | break; |
| 175 | case "NetConnection.Connect.Closed": | 193 | case "NetConnection.Connect.Closed": |
| 176 | - if (bandwidth.report) { | 194 | + if (bandwidth.completed) { |
| 177 | return; | 195 | return; |
| 178 | } | 196 | } |
| 197 | + bandwidth.on_error(code); | ||
| 179 | status = "连接已断开!"; | 198 | status = "连接已断开!"; |
| 180 | break; | 199 | break; |
| 181 | case "srs.bwtc.play.start": | 200 | case "srs.bwtc.play.start": |
| 182 | status = "开始测试下行带宽"; | 201 | status = "开始测试下行带宽"; |
| 183 | break; | 202 | break; |
| 184 | case "srs.bwtc.play.stop": | 203 | case "srs.bwtc.play.stop": |
| 204 | + bandwidth.completed = true; | ||
| 185 | status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"; | 205 | status = "下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"; |
| 186 | break; | 206 | break; |
| 187 | default: | 207 | default: |
| @@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl | @@ -202,7 +222,7 @@ function __srs_on_complete(id, start_time, end_time, play_kbps, publish_kbps, pl | ||
| 202 | 222 | ||
| 203 | var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" | 223 | var status = "检测结束: " + bandwidth.server + " 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" |
| 204 | + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; | 224 | + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; |
| 205 | - bandwidth.report = status; | 225 | + bandwidth.status = status; |
| 206 | bandwidth.on_update_status(status); | 226 | bandwidth.on_update_status(status); |
| 207 | 227 | ||
| 208 | bandwidth.on_complete(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time); | 228 | bandwidth.on_complete(start_time, end_time, play_kbps, publish_kbps, play_bytes, publish_bytes, play_time, publish_time); |
| @@ -78,7 +78,7 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, SrsRequest* req, string l | @@ -78,7 +78,7 @@ int SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, SrsRequest* req, string l | ||
| 78 | // reject the connection in the interval window. | 78 | // reject the connection in the interval window. |
| 79 | if (last_check_time > 0 && time_now - last_check_time < interval_ms) { | 79 | if (last_check_time > 0 && time_now - last_check_time < interval_ms) { |
| 80 | ret = ERROR_SYSTEM_BANDWIDTH_DENIED; | 80 | ret = ERROR_SYSTEM_BANDWIDTH_DENIED; |
| 81 | - srs_trace("bandcheck denied, " | 81 | + srs_trace("reject, " |
| 82 | "last_check=%"PRId64", now=%"PRId64", interval=%d", | 82 | "last_check=%"PRId64", now=%"PRId64", interval=%d", |
| 83 | last_check_time, time_now, interval_ms); | 83 | last_check_time, time_now, interval_ms); |
| 84 | 84 |
| @@ -1866,20 +1866,20 @@ int SrsConfig::get_bw_check_interval_ms(const string &vhost) | @@ -1866,20 +1866,20 @@ int SrsConfig::get_bw_check_interval_ms(const string &vhost) | ||
| 1866 | SrsConfDirective* conf = get_vhost(vhost); | 1866 | SrsConfDirective* conf = get_vhost(vhost); |
| 1867 | 1867 | ||
| 1868 | if (!conf) { | 1868 | if (!conf) { |
| 1869 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | 1869 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000; |
| 1870 | } | 1870 | } |
| 1871 | 1871 | ||
| 1872 | conf = conf->get("bandcheck"); | 1872 | conf = conf->get("bandcheck"); |
| 1873 | if (!conf) { | 1873 | if (!conf) { |
| 1874 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | 1874 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000; |
| 1875 | } | 1875 | } |
| 1876 | 1876 | ||
| 1877 | - conf = conf->get("interval_ms"); | 1877 | + conf = conf->get("interval"); |
| 1878 | if (!conf) { | 1878 | if (!conf) { |
| 1879 | - return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL; | 1879 | + return SRS_CONF_DEFAULT_BANDWIDTH_INTERVAL * 1000; |
| 1880 | } | 1880 | } |
| 1881 | 1881 | ||
| 1882 | - return ::atoi(conf->arg0().c_str()) * 1000; | 1882 | + return ::atof(conf->arg0().c_str()) * 1000; |
| 1883 | } | 1883 | } |
| 1884 | 1884 | ||
| 1885 | int SrsConfig::get_bw_check_limit_kbps(const string &vhost) | 1885 | int SrsConfig::get_bw_check_limit_kbps(const string &vhost) |
| @@ -40,39 +40,39 @@ using namespace std; | @@ -40,39 +40,39 @@ using namespace std; | ||
| 40 | /** | 40 | /** |
| 41 | * the signature for packets to client. | 41 | * the signature for packets to client. |
| 42 | */ | 42 | */ |
| 43 | -#define RTMP_SIG_FMS_VER "3,5,3,888" | ||
| 44 | -#define RTMP_SIG_AMF0_VER 0 | ||
| 45 | -#define RTMP_SIG_CLIENT_ID "ASAICiss" | 43 | +#define RTMP_SIG_FMS_VER "3,5,3,888" |
| 44 | +#define RTMP_SIG_AMF0_VER 0 | ||
| 45 | +#define RTMP_SIG_CLIENT_ID "ASAICiss" | ||
| 46 | 46 | ||
| 47 | /** | 47 | /** |
| 48 | * onStatus consts. | 48 | * onStatus consts. |
| 49 | */ | 49 | */ |
| 50 | -#define StatusLevel "level" | ||
| 51 | -#define StatusCode "code" | ||
| 52 | -#define StatusDescription "description" | ||
| 53 | -#define StatusDetails "details" | ||
| 54 | -#define StatusClientId "clientid" | 50 | +#define StatusLevel "level" |
| 51 | +#define StatusCode "code" | ||
| 52 | +#define StatusDescription "description" | ||
| 53 | +#define StatusDetails "details" | ||
| 54 | +#define StatusClientId "clientid" | ||
| 55 | // status value | 55 | // status value |
| 56 | -#define StatusLevelStatus "status" | 56 | +#define StatusLevelStatus "status" |
| 57 | // status error | 57 | // status error |
| 58 | -#define StatusLevelError "error" | 58 | +#define StatusLevelError "error" |
| 59 | // code value | 59 | // code value |
| 60 | -#define StatusCodeConnectSuccess "NetConnection.Connect.Success" | ||
| 61 | -#define StatusCodeConnectRejected "NetConnection.Connect.Rejected" | ||
| 62 | -#define StatusCodeStreamReset "NetStream.Play.Reset" | ||
| 63 | -#define StatusCodeStreamStart "NetStream.Play.Start" | ||
| 64 | -#define StatusCodeStreamPause "NetStream.Pause.Notify" | ||
| 65 | -#define StatusCodeStreamUnpause "NetStream.Unpause.Notify" | ||
| 66 | -#define StatusCodePublishStart "NetStream.Publish.Start" | ||
| 67 | -#define StatusCodeDataStart "NetStream.Data.Start" | ||
| 68 | -#define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success" | 60 | +#define StatusCodeConnectSuccess "NetConnection.Connect.Success" |
| 61 | +#define StatusCodeConnectRejected "NetConnection.Connect.Rejected" | ||
| 62 | +#define StatusCodeStreamReset "NetStream.Play.Reset" | ||
| 63 | +#define StatusCodeStreamStart "NetStream.Play.Start" | ||
| 64 | +#define StatusCodeStreamPause "NetStream.Pause.Notify" | ||
| 65 | +#define StatusCodeStreamUnpause "NetStream.Unpause.Notify" | ||
| 66 | +#define StatusCodePublishStart "NetStream.Publish.Start" | ||
| 67 | +#define StatusCodeDataStart "NetStream.Data.Start" | ||
| 68 | +#define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success" | ||
| 69 | 69 | ||
| 70 | // FMLE | 70 | // FMLE |
| 71 | -#define RTMP_AMF0_COMMAND_ON_FC_PUBLISH "onFCPublish" | ||
| 72 | -#define RTMP_AMF0_COMMAND_ON_FC_UNPUBLISH "onFCUnpublish" | 71 | +#define RTMP_AMF0_COMMAND_ON_FC_PUBLISH "onFCPublish" |
| 72 | +#define RTMP_AMF0_COMMAND_ON_FC_UNPUBLISH "onFCUnpublish" | ||
| 73 | 73 | ||
| 74 | // default stream id for response the createStream request. | 74 | // default stream id for response the createStream request. |
| 75 | -#define SRS_DEFAULT_SID 1 | 75 | +#define SRS_DEFAULT_SID 1 |
| 76 | 76 | ||
| 77 | SrsRequest::SrsRequest() | 77 | SrsRequest::SrsRequest() |
| 78 | { | 78 | { |
| @@ -910,12 +910,10 @@ void SrsRtmpServer::response_connect_reject(SrsRequest *req, const char* desc) | @@ -910,12 +910,10 @@ void SrsRtmpServer::response_connect_reject(SrsRequest *req, const char* desc) | ||
| 910 | { | 910 | { |
| 911 | int ret = ERROR_SUCCESS; | 911 | int ret = ERROR_SUCCESS; |
| 912 | 912 | ||
| 913 | - SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket(); | ||
| 914 | - pkt->command_name = "_error"; | ||
| 915 | - pkt->props->set(StatusLevel, SrsAmf0Any::str(StatusLevelError)); | ||
| 916 | - pkt->props->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected)); | ||
| 917 | - pkt->props->set(StatusDescription, SrsAmf0Any::str(desc)); | ||
| 918 | - //pkt->props->set("objectEncoding", SrsAmf0Any::number(req->objectEncoding)); | 913 | + SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket(); |
| 914 | + pkt->data->set(StatusLevel, SrsAmf0Any::str(StatusLevelError)); | ||
| 915 | + pkt->data->set(StatusCode, SrsAmf0Any::str(StatusCodeConnectRejected)); | ||
| 916 | + pkt->data->set(StatusDescription, SrsAmf0Any::str(desc)); | ||
| 919 | 917 | ||
| 920 | if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { | 918 | if ((ret = protocol->send_and_free_packet(pkt, 0)) != ERROR_SUCCESS) { |
| 921 | srs_error("send connect app response rejected message failed. ret=%d", ret); | 919 | srs_error("send connect app response rejected message failed. ret=%d", ret); |
-
请 注册 或 登录 后发表评论