Hi,
I am trying to collect appstats using this code in main.asc.
What is wrong here?
application.onConnect = function( p_client, p_autoSenseBW )
{
this.acceptConnection(p_client);
nc_poll=new NetConnection();
nc_poll.connect("rtmp://localhost:1111/admin","admin","a1s2d3f4");
nc_poll.call("getAppStats",new onGetAppStats(), "vod");
function onGetAppStats()
{
this.onResult = function(info)
{
trace("POOJA 1111");
outputBox.text = "Info for "+appName.text+ " returned:" + newline;
trace("POOJA 2222");
printObj(info, outputBox);
}
}
function printObj(obj, destination)
{
trace("POOJA 3333");
for (var prop in obj)
{
destination.text += "\t";
destination.text += prop + " = " + obj[prop] + newline;
if (typeof (obj[prop]) == "object")
{
trace("POOJA 4444");
printObj(obj[prop], destination);
}
}
}
}
thanks
1. Wait for the onStatus event from the NetConnection before invoking methods. Otherwise, you may be calling a method on a netconnection that hasn't been completed.
2. Are you defining the nc_poll variable outside of the onConnect method? If not, the scope of nc_poll is the onConnect function, so when the function returns, the nc_poll variable will have gone out of scope, and will be eligible for garbage collection.
Hi JayCharles,
I think onStatus event is received as seen in logs:
| 2012-04-09 | 16:39:05 | 16248 (s)2641173 | ******RECEIVED ONSTATUS****** - |
Main.asc file code is as below, Pls help.
var nc_poll;
application.onConnect = function( p_client, p_autoSenseBW )
{
this.acceptConnection(p_client);
nc_poll=new NetConnection();
nc_poll.onStatus = function(info)
{
trace("******RECEIVED ONSTATUS******");
}
nc_poll.connect("rtmp://localhost:1111/admin","admin","admin123");
function onGetAppStats()
{
this.onResult = function(info)
{
trace("POOJA 1111");
outputBox.text = "Info for "+appName.text+ " returned:" + newline;
trace("POOJA 2222");
printObj(info, outputBox);
}
}
function printObj(obj, destination)
{
trace("POOJA 3333");
for (var prop in obj)
{
destination.text += "\t";
destination.text += prop + " = " + obj[prop] + newline;
if (typeof (obj[prop]) == "object")
{
trace("POOJA 4444");
printObj(obj[prop], destination);
}
}
}
nc_poll.call("getAppStats",new onGetAppStats(), "vod");
}
Thanks Jay, i could write the correct code!!
One query: This is giving stats when onConnect() is called from main.asc.
If i need stats at just any time, where should i call admin api from?
thanks.
var nc_poll;
application.onConnect = function( p_client, p_autoSenseBW )
{
this.acceptConnection(p_client);
nc_poll=new NetConnection();
nc_poll.connect("rtmp://localhost:1111/admin","admin","admin");
nc_poll.onStatus = function(info)
{
if (info.code == "NetConnection.Connect.Success" && nc_poll.isConnected)
{
trace("We are connected");
nc_poll.call("getInstanceStats",new onGetInstanceStats(), "vod/_defInst_");
}
}
function onGetInstanceStats()
{
this.onResult = function(info)
{
trace("POOJA 1111");
var dataobj=info.data;
trace("TOTAL NUMBER OF CONNECTIONS CURRENTLY ACTIVE: " +dataobj.connected);
trace("NUMBER OF CONNECTION ATTEMPTS ACCEPTED BY THIS APPLICATION: "+dataobj.accepted);
trace("NUMBER OF BYTES READ BY THIS APPLICATION: " +dataobj.bytes_in);
trace("NUMBER OF SOCKET CONNECTIONS TO THE APPLICATION SINCE THE APPLICATION WAS STARTED: " +dataobj.total_connects);
trace("POOJA 2222");
}
}
}
North America
Europe, Middle East and Africa
Asia Pacific