PDA

View Full Version : [AS2] Bandwidth Detection


tsj4
12-15-2009, 05:27 AM
I got an instance of a fms 3.5 server online and am attempting to use it to determine a users bandwidth. So far my attempts just return undefined. I connect to the server correctly and I have verified that bandwidthdetection is enabled in the Application.xml file and restarted the server. My test is sandboxed, what else could it be.

TestBandwidth.as

var nc = new NetConnection();
nc.onStatus = netStatusHandler;
nc.connect("rtmp://fms.myserver.org/vod/");

function netStatusHandler(event:Object):Void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
// calls bandwidth detection code built in to the server
// no server-side code required
trace("The connection was made successfully");
nc.call("checkBandwidth", null);
break;
case "NetConnection.Connect.Rejected":
trace ("sorry, the connection was rejected");
break;
case "NetConnection.Connect.Failed":
trace("Failed to connect to server.");
break;
}
}

NetConnection.prototype.onBWDone = function(p_bw) {
trace("BANDWIDTH= "+p_bw);
bandwidth.text = "BANDWIDTH= "+p_bw;
//close the Netconnection to bwcheck
this.close();
};

NetConnection.prototype.onBWCheck = function() {
return ++counter;
};


Application.xml

<Application>
<StreamManager>
<VirtualDirectory>
<!-- Specifies application specific virtual directory mapping for recorded streams. -->
<Streams>/;${VOD_COMMON_DIR}</Streams>
<Streams>/;${VOD_DIR}</Streams>

</VirtualDirectory>
</StreamManager>



<!-- Settings specific to runtime script engine memory -->
<JSEngine>
<!-- This specifies the max size (Kb.) the runtime can grow to before -->
<!-- garbage collection is performed. -->
<RuntimeSize>20480</RuntimeSize>
</JSEngine>


<Client>
<Bandwidth>
<BandwidthDetection enabled="true">
<!-- Specified in bytes/sec -->
<ServerToClient>2500000</ServerToClient>
<!-- Specified in bytes/sec -->
<ClientToServer>2500000</ClientToServer>
</Bandwidth>

<MsgQueue>
<Live>
<!-- Drop live audio if audio q exceeds time specified. time in milliseconds -->
<MaxAudioLatency>2000</MaxAudioLatency>
<!-- Default buffer length in millisecond for live audio and video queue. -->
<MinBufferTime>2000</MinBufferTime>
</Live>
<Recorded>
<!-- Default buffer length in millisecond for live audio and video, value cannot be set below this by Flash player. -->
<MinBufferTime>2000</MinBufferTime>
</Recorded>
<Server>
<!-- Ratio of the buffer length used by server side stream -->
<!-- to live buffer. The value is between 0 and 1. To -->
<!-- avoid break up of audio, the ratio should not be more -->
<!-- than 0.5 of the live buffer. -->
<BufferRatio>0.5</BufferRatio>
</Server>
</MsgQueue>
</Client>




</Application>

tsj4
12-15-2009, 04:19 PM
What was missing was passing an argument in the connect method which tells the server to invoke the bandwidth test. Also I do not believe adding the line to the Application.xml is required

Changed line:

nc.connect("rtmp://fms.myserver.org/vod/", true);


Complete Test:

var nc = new NetConnection();
nc.onStatus = netStatusHandler;
nc.connect("rtmp://fms.myserver.org/vod/", true);

function netStatusHandler(event:Object):Void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
// calls bandwidth detection code built in to the server
// no server-side code required
trace("The connection was made successfully");
nc.call("checkBandwidth", null);
break;
case "NetConnection.Connect.Rejected":
trace ("sorry, the connection was rejected");
break;
case "NetConnection.Connect.Failed":
trace("Failed to connect to server.");
break;
}
}

NetConnection.prototype.onBWDone = function(p_bw) {
trace("BANDWIDTH= "+p_bw);
bandwidth.text = "BANDWIDTH= "+p_bw;
//close the Netconnection to bwcheck
this.close();
};

NetConnection.prototype.onBWCheck = function() {
return ++counter;
};


Outputs:

BANDWIDTH= 109010