mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine bandwidth test
This commit is contained in:
parent
20d1732ced
commit
19f9342034
8 changed files with 322 additions and 171 deletions
|
@ -1,27 +1,136 @@
|
||||||
// for bw to init url
|
/**
|
||||||
// url: scheme://host:port/path?query#fragment
|
* the SrsBandwidth object.
|
||||||
function srs_init_bwt(rtmp_url, hls_url) {
|
* @param container the html container id.
|
||||||
update_nav();
|
* @param width a float value specifies the width of bandwidth.
|
||||||
|
* @param height a float value specifies the height of bandwidth.
|
||||||
if (rtmp_url) {
|
* @param private_object [optional] an object that used as private object,
|
||||||
//var query = parse_query_string();
|
* for example, the logic chat object which owner this bandwidth.
|
||||||
var search_filed = String(window.location.search).replace(" ", "").split("?")[1];
|
*/
|
||||||
$(rtmp_url).val("rtmp://" + window.location.host + ":" + 1935 + "/app?" + search_filed);
|
function SrsBandwidth(container, width, height, private_object) {
|
||||||
}
|
if (!SrsBandwidth.__id) {
|
||||||
if (hls_url) {
|
SrsBandwidth.__id = 100;
|
||||||
$(hls_url).val(build_default_hls_url());
|
|
||||||
}
|
}
|
||||||
|
if (!SrsBandwidth.__bandwidths) {
|
||||||
|
SrsBandwidth.__bandwidths = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function srs_bwt_check_url(url) {
|
SrsBandwidth.__bandwidths.push(this);
|
||||||
if (url.indexOf("key") != -1 && url.indexOf("vhost") != -1) {
|
|
||||||
return true;
|
this.private_object = private_object;
|
||||||
|
this.container = container;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.id = SrsBandwidth.__id++;
|
||||||
|
this.stream_url = null;
|
||||||
|
this.callbackObj = null;
|
||||||
|
|
||||||
|
// the callback set data.
|
||||||
|
this.percent = 0;
|
||||||
|
this.status = "";
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* user can set some callback, then start the bandwidth.
|
||||||
|
* @param url the bandwidth test url.
|
||||||
|
* callbacks:
|
||||||
|
* on_bandwidth_ready():void, when srs bandwidth ready, user can play.
|
||||||
|
* on_update_progress(percent:Number):void, when srs bandwidth update the progress.
|
||||||
|
* percent:Number 100 means 100%.
|
||||||
|
* on_update_status(status:String):void, when srs bandwidth update the status.
|
||||||
|
* status:String the human readable status text.
|
||||||
|
*/
|
||||||
|
SrsBandwidth.prototype.start = function(url) {
|
||||||
|
if (url) {
|
||||||
|
this.stream_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
// embed the flash.
|
||||||
|
var flashvars = {};
|
||||||
|
flashvars.id = this.id;
|
||||||
|
flashvars.on_bandwidth_ready = "__srs_on_bandwidth_ready";
|
||||||
|
flashvars.on_update_progress = "__srs_on_update_progress";
|
||||||
|
flashvars.on_update_status = "__srs_on_update_status";
|
||||||
|
|
||||||
|
var params = {};
|
||||||
|
params.wmode = "opaque";
|
||||||
|
params.allowFullScreen = "true";
|
||||||
|
params.allowScriptAccess = "always";
|
||||||
|
|
||||||
|
var attributes = {};
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
swfobject.embedSWF(
|
||||||
|
"srs_bwt/release/srs_bwt.swf?_version="+srs_get_version_code(),
|
||||||
|
this.container,
|
||||||
|
this.width, this.height,
|
||||||
|
"11.1.0", "js/AdobeFlashbandwidthInstall.swf",
|
||||||
|
flashvars, params, attributes,
|
||||||
|
function(callbackObj){
|
||||||
|
self.callbackObj = callbackObj;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* play the stream.
|
||||||
|
* @param stream_url the url of stream, rtmp or http.
|
||||||
|
* @param volume the volume, 0 is mute, 1 is 100%, 2 is 200%.
|
||||||
|
*/
|
||||||
|
SrsBandwidth.prototype.check_bandwidth = function(url) {
|
||||||
|
this.stop();
|
||||||
|
SrsBandwidth.__bandwidths.push(this);
|
||||||
|
|
||||||
|
if (url) {
|
||||||
|
this.stream_url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function srs_bwt_build_default_url() {
|
this.callbackObj.ref.__check_bandwidth(this.stream_url);
|
||||||
var url_default = "rtmp://" + window.location.host + ":" + 1935 + "/app?key=35c9b402c12a7246868752e2878f7e0e&vhost=bandcheck.srs.com";
|
}
|
||||||
return url_default;
|
SrsBandwidth.prototype.stop = function(url) {
|
||||||
|
for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) {
|
||||||
|
var bandwidth = SrsBandwidth.__bandwidths[i];
|
||||||
|
|
||||||
|
if (bandwidth.id != this.id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SrsBandwidth.__bandwidths.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.callbackObj.ref.__stop();
|
||||||
|
}
|
||||||
|
SrsBandwidth.prototype.on_bandwidth_ready = function() {
|
||||||
|
}
|
||||||
|
SrsBandwidth.prototype.on_update_progress = function(percent) {
|
||||||
|
}
|
||||||
|
SrsBandwidth.prototype.on_update_status = function(status) {
|
||||||
|
}
|
||||||
|
function __srs_find_bandwidth(id) {
|
||||||
|
for (var i = 0; i < SrsBandwidth.__bandwidths.length; i++) {
|
||||||
|
var bandwidth = SrsBandwidth.__bandwidths[i];
|
||||||
|
|
||||||
|
if (bandwidth.id != id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bandwidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("bandwidth not found. id=" + id);
|
||||||
|
}
|
||||||
|
function __srs_on_bandwidth_ready(id) {
|
||||||
|
var bandwidth = __srs_find_bandwidth(id);
|
||||||
|
bandwidth.on_bandwidth_ready();
|
||||||
|
}
|
||||||
|
function __srs_on_update_progress(id, percent) {
|
||||||
|
var bandwidth = __srs_find_bandwidth(id);
|
||||||
|
bandwidth.percent = percent;
|
||||||
|
bandwidth.on_update_progress(percent);
|
||||||
|
}
|
||||||
|
function __srs_on_update_status(id, status) {
|
||||||
|
var bandwidth = __srs_find_bandwidth(id);
|
||||||
|
bandwidth.status = status;
|
||||||
|
bandwidth.on_update_status(status);
|
||||||
}
|
}
|
|
@ -80,6 +80,18 @@ function build_default_publish_rtmp_url() {
|
||||||
return "rtmp://" + server + ":" + port + "/" + app + "...vhost..." + vhost + "/" + stream;
|
return "rtmp://" + server + ":" + port + "/" + app + "...vhost..." + vhost + "/" + stream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// for the bandwidth tool to init page
|
||||||
|
function build_default_bandwidth_rtmp_url() {
|
||||||
|
var query = parse_query_string();
|
||||||
|
|
||||||
|
var server = (query.server == undefined)? window.location.hostname:query.server;
|
||||||
|
var port = (query.port == undefined)? 1935:query.port;
|
||||||
|
var vhost = (query.vhost == undefined)? "bandcheck.srs.com":query.vhost;
|
||||||
|
var app = (query.app == undefined)? "app":query.app;
|
||||||
|
var key = (query.key == undefined)? "35c9b402c12a7246868752e2878f7e0e":query.key;
|
||||||
|
|
||||||
|
return "rtmp://" + server + ":" + port + "/" + app + "?key=" + key + "&vhost=" + vhost;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@param server the ip of server. default to window.location.hostname
|
@param server the ip of server. default to window.location.hostname
|
||||||
|
@ -139,6 +151,15 @@ function srs_init_publish(rtmp_url) {
|
||||||
$(rtmp_url).val(build_default_publish_rtmp_url());
|
$(rtmp_url).val(build_default_publish_rtmp_url());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// for bw to init url
|
||||||
|
// url: scheme://host:port/path?query#fragment
|
||||||
|
function srs_init_bwt(rtmp_url, hls_url) {
|
||||||
|
update_nav();
|
||||||
|
|
||||||
|
if (rtmp_url) {
|
||||||
|
$(rtmp_url).val(build_default_bandwidth_rtmp_url());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check whether can republish
|
// check whether can republish
|
||||||
function srs_can_republish() {
|
function srs_can_republish() {
|
||||||
|
|
|
@ -63,7 +63,7 @@ SrsPlayer.prototype.start = function(url) {
|
||||||
"srs_player/release/srs_player.swf?_version="+srs_get_version_code(),
|
"srs_player/release/srs_player.swf?_version="+srs_get_version_code(),
|
||||||
this.container,
|
this.container,
|
||||||
this.width, this.height,
|
this.width, this.height,
|
||||||
"11.1", "js/AdobeFlashPlayerInstall.swf",
|
"11.1.0", "js/AdobeFlashPlayerInstall.swf",
|
||||||
flashvars, params, attributes,
|
flashvars, params, attributes,
|
||||||
function(callbackObj){
|
function(callbackObj){
|
||||||
self.callbackObj = callbackObj;
|
self.callbackObj = callbackObj;
|
||||||
|
|
|
@ -73,7 +73,7 @@ SrsPublisher.prototype.start = function() {
|
||||||
"srs_publisher/release/srs_publisher.swf?_version="+srs_get_version_code(),
|
"srs_publisher/release/srs_publisher.swf?_version="+srs_get_version_code(),
|
||||||
this.container,
|
this.container,
|
||||||
this.width, this.height,
|
this.width, this.height,
|
||||||
"11.1", "js/AdobeFlashPlayerInstall.swf",
|
"11.1.0", "js/AdobeFlashPlayerInstall.swf",
|
||||||
flashvars, params, attributes,
|
flashvars, params, attributes,
|
||||||
function(callbackObj){
|
function(callbackObj){
|
||||||
self.callbackObj = callbackObj;
|
self.callbackObj = callbackObj;
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
<script type="text/javascript" src="js/srs.log.js"></script>
|
<script type="text/javascript" src="js/srs.log.js"></script>
|
||||||
<script type="text/javascript" src="js/srs.player.js"></script>
|
<script type="text/javascript" src="js/srs.player.js"></script>
|
||||||
<script type="text/javascript" src="js/srs.publisher.js"></script>
|
<script type="text/javascript" src="js/srs.publisher.js"></script>
|
||||||
<script type="text/javascript" src="js/srs.utility.js"></script>
|
|
||||||
<script type="text/javascript" src="js/srs.utility.js"></script>
|
<script type="text/javascript" src="js/srs.utility.js"></script>
|
||||||
<script type="text/javascript" src="js/srs.bandwidth.js"></script>
|
<script type="text/javascript" src="js/srs.bandwidth.js"></script>
|
||||||
<style>
|
<style>
|
||||||
|
@ -19,106 +18,54 @@
|
||||||
padding-top: 55px;
|
padding-top: 55px;
|
||||||
}
|
}
|
||||||
#main_modal {
|
#main_modal {
|
||||||
width: 600px;
|
width: 700px;
|
||||||
margin-left: -300px;
|
margin-left: -350px;
|
||||||
}
|
|
||||||
#check_status {
|
|
||||||
margin-left: 20px;
|
|
||||||
margin-top: -55px;
|
|
||||||
}
|
|
||||||
#pb_buffer_bg {
|
|
||||||
margin-top: 40px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
var bandwidth = null;
|
||||||
function update_progress(percent) {
|
|
||||||
$("#progress_bar").width(percent);
|
|
||||||
}
|
|
||||||
|
|
||||||
function progress_reset() {
|
|
||||||
$("#progress_bar").width("0%");
|
|
||||||
}
|
|
||||||
|
|
||||||
function update_status(text) {
|
|
||||||
$("#check_status").text(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_swf_width() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_swf_height() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function show_modal() {
|
|
||||||
$("#main_modal").modal({show:true, keyboard:false});
|
|
||||||
}
|
|
||||||
|
|
||||||
function band_check(url) {
|
|
||||||
|
|
||||||
// remove flash contet
|
|
||||||
var bw_div = $("<div/>");
|
|
||||||
$(bw_div).attr("id", "bw_div");
|
|
||||||
$("#bw_center").append(bw_div);
|
|
||||||
|
|
||||||
var flashvars = {};
|
|
||||||
flashvars.url = url;
|
|
||||||
flashvars.update_progress = "update_progress";
|
|
||||||
flashvars.progress_reset = "progress_reset";
|
|
||||||
flashvars.update_status = "update_status";
|
|
||||||
|
|
||||||
var params = {};
|
|
||||||
params.allowFullScreen = true;
|
|
||||||
|
|
||||||
var attributes = {};
|
|
||||||
|
|
||||||
swfobject.embedSWF(
|
|
||||||
"srs_bwt/release/srs_bwt.swf", "bw_div",
|
|
||||||
get_swf_width(), get_swf_height(),
|
|
||||||
"11.1.0", "js/AdobeFlashPlayerInstall.swf",
|
|
||||||
flashvars, params, attributes
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
update_nav();
|
|
||||||
srs_init_bwt("#txt_url");
|
srs_init_bwt("#txt_url");
|
||||||
|
|
||||||
var txt_input = $("#txt_url").val();
|
$("#btn_play").click(on_click_play);
|
||||||
// if valid ?
|
$("#main_modal").on("show", on_start_bandwidth_test);
|
||||||
if (!srs_bwt_check_url(txt_input)) {
|
$("#main_modal").on("hide", on_stop_bandwidth_test);
|
||||||
$("#txt_url").val(srs_bwt_build_default_url());
|
|
||||||
}
|
|
||||||
|
|
||||||
$("#main_modal").on(
|
|
||||||
"show",
|
|
||||||
function()
|
|
||||||
{
|
|
||||||
progress_reset();
|
|
||||||
update_status("");
|
|
||||||
var url = $("#txt_url").val();
|
|
||||||
/*!
|
|
||||||
url encode
|
|
||||||
*/
|
|
||||||
url = escape(url);
|
|
||||||
band_check(url);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$("#main_modal").on("hide", function(){
|
|
||||||
$("#bw_div").remove();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#btn_play").click(
|
function on_click_play() {
|
||||||
function()
|
$("#check_status").text("");
|
||||||
{
|
$("#progress_bar").width("0%");
|
||||||
$("#main_modal").modal({show:true, keyboard:false});
|
$("#main_modal").modal({show:true, keyboard:false});
|
||||||
}
|
}
|
||||||
);
|
function on_start_bandwidth_test() {
|
||||||
});
|
$("#div_container").remove();
|
||||||
|
|
||||||
|
var div_container = $("<div/>");
|
||||||
|
$(div_container).attr("id", "div_container");
|
||||||
|
$("#player").append(div_container);
|
||||||
|
|
||||||
|
var player = $("<div/>");
|
||||||
|
$(player).attr("id", "player_id");
|
||||||
|
$(div_container).append(player);
|
||||||
|
|
||||||
|
var url = $("#txt_url").val();
|
||||||
|
|
||||||
|
bandwidth = new SrsBandwidth("player_id", 100, 1);
|
||||||
|
bandwidth.on_bandwidth_ready = function() {
|
||||||
|
this.check_bandwidth(url);
|
||||||
|
}
|
||||||
|
bandwidth.on_update_progress = function(percent) {
|
||||||
|
$("#progress_bar").width(percent + "%");
|
||||||
|
}
|
||||||
|
bandwidth.on_update_status = function(status) {
|
||||||
|
$("#check_status").text(status);
|
||||||
|
}
|
||||||
|
bandwidth.start(url);
|
||||||
|
}
|
||||||
|
function on_stop_bandwidth_test() {
|
||||||
|
bandwidth.stop();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -141,38 +88,43 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
<div class="alert alert-info fade in">
|
||||||
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
|
<strong><span>Usage:</span></strong> <span>点击“开始测速”即可测带宽,最大可测试带宽由服务器限制</span>
|
||||||
|
</div>
|
||||||
<div class="form-inline">
|
<div class="form-inline">
|
||||||
URL:
|
URL:
|
||||||
<input type="text" id="txt_url" class="input-xxlarge" value="" placeholder="例如:rtmp://host:port/app?key=xx&vhost=yy"></input>
|
<input type="text" id="txt_url" class="input-xxlarge" value=""></input>
|
||||||
<button class="btn btn-primary" id="btn_play">开始测速</button>
|
<button class="btn btn-primary" id="btn_play">开始测速</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main_modal" class="modal hide fade">
|
<div id="main_modal" class="modal hide fade">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
<h3>SRS Band Check</h3>
|
<h3>SRS Bandwidth Check</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div id="player"></div>
|
<div class="row-fluid">
|
||||||
|
<div class="span1"></div>
|
||||||
|
<div class="span10">
|
||||||
<div class="progress progress-striped active" id="pb_buffer_bg">
|
<div class="progress progress-striped active" id="pb_buffer_bg">
|
||||||
<div class="bar" style="width: 50%;" id="progress_bar"></div>
|
<div class="bar" style="width: 0%;" id="progress_bar"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="span1"></div>
|
||||||
<div class="modal-body" id="bw_center">
|
</div>
|
||||||
|
<span id="check_status">status</span>
|
||||||
</div>
|
</div>
|
||||||
<span id="check_status1"><font ><strong id="check_status">status</strong></font> </span>
|
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
|
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true"> 关闭 </button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<footer>
|
<footer>
|
||||||
<p><a href="https://github.com/winlinvip/simple-rtmp-server">SRS Team © 2013</a></p>
|
<p><a href="https://github.com/winlinvip/simple-rtmp-server">SRS Team © 2013</a></p>
|
||||||
</footer>
|
</footer>
|
||||||
|
<div class="container">
|
||||||
|
<div id="player"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<actionScriptProperties analytics="false" mainApplicationPath="srs_bwt.as" projectUUID="00251213-e6a2-4dd5-a033-125cc78f843c" version="10">
|
<actionScriptProperties analytics="false" mainApplicationPath="srs_bwt.as" projectUUID="00251213-e6a2-4dd5-a033-125cc78f843c" version="10">
|
||||||
<compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="true" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="bin-debug" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
|
<compiler additionalCompilerArguments="-locale en_US" autoRSLOrdering="true" copyDependentFiles="true" fteInMXComponents="false" generateAccessible="true" htmlExpressInstall="true" htmlGenerate="false" htmlHistoryManagement="true" htmlPlayerVersionCheck="true" includeNetmonSwc="false" outputFolderPath="release" removeUnusedRSL="true" sourceFolderPath="src" strict="true" targetPlayerVersion="0.0.0" useApolloConfig="false" useDebugRSLSwfs="true" verifyDigests="true" warn="true">
|
||||||
<compilerSourcePath/>
|
<compilerSourcePath/>
|
||||||
<libraryPath defaultLinkType="0">
|
<libraryPath defaultLinkType="0">
|
||||||
<libraryPathEntry kind="4" path="">
|
<libraryPathEntry kind="4" path="">
|
||||||
|
@ -17,13 +17,13 @@
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/sparkskins.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/sparkskins.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/rpc.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/rpc.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/>
|
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/>
|
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/datavisualization.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/datavisualization.swc" useDefaultLinkType="false"/>
|
||||||
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/qtp_air.swc" useDefaultLinkType="false"/>
|
||||||
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/videoPlayer.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/spark_dmv.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/>
|
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_dmv.swc" useDefaultLinkType="false"/>
|
||||||
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/flash-integration.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_flashflexkit.swc" useDefaultLinkType="false"/>
|
||||||
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/>
|
<libraryPathEntry kind="3" linkType="1" path="${PROJECT_FRAMEWORKS}/libs/automation_agent.swc" useDefaultLinkType="false"/>
|
||||||
</excludedEntries>
|
</excludedEntries>
|
||||||
|
|
Binary file not shown.
|
@ -20,10 +20,15 @@ package
|
||||||
|
|
||||||
public class srs_bwt extends Sprite
|
public class srs_bwt extends Sprite
|
||||||
{
|
{
|
||||||
private var connection:NetConnection;
|
private var connection:NetConnection = null;
|
||||||
|
|
||||||
private var updatePlayProgressTimer:Timer;
|
private var updatePlayProgressTimer:Timer = null;
|
||||||
private var elapTimer:SrsElapsedTimer;
|
private var elapTimer:SrsElapsedTimer = null;
|
||||||
|
|
||||||
|
// user set id.
|
||||||
|
private var js_id:String = null;
|
||||||
|
// play param url.
|
||||||
|
private var user_url:String = null;
|
||||||
|
|
||||||
// server ip get from server
|
// server ip get from server
|
||||||
private var server_ip:String;
|
private var server_ip:String;
|
||||||
|
@ -32,8 +37,8 @@ package
|
||||||
private var stop_pub:Boolean = false;
|
private var stop_pub:Boolean = false;
|
||||||
|
|
||||||
// js interface
|
// js interface
|
||||||
|
private var js_on_player_ready:String;
|
||||||
private var js_update_progress:String;
|
private var js_update_progress:String;
|
||||||
private var js_progress_reset:String;
|
|
||||||
private var js_update_status:String;
|
private var js_update_status:String;
|
||||||
|
|
||||||
private var value_progressbar:Number = 0;
|
private var value_progressbar:Number = 0;
|
||||||
|
@ -44,25 +49,66 @@ package
|
||||||
|
|
||||||
public function srs_bwt()
|
public function srs_bwt()
|
||||||
{
|
{
|
||||||
|
if (!this.stage) {
|
||||||
|
this.addEventListener(Event.ADDED_TO_STAGE, this.system_on_add_to_stage);
|
||||||
|
} else {
|
||||||
|
this.system_on_add_to_stage(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* system event callback, when this control added to stage.
|
||||||
|
* the main function.
|
||||||
|
*/
|
||||||
|
private function system_on_add_to_stage(evt:Event):void {
|
||||||
this.stage.scaleMode = StageScaleMode.NO_SCALE;
|
this.stage.scaleMode = StageScaleMode.NO_SCALE;
|
||||||
this.stage.align = StageAlign.TOP_LEFT;
|
this.stage.align = StageAlign.TOP_LEFT;
|
||||||
|
|
||||||
var flashvars:Object = this.root.loaderInfo.parameters;
|
var flashvars:Object = this.root.loaderInfo.parameters;
|
||||||
this.js_update_progress = flashvars.update_progress;
|
|
||||||
this.js_progress_reset = flashvars.progress_reset;
|
|
||||||
this.js_update_status = flashvars.update_status;
|
|
||||||
|
|
||||||
// init context menu, add action "Srs 带宽测试工具 0.1"
|
if (!flashvars.hasOwnProperty("id")) {
|
||||||
|
throw new Error("must specifies the id");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.js_id = flashvars.id;
|
||||||
|
this.js_on_player_ready = flashvars.on_bandwidth_ready;
|
||||||
|
this.js_update_progress = flashvars.on_update_progress;
|
||||||
|
this.js_update_status = flashvars.on_update_status;
|
||||||
|
|
||||||
|
// init context menu
|
||||||
var myMenu:ContextMenu = new ContextMenu();
|
var myMenu:ContextMenu = new ContextMenu();
|
||||||
myMenu.hideBuiltInItems();
|
myMenu.hideBuiltInItems();
|
||||||
myMenu.customItems.push(new ContextMenuItem("Srs 带宽测试工具 0.1", true));
|
myMenu.customItems.push(new ContextMenuItem("SRS 带宽测试工具", true));
|
||||||
this.contextMenu = myMenu;
|
this.contextMenu = myMenu;
|
||||||
|
|
||||||
|
flash.utils.setTimeout(this.system_on_js_ready, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* system callack event, when js ready, register callback for js.
|
||||||
|
* the actual main function.
|
||||||
|
*/
|
||||||
|
private function system_on_js_ready():void {
|
||||||
|
if (!flash.external.ExternalInterface.available) {
|
||||||
|
trace("js not ready, try later.");
|
||||||
|
flash.utils.setTimeout(this.system_on_js_ready, 100);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
flash.external.ExternalInterface.addCallback("__check_bandwidth", this.js_call_check_bandwidth);
|
||||||
|
flash.external.ExternalInterface.addCallback("__stop", this.js_call_stop);
|
||||||
|
|
||||||
|
flash.external.ExternalInterface.call(this.js_on_player_ready, this.js_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function js_call_check_bandwidth(url:String):void {
|
||||||
|
js_call_stop();
|
||||||
|
|
||||||
// init connection
|
// init connection
|
||||||
connection = new NetConnection;
|
connection = new NetConnection;
|
||||||
connection.client = this;
|
connection.client = this;
|
||||||
connection.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
|
connection.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
|
||||||
connection.connect(flashvars.url);
|
connection.connect(url);
|
||||||
//connection.connect("rtmp://192.168.8.234:1935/app?key=35c9b402c12a7246868752e2878f7e0e&vhost=bandcheck.srs.com");
|
//connection.connect("rtmp://192.168.8.234:1935/app?key=35c9b402c12a7246868752e2878f7e0e&vhost=bandcheck.srs.com");
|
||||||
|
|
||||||
// for play to update progress bar
|
// for play to update progress bar
|
||||||
|
@ -73,10 +119,36 @@ package
|
||||||
updatePlayProgressTimer.addEventListener(TimerEvent.TIMER, onTimerTimeout);
|
updatePlayProgressTimer.addEventListener(TimerEvent.TIMER, onTimerTimeout);
|
||||||
updatePlayProgressTimer.start();
|
updatePlayProgressTimer.start();
|
||||||
}
|
}
|
||||||
|
private function js_call_stop():void {
|
||||||
|
if (connection) {
|
||||||
|
connection.close();
|
||||||
|
connection = null;
|
||||||
|
}
|
||||||
|
if (updatePlayProgressTimer) {
|
||||||
|
updatePlayProgressTimer.stop();
|
||||||
|
updatePlayProgressTimer = null;
|
||||||
|
}
|
||||||
|
if (elapTimer) {
|
||||||
|
elapTimer.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get NetConnection NetStatusEvent
|
// get NetConnection NetStatusEvent
|
||||||
public function onStatus(evt:NetStatusEvent) : void{
|
public function onStatus(evt:NetStatusEvent) : void{
|
||||||
trace(evt.info.code);
|
trace(evt.info.code);
|
||||||
|
|
||||||
|
if (evt.info.hasOwnProperty("data") && evt.info.data) {
|
||||||
|
// for context menu
|
||||||
|
var customItems:Array = [new ContextMenuItem("SrsPlayer")];
|
||||||
|
if (evt.info.data.hasOwnProperty("srs_server")) {
|
||||||
|
customItems.push(new ContextMenuItem("Server: " + evt.info.data.srs_server));
|
||||||
|
}
|
||||||
|
if (evt.info.data.hasOwnProperty("srs_contributor")) {
|
||||||
|
customItems.push(new ContextMenuItem("Contributor: " + evt.info.data.srs_contributor));
|
||||||
|
}
|
||||||
|
contextMenu.customItems = customItems;
|
||||||
|
}
|
||||||
|
|
||||||
switch(evt.info.code){
|
switch(evt.info.code){
|
||||||
case "NetConnection.Connect.Failed":
|
case "NetConnection.Connect.Failed":
|
||||||
updateState("连接服务器失败!");
|
updateState("连接服务器失败!");
|
||||||
|
@ -92,7 +164,12 @@ package
|
||||||
//updateState("连接已断开!");
|
//updateState("连接已断开!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onTimerTimeout(evt:TimerEvent):void
|
||||||
|
{
|
||||||
|
value_progressbar = elapTimer.elapsed();
|
||||||
|
updateProgess(value_progressbar, max_progressbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -104,20 +181,13 @@ package
|
||||||
var interval_ms:Number = evt.interval_ms;
|
var interval_ms:Number = evt.interval_ms;
|
||||||
|
|
||||||
connection.call("onSrsBandCheckStartingPlayBytes", null);
|
connection.call("onSrsBandCheckStartingPlayBytes", null);
|
||||||
updateState("测试下行带宽(" + server_ip + ")");
|
updateState("开始测试下行带宽,服务器IP:" + server_ip);
|
||||||
|
|
||||||
// we suppose play duration_ms = pub duration_ms
|
// we suppose play duration_ms = pub duration_ms
|
||||||
max_progressbar = duration_ms * 2;
|
max_progressbar = duration_ms * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSrsBandCheckPlaying(evt:Object):void{
|
public function onSrsBandCheckPlaying(evt:Object):void{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onTimerTimeout(evt:TimerEvent):void
|
|
||||||
{
|
|
||||||
value_progressbar = elapTimer.elapsed();
|
|
||||||
updateProgess(value_progressbar, max_progressbar);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onSrsBandCheckStopPlayBytes(evt:Object):void{
|
public function onSrsBandCheckStopPlayBytes(evt:Object):void{
|
||||||
|
@ -133,6 +203,7 @@ package
|
||||||
kbps = (int(kbps * 10))/10.0;
|
kbps = (int(kbps * 10))/10.0;
|
||||||
|
|
||||||
flash.utils.setTimeout(stopPlayTest, 0);
|
flash.utils.setTimeout(stopPlayTest, 0);
|
||||||
|
updateState("下行带宽测试完毕:" + kbps + "kbps,开始测试上行带宽。");
|
||||||
}
|
}
|
||||||
|
|
||||||
private function stopPlayTest():void{
|
private function stopPlayTest():void{
|
||||||
|
@ -144,7 +215,6 @@ package
|
||||||
var interval_ms:Number = evt.interval_ms;
|
var interval_ms:Number = evt.interval_ms;
|
||||||
|
|
||||||
connection.call("onSrsBandCheckStartingPublishBytes", null);
|
connection.call("onSrsBandCheckStartingPublishBytes", null);
|
||||||
updateState("测试上行带宽(" + server_ip + ")");
|
|
||||||
|
|
||||||
flash.utils.setTimeout(publisher, 0);
|
flash.utils.setTimeout(publisher, 0);
|
||||||
}
|
}
|
||||||
|
@ -208,20 +278,19 @@ package
|
||||||
connection.call("finalClientPacket", null);
|
connection.call("finalClientPacket", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBWDone():void{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
// update progressBar's value
|
// update progressBar's value
|
||||||
private function updateProgess(value:Number, maxValue:Number):void{
|
private function updateProgess(value:Number, maxValue:Number):void{
|
||||||
flash.external.ExternalInterface.call(this.js_update_progress, value * 100 / maxValue + "%");
|
flash.external.ExternalInterface.call(this.js_update_progress, this.js_id, value * 100 / maxValue);
|
||||||
trace(value + "-" + maxValue + "-" + value * 100 / maxValue + "%");
|
trace(value + "-" + maxValue + "-" + value * 100 / maxValue + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
// update checking status
|
// update checking status
|
||||||
private function updateState(text:String):void{
|
private function updateState(text:String):void{
|
||||||
flash.external.ExternalInterface.call(this.js_update_status, text);
|
flash.external.ExternalInterface.call(this.js_update_status, this.js_id, text);
|
||||||
trace(text);
|
trace(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onBWDone():void{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue