mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the bwtc, to compatible with bms4.
This commit is contained in:
parent
eed4626c35
commit
b3c13f2550
4 changed files with 79 additions and 26 deletions
|
@ -38,3 +38,4 @@
|
|||
<buildCSSFiles/>
|
||||
<flashCatalyst validateFlashCatalystCompatibility="false"/>
|
||||
</actionScriptProperties>
|
||||
|
||||
|
|
Binary file not shown.
|
@ -25,6 +25,7 @@ package
|
|||
import flash.events.NetStatusEvent;
|
||||
import flash.external.ExternalInterface;
|
||||
import flash.net.NetConnection;
|
||||
import flash.net.NetStream;
|
||||
import flash.net.ObjectEncoding;
|
||||
import flash.utils.clearTimeout;
|
||||
import flash.utils.setTimeout;
|
||||
|
@ -92,7 +93,7 @@ package
|
|||
* srs_server: the srs server info.
|
||||
* srs_primary: the srs primary authors info.
|
||||
* srs_authors: the srs authors info.
|
||||
* srs_id: the tracable log id, to direclty grep the log..
|
||||
* srs_id: the tracable log id, to direclty grep the log.
|
||||
* srs_pid: the srs process id, to direclty grep the log.
|
||||
* srs_server_ip: the srs server ip, where client connected at.
|
||||
* @param as_on_complete, function(start_time:Number, end_time:Number, play_kbps:Number, publish_kbps:Number, play_bytes:Number, publish_bytes:Number, play_time:Number, publish_time:Number):void, where
|
||||
|
@ -280,6 +281,8 @@ package
|
|||
* check/test with server.
|
||||
*/
|
||||
private var connection:NetConnection = null;
|
||||
// for bms4, use stream to play then do bandwidth test.
|
||||
private var stream:NetStream = null;
|
||||
|
||||
/**
|
||||
* use timeout to sendout publish call packets.
|
||||
|
@ -293,7 +296,7 @@ package
|
|||
*/
|
||||
private function system_on_js_ready():void {
|
||||
if (!flash.external.ExternalInterface.available) {
|
||||
trace("js not ready, try later.");
|
||||
log("js not ready, try later.");
|
||||
flash.utils.setTimeout(this.system_on_js_ready, 100);
|
||||
return;
|
||||
}
|
||||
|
@ -318,6 +321,7 @@ package
|
|||
__on_progress_change(0);
|
||||
|
||||
// init connection
|
||||
log("create connection for bandwidth check");
|
||||
connection = new NetConnection;
|
||||
connection.objectEncoding = ObjectEncoding.AMF0;
|
||||
connection.client = {
|
||||
|
@ -350,7 +354,7 @@ package
|
|||
private function onSrsBandCheckStartPlayBytes(evt:Object):void{
|
||||
var duration_ms:Number = evt.duration_ms;
|
||||
var interval_ms:Number = evt.interval_ms;
|
||||
trace("start play test, duration=" + duration_ms + ", interval=" + interval_ms);
|
||||
log("start play test, duration=" + duration_ms + ", interval=" + interval_ms);
|
||||
|
||||
connection.call("onSrsBandCheckStartingPlayBytes", null);
|
||||
__on_status_change(SrsBandwidth.StatusSrsBwtcPlayStart);
|
||||
|
@ -482,8 +486,9 @@ package
|
|||
* get NetConnection NetStatusEvent
|
||||
*/
|
||||
private function onStatus(evt:NetStatusEvent): void {
|
||||
trace(evt.info.code);
|
||||
log(evt.info.code);
|
||||
|
||||
var srs_version:String = null;
|
||||
if (evt.info.hasOwnProperty("data") && evt.info.data) {
|
||||
if (evt.info.data.hasOwnProperty("srs_server")) {
|
||||
srs_server = evt.info.data.srs_server;
|
||||
|
@ -503,6 +508,9 @@ package
|
|||
if (evt.info.data.hasOwnProperty("srs_server_ip")) {
|
||||
srs_server_ip = evt.info.data.srs_server_ip;
|
||||
}
|
||||
if (evt.info.data.hasOwnProperty("srs_version")) {
|
||||
srs_version = evt.info.data.srs_version;
|
||||
}
|
||||
|
||||
if (this.as_on_srs_info != null) {
|
||||
this.as_on_srs_info(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip);
|
||||
|
@ -512,6 +520,10 @@ package
|
|||
srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip);
|
||||
}
|
||||
}
|
||||
|
||||
var e:NetStatusEvent = evt;
|
||||
var foo:Function = function():void{
|
||||
var evt:NetStatusEvent = e;
|
||||
if (evt.info.code) {
|
||||
__on_status_change(evt.info.code);
|
||||
}
|
||||
|
@ -520,7 +532,33 @@ package
|
|||
__on_progress_change(8);
|
||||
break;
|
||||
}
|
||||
};
|
||||
foo();
|
||||
|
||||
// for bms4, play stream to trigger the bandwidth check.
|
||||
if (evt.info.code != "NetConnection.Connect.Success") {
|
||||
return;
|
||||
}
|
||||
if (stream != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var is_bms:Boolean = false;
|
||||
if (srs_server.indexOf("BMS/") == 0 || srs_server.indexOf("UPYUN/") == 0) {
|
||||
is_bms = true;
|
||||
}
|
||||
if (parseInt(srs_version.charAt(0)) >= 4 && is_bms) {
|
||||
stream = new NetStream(connection);
|
||||
stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{
|
||||
log(evt.info.code);
|
||||
|
||||
if (evt.info.code == "NetStream.Play.Start") {
|
||||
}
|
||||
});
|
||||
stream.play("test");
|
||||
log("play stream for " + srs_server + " " + srs_version);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -544,5 +582,12 @@ package
|
|||
code, data);
|
||||
}
|
||||
}
|
||||
|
||||
private function log(msg:String):void {
|
||||
trace(msg);
|
||||
if (ExternalInterface.available) {
|
||||
ExternalInterface.call("console.log", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,13 +121,13 @@ package
|
|||
|
||||
// for directly run swf.
|
||||
if (!conf.id) {
|
||||
trace("directly run swf, load default url: " + this.default_url);
|
||||
log("directly run swf, load default url: " + this.default_url);
|
||||
this.bandwidth.check_bandwidth(this.default_url);
|
||||
}
|
||||
|
||||
}
|
||||
private function on_progress(percent:Number):void {
|
||||
trace("progress:" + percent + "%");
|
||||
log("progress:" + percent + "%");
|
||||
}
|
||||
private function update_context_items(
|
||||
srs_server:String, srs_primary:String, srs_authors:String,
|
||||
|
@ -156,31 +156,31 @@ package
|
|||
contextMenu.customItems = customItems;
|
||||
}
|
||||
public function on_status_change(code:String, data:String): void {
|
||||
trace(code);
|
||||
log(code);
|
||||
switch(code){
|
||||
case "NetConnection.Connect.Failed":
|
||||
trace("连接服务器失败!");
|
||||
log("连接服务器失败!");
|
||||
break;
|
||||
case "NetConnection.Connect.Rejected":
|
||||
trace("服务器拒绝连接!");
|
||||
log("服务器拒绝连接!");
|
||||
break;
|
||||
case "NetConnection.Connect.Success":
|
||||
trace("连接服务器成功!");
|
||||
log("连接服务器成功!");
|
||||
break;
|
||||
case SrsBandwidth.StatusSrsBwtcPlayStart:
|
||||
trace("开始测试下行带宽");
|
||||
log("开始测试下行带宽");
|
||||
break;
|
||||
case SrsBandwidth.StatusSrsBwtcPlayStop:
|
||||
trace("下行带宽测试完毕," + data + "kbps,开始测试上行带宽。");
|
||||
log("下行带宽测试完毕," + data + "kbps,开始测试上行带宽。");
|
||||
break;
|
||||
case SrsBandwidth.StatusSrsBwtcPublishStart:
|
||||
trace("开始测试上行带宽");
|
||||
log("开始测试上行带宽");
|
||||
break;
|
||||
case SrsBandwidth.StatusSrsBwtcPublishStop:
|
||||
trace("上行带宽测试完毕," + data + "kbps,");
|
||||
log("上行带宽测试完毕," + data + "kbps,");
|
||||
break;
|
||||
case "NetConnection.Connect.Closed":
|
||||
trace("连接已断开!");
|
||||
log("连接已断开!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,14 @@ package
|
|||
):void {
|
||||
var status:String = "检测结束: 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps"
|
||||
+ " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒";
|
||||
trace(status);
|
||||
log(status);
|
||||
}
|
||||
|
||||
private function log(msg:String):void {
|
||||
trace(msg);
|
||||
if (ExternalInterface.available) {
|
||||
ExternalInterface.call("console.log", msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue