Skip to main content
April 4, 2012
Answered

AppStats using onGetAppStats() in main.asc

  • April 4, 2012
  • 1 reply
  • 1232 views

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

This topic has been closed for replies.
Correct answer

You're still calling getAppStats on the connection without being sure the connection is established. Invoke a method outside of onConnect in response to the onStatus event.

1 reply

April 4, 2012

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.

April 9, 2012

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");  

}

Correct answer
April 9, 2012

You're still calling getAppStats on the connection without being sure the connection is established. Invoke a method outside of onConnect in response to the onStatus event.