Skip to main content
Participant
September 2, 2010
Question

Unable to call onFCPublish method

  • September 2, 2010
  • 1 reply
  • 1341 views

Hi,
I am trying to develop a server-side application(
splitterApp) using FMS 3.5.2 which would accept an incoming stream from 3rd Party encoders and publish the stream using FCPublish method to an application(edgeApp) on our edge servers. The splitterApp contains 3 classes for performing the activity. So whenever a incoming stream is received by the splitterApp, the main.asc would create an object of type IncomingStream() and push into unPublished array. A timer based job then picks the unpublished stream from the array and invokes StreamController.PublishStream(). The StreamController.PublishStream() method then creates a new PublishedStream() initialised with incoming stream. The method thereafter calls PublishedStream.PublishStream() to initiate net connection to the edge server application(edgeApp). After successful net connection, I call "this.publish_connection.call ("FCPublish", null,this.thisStream.stream.name)".


The edgeApp accepts the publish and therefore performs:

client.call ("onFCPublish", null,
    {
        code : "NetStream.Publish.Start", description : name
    });


So now when the call reaches splitterApp, I get an error stating "Sending error message: Method not found (onFCPublish)."

Any help or suggestion is much appreciated.

/************ StreamController.asc*************/

StreamController = function ()
{
    //initialisation
    trace ("StreamController initialized");
    this._publishedStreams = new Array ();
}
StreamController.prototype.PublishStream = function (stream)
{
    trace ("StreamController.PublishStream received new stream: " + stream.name);   
    var newStream = new IngressStream (stream);
    newStream.PublishStream ();
    this._publishedStreams.push(newStream);
}
/***************End of StreamController.asc**************/


/*************** PublishedStream.asc**************/
var publish_connection = new NetConnection ();
var publish_netstream;
var fms_pub_url = "rtmp://xxxxxx/xxxxxxxx";
var thisStream;
PublishedStream = function (incomingStream)
{
    this.thisStream = incomingStream;
    trace ("PublishedStream.Initialised for incoming stream " + incomingStream.stream.name);
}
PublishedStream.prototype.PublishStream = function ()
{
    trace ("PublishedStream.PublishStream for incoming stream " + this.thisStream.stream.name);
    this.publish_connection = new NetConnection ();
    this.publish_connection.client = this;   
    var thisObject = this;
    this.publish_connection.onStatus = function (info)
    {
        thisObject.onStatus(info);
    }
    publish_connection.connect (fms_pub_url);
}
PublishedStream.prototype.onStatus= function (e)
{
    trace ("PublishedStream.onStatus:" + e.code);
    if (e.code == "NetConnection.Connect.Success")
    {
         this.publish_connection.client = this;   
        var thisObject = this;
        this.publish_connection.client.onFCPublish = function(info)
        {
            thisObject.onFCPublish(info);
        }
        this.publish_connection.call ("FCPublish", null,this.thisStream.stream.name);
    }
}
PublishedStream.prototype.onFCPublish = function (info)
{
    trace ("PublishedStream.onFCPublish:" + info.code);
    if (info.code == "NetStream.Publish.Start")
    {
        this.publish_netstream = new NetStream (this.publish_connection);
        this.publish_netstream.setBufferTime (2);
        this.publish_netstream.attach (this.thisStream.stream.name);
        this.publish_netstream.publish (this.thisStream.stream.name, "live");
        this.publish_netstream.onStatus = function (infoObject)
        {
            var eventCode = infoObject.code;           
        }
    }
}

/**************************************End of PublishedStream.asc*******************************/

/**************************************IncomingStream.asc************************************/
IncomingStream = function (newClient , newStream)
{
    this.client = newClient;
    this.stream = newStream;
    this.name = this.stream.name;
}
IncomingStream.prototype.ToString = function     ()
{
    var toString = this.stream.name + " from " +this.client.ip;
    return toString;
}
/***************End of IncomingStream.asc****************/

/********************Main.asc of Edge server application***********/
application.onConnect = function (newClient )
{
    var thisClient = newClient;
    //clients send FCPublish to ask for the premission to publish a stream
    newClient.FCPublish = function (name )
    {
        trace ("Inside newClient.FCPublish with name: " + name);
        if (some condition)
        {
            //the stream is already published by another client
            this.call ("onFCPublish", null,
            {
                code : "NetStream.Publish.BadName", description : name
            });
        }
        else
        {
            application.acceptPublish (name, thisClient );
        }
    }   
    return true;
}

application.acceptPublish = function (name, client )
{
    trace ("main:application.acceptPublish: started for " + name);
    client.call ("onFCPublish", null,
    {
        code : "NetStream.Publish.Start", description : name
    });
}
/*************End of Main.asc of Edge server application*****************/


Snippet from the splitterApp log file:

2010-09-02    14:20:35    6724    (s)2641173    StreamController.PublishStream received new stream: dev_stream    -

2010-09-02    14:20:35    6724    (s)2641173    PublishedStream.Initialised for incoming stream dev_stream    -

2010-09-02    14:20:35    6724    (s)2641173    PublishedStream.PublishStream for incoming stream dev_stream    -

2010-09-02    14:20:35    6724    (s)2641173    IngressStream.onStatus for incoming stream dev_stream    -

2010-09-02    14:20:35    6724    (e)2641277    Sending error message: Method not found (onFCPublish).    -

Snippet from the edgeApp log file:

2010-09-02    14:20:35    6724    (s)2641173    Inside newClient.FCPublish with name: dev_stream    -

2010-09-02    14:20:35    6724    (s)2641173    The stream doesnot exists for stream: dev_stream    -

2010-09-02    14:20:35    6724    (s)2641173    main:application.acceptPublish: started for dev_stream    -

Thanks in advance,

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    September 8, 2010

    I did not go through detail and not exactly sure what you are trying and how you are trying them out.

    But just on thought can you change this line :  this.publish_connection.client.onFCPublish to just "this.publish_connection.onFCPublish " and see if that takes care of the error. Server-side code is AS1 , the way you coded is more like AS3 - i don't know how it should pan out.

    sisfmsAuthor
    Participant
    September 10, 2010

    Hi,

    Thanks for your response.


    I did changed the line to "this.publish_connection.onFCPublish", but it started to throw error saying

    ## TypeError : this.publish_connection has no properties ##.

    Therefore I changed in the onStatus function to contain:

    /**************/

        this.publish_connection.client = this;   
            var thisObject = this;
                   
            this.publish_connection.onFCPublish = function(info)
            {
                thisObject.onFCPublish(info);
            }

    /**************/

    And added :

    PublishedStream.prototype.onFCPublish = function (info)
    {
        trace ("
    PublishedStream.onFCPublish:" + info.code);
        trace ("
    PublishedStream.onFCPublish for incoming stream " + this.thisStream.stream.name +" at: "+this.publish_connection.uri);
        if (info.code == "NetStream.Publish.Start")
        {       
            this.publish_netstream = new NetStream (this.publish_connection);
            this.publish_netstream.setBufferTime (2);
            this.publish_netstream.attach (this.thisStream.stream.name);
            this.publish_netstream.publish (this.thisStream.stream.name, "live");
            this.publish_netstream.onStatus = function (infoObject)
            {
                var eventCode = infoObject.code;
                trace ("PublishedStream NetStream.onStatus event: " + infoObject.code);
            }
        }
    }

    Thereby now its able to find the onFCPublish method, but now it seems that the stream is not being published on the other end. The whole code inside onFCPublish gets executed without any error but the stream doesn't seems to appear on the published connection.