正在显示
4 个修改的文件
包含
79 行增加
和
26 行删除
| @@ -25,6 +25,7 @@ package | @@ -25,6 +25,7 @@ package | ||
| 25 | import flash.events.NetStatusEvent; | 25 | import flash.events.NetStatusEvent; |
| 26 | import flash.external.ExternalInterface; | 26 | import flash.external.ExternalInterface; |
| 27 | import flash.net.NetConnection; | 27 | import flash.net.NetConnection; |
| 28 | + import flash.net.NetStream; | ||
| 28 | import flash.net.ObjectEncoding; | 29 | import flash.net.ObjectEncoding; |
| 29 | import flash.utils.clearTimeout; | 30 | import flash.utils.clearTimeout; |
| 30 | import flash.utils.setTimeout; | 31 | import flash.utils.setTimeout; |
| @@ -92,7 +93,7 @@ package | @@ -92,7 +93,7 @@ package | ||
| 92 | * srs_server: the srs server info. | 93 | * srs_server: the srs server info. |
| 93 | * srs_primary: the srs primary authors info. | 94 | * srs_primary: the srs primary authors info. |
| 94 | * srs_authors: the srs authors info. | 95 | * srs_authors: the srs authors info. |
| 95 | - * srs_id: the tracable log id, to direclty grep the log.. | 96 | + * srs_id: the tracable log id, to direclty grep the log. |
| 96 | * srs_pid: the srs process id, to direclty grep the log. | 97 | * srs_pid: the srs process id, to direclty grep the log. |
| 97 | * srs_server_ip: the srs server ip, where client connected at. | 98 | * srs_server_ip: the srs server ip, where client connected at. |
| 98 | * @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 | 99 | * @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 | @@ -280,6 +281,8 @@ package | ||
| 280 | * check/test with server. | 281 | * check/test with server. |
| 281 | */ | 282 | */ |
| 282 | private var connection:NetConnection = null; | 283 | private var connection:NetConnection = null; |
| 284 | + // for bms4, use stream to play then do bandwidth test. | ||
| 285 | + private var stream:NetStream = null; | ||
| 283 | 286 | ||
| 284 | /** | 287 | /** |
| 285 | * use timeout to sendout publish call packets. | 288 | * use timeout to sendout publish call packets. |
| @@ -293,7 +296,7 @@ package | @@ -293,7 +296,7 @@ package | ||
| 293 | */ | 296 | */ |
| 294 | private function system_on_js_ready():void { | 297 | private function system_on_js_ready():void { |
| 295 | if (!flash.external.ExternalInterface.available) { | 298 | if (!flash.external.ExternalInterface.available) { |
| 296 | - trace("js not ready, try later."); | 299 | + log("js not ready, try later."); |
| 297 | flash.utils.setTimeout(this.system_on_js_ready, 100); | 300 | flash.utils.setTimeout(this.system_on_js_ready, 100); |
| 298 | return; | 301 | return; |
| 299 | } | 302 | } |
| @@ -318,6 +321,7 @@ package | @@ -318,6 +321,7 @@ package | ||
| 318 | __on_progress_change(0); | 321 | __on_progress_change(0); |
| 319 | 322 | ||
| 320 | // init connection | 323 | // init connection |
| 324 | + log("create connection for bandwidth check"); | ||
| 321 | connection = new NetConnection; | 325 | connection = new NetConnection; |
| 322 | connection.objectEncoding = ObjectEncoding.AMF0; | 326 | connection.objectEncoding = ObjectEncoding.AMF0; |
| 323 | connection.client = { | 327 | connection.client = { |
| @@ -350,7 +354,7 @@ package | @@ -350,7 +354,7 @@ package | ||
| 350 | private function onSrsBandCheckStartPlayBytes(evt:Object):void{ | 354 | private function onSrsBandCheckStartPlayBytes(evt:Object):void{ |
| 351 | var duration_ms:Number = evt.duration_ms; | 355 | var duration_ms:Number = evt.duration_ms; |
| 352 | var interval_ms:Number = evt.interval_ms; | 356 | var interval_ms:Number = evt.interval_ms; |
| 353 | - trace("start play test, duration=" + duration_ms + ", interval=" + interval_ms); | 357 | + log("start play test, duration=" + duration_ms + ", interval=" + interval_ms); |
| 354 | 358 | ||
| 355 | connection.call("onSrsBandCheckStartingPlayBytes", null); | 359 | connection.call("onSrsBandCheckStartingPlayBytes", null); |
| 356 | __on_status_change(SrsBandwidth.StatusSrsBwtcPlayStart); | 360 | __on_status_change(SrsBandwidth.StatusSrsBwtcPlayStart); |
| @@ -482,8 +486,9 @@ package | @@ -482,8 +486,9 @@ package | ||
| 482 | * get NetConnection NetStatusEvent | 486 | * get NetConnection NetStatusEvent |
| 483 | */ | 487 | */ |
| 484 | private function onStatus(evt:NetStatusEvent): void { | 488 | private function onStatus(evt:NetStatusEvent): void { |
| 485 | - trace(evt.info.code); | 489 | + log(evt.info.code); |
| 486 | 490 | ||
| 491 | + var srs_version:String = null; | ||
| 487 | if (evt.info.hasOwnProperty("data") && evt.info.data) { | 492 | if (evt.info.hasOwnProperty("data") && evt.info.data) { |
| 488 | if (evt.info.data.hasOwnProperty("srs_server")) { | 493 | if (evt.info.data.hasOwnProperty("srs_server")) { |
| 489 | srs_server = evt.info.data.srs_server; | 494 | srs_server = evt.info.data.srs_server; |
| @@ -503,6 +508,9 @@ package | @@ -503,6 +508,9 @@ package | ||
| 503 | if (evt.info.data.hasOwnProperty("srs_server_ip")) { | 508 | if (evt.info.data.hasOwnProperty("srs_server_ip")) { |
| 504 | srs_server_ip = evt.info.data.srs_server_ip; | 509 | srs_server_ip = evt.info.data.srs_server_ip; |
| 505 | } | 510 | } |
| 511 | + if (evt.info.data.hasOwnProperty("srs_version")) { | ||
| 512 | + srs_version = evt.info.data.srs_version; | ||
| 513 | + } | ||
| 506 | 514 | ||
| 507 | if (this.as_on_srs_info != null) { | 515 | if (this.as_on_srs_info != null) { |
| 508 | this.as_on_srs_info(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); | 516 | this.as_on_srs_info(srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); |
| @@ -511,16 +519,46 @@ package | @@ -511,16 +519,46 @@ package | ||
| 511 | flash.external.ExternalInterface.call(this.js_on_srs_info, this.js_id, | 519 | flash.external.ExternalInterface.call(this.js_on_srs_info, this.js_id, |
| 512 | srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); | 520 | srs_server, srs_primary, srs_authors, srs_id, srs_pid, srs_server_ip); |
| 513 | } | 521 | } |
| 514 | - } | ||
| 515 | - if (evt.info.code) { | ||
| 516 | - __on_status_change(evt.info.code); | ||
| 517 | - } | ||
| 518 | - switch(evt.info.code){ | ||
| 519 | - case "NetConnection.Connect.Success": | ||
| 520 | - __on_progress_change(8); | ||
| 521 | - break; | ||
| 522 | - } | ||
| 523 | - | 522 | + } |
| 523 | + | ||
| 524 | + var e:NetStatusEvent = evt; | ||
| 525 | + var foo:Function = function():void{ | ||
| 526 | + var evt:NetStatusEvent = e; | ||
| 527 | + if (evt.info.code) { | ||
| 528 | + __on_status_change(evt.info.code); | ||
| 529 | + } | ||
| 530 | + switch(evt.info.code){ | ||
| 531 | + case "NetConnection.Connect.Success": | ||
| 532 | + __on_progress_change(8); | ||
| 533 | + break; | ||
| 534 | + } | ||
| 535 | + }; | ||
| 536 | + foo(); | ||
| 537 | + | ||
| 538 | + // for bms4, play stream to trigger the bandwidth check. | ||
| 539 | + if (evt.info.code != "NetConnection.Connect.Success") { | ||
| 540 | + return; | ||
| 541 | + } | ||
| 542 | + if (stream != null) { | ||
| 543 | + return; | ||
| 544 | + } | ||
| 545 | + | ||
| 546 | + var is_bms:Boolean = false; | ||
| 547 | + if (srs_server.indexOf("BMS/") == 0 || srs_server.indexOf("UPYUN/") == 0) { | ||
| 548 | + is_bms = true; | ||
| 549 | + } | ||
| 550 | + if (parseInt(srs_version.charAt(0)) >= 4 && is_bms) { | ||
| 551 | + stream = new NetStream(connection); | ||
| 552 | + stream.addEventListener(NetStatusEvent.NET_STATUS, function(evt:NetStatusEvent):void{ | ||
| 553 | + log(evt.info.code); | ||
| 554 | + | ||
| 555 | + if (evt.info.code == "NetStream.Play.Start") { | ||
| 556 | + } | ||
| 557 | + }); | ||
| 558 | + stream.play("test"); | ||
| 559 | + log("play stream for " + srs_server + " " + srs_version); | ||
| 560 | + return; | ||
| 561 | + } | ||
| 524 | } | 562 | } |
| 525 | 563 | ||
| 526 | /** | 564 | /** |
| @@ -544,5 +582,12 @@ package | @@ -544,5 +582,12 @@ package | ||
| 544 | code, data); | 582 | code, data); |
| 545 | } | 583 | } |
| 546 | } | 584 | } |
| 585 | + | ||
| 586 | + private function log(msg:String):void { | ||
| 587 | + trace(msg); | ||
| 588 | + if (ExternalInterface.available) { | ||
| 589 | + ExternalInterface.call("console.log", msg); | ||
| 590 | + } | ||
| 591 | + } | ||
| 547 | } | 592 | } |
| 548 | } | 593 | } |
| @@ -121,13 +121,13 @@ package | @@ -121,13 +121,13 @@ package | ||
| 121 | 121 | ||
| 122 | // for directly run swf. | 122 | // for directly run swf. |
| 123 | if (!conf.id) { | 123 | if (!conf.id) { |
| 124 | - trace("directly run swf, load default url: " + this.default_url); | 124 | + log("directly run swf, load default url: " + this.default_url); |
| 125 | this.bandwidth.check_bandwidth(this.default_url); | 125 | this.bandwidth.check_bandwidth(this.default_url); |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | } | 128 | } |
| 129 | private function on_progress(percent:Number):void { | 129 | private function on_progress(percent:Number):void { |
| 130 | - trace("progress:" + percent + "%"); | 130 | + log("progress:" + percent + "%"); |
| 131 | } | 131 | } |
| 132 | private function update_context_items( | 132 | private function update_context_items( |
| 133 | srs_server:String, srs_primary:String, srs_authors:String, | 133 | srs_server:String, srs_primary:String, srs_authors:String, |
| @@ -156,31 +156,31 @@ package | @@ -156,31 +156,31 @@ package | ||
| 156 | contextMenu.customItems = customItems; | 156 | contextMenu.customItems = customItems; |
| 157 | } | 157 | } |
| 158 | public function on_status_change(code:String, data:String): void { | 158 | public function on_status_change(code:String, data:String): void { |
| 159 | - trace(code); | 159 | + log(code); |
| 160 | switch(code){ | 160 | switch(code){ |
| 161 | case "NetConnection.Connect.Failed": | 161 | case "NetConnection.Connect.Failed": |
| 162 | - trace("连接服务器失败!"); | 162 | + log("连接服务器失败!"); |
| 163 | break; | 163 | break; |
| 164 | case "NetConnection.Connect.Rejected": | 164 | case "NetConnection.Connect.Rejected": |
| 165 | - trace("服务器拒绝连接!"); | 165 | + log("服务器拒绝连接!"); |
| 166 | break; | 166 | break; |
| 167 | case "NetConnection.Connect.Success": | 167 | case "NetConnection.Connect.Success": |
| 168 | - trace("连接服务器成功!"); | 168 | + log("连接服务器成功!"); |
| 169 | break; | 169 | break; |
| 170 | case SrsBandwidth.StatusSrsBwtcPlayStart: | 170 | case SrsBandwidth.StatusSrsBwtcPlayStart: |
| 171 | - trace("开始测试下行带宽"); | 171 | + log("开始测试下行带宽"); |
| 172 | break; | 172 | break; |
| 173 | case SrsBandwidth.StatusSrsBwtcPlayStop: | 173 | case SrsBandwidth.StatusSrsBwtcPlayStop: |
| 174 | - trace("下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"); | 174 | + log("下行带宽测试完毕," + data + "kbps,开始测试上行带宽。"); |
| 175 | break; | 175 | break; |
| 176 | case SrsBandwidth.StatusSrsBwtcPublishStart: | 176 | case SrsBandwidth.StatusSrsBwtcPublishStart: |
| 177 | - trace("开始测试上行带宽"); | 177 | + log("开始测试上行带宽"); |
| 178 | break; | 178 | break; |
| 179 | case SrsBandwidth.StatusSrsBwtcPublishStop: | 179 | case SrsBandwidth.StatusSrsBwtcPublishStop: |
| 180 | - trace("上行带宽测试完毕," + data + "kbps,"); | 180 | + log("上行带宽测试完毕," + data + "kbps,"); |
| 181 | break; | 181 | break; |
| 182 | case "NetConnection.Connect.Closed": | 182 | case "NetConnection.Connect.Closed": |
| 183 | - trace("连接已断开!"); | 183 | + log("连接已断开!"); |
| 184 | break; | 184 | break; |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| @@ -190,7 +190,14 @@ package | @@ -190,7 +190,14 @@ package | ||
| 190 | ):void { | 190 | ):void { |
| 191 | var status:String = "检测结束: 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" | 191 | var status:String = "检测结束: 上行: " + publish_kbps + " kbps" + " 下行: " + play_kbps + " kbps" |
| 192 | + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; | 192 | + " 测试时间: " + Number((end_time - start_time) / 1000).toFixed(1) + " 秒"; |
| 193 | - trace(status); | 193 | + log(status); |
| 194 | } | 194 | } |
| 195 | + | ||
| 196 | + private function log(msg:String):void { | ||
| 197 | + trace(msg); | ||
| 198 | + if (ExternalInterface.available) { | ||
| 199 | + ExternalInterface.call("console.log", msg); | ||
| 200 | + } | ||
| 201 | + } | ||
| 195 | } | 202 | } |
| 196 | } | 203 | } |
-
请 注册 或 登录 后发表评论