Skip to main content
February 23, 2009
Question

NetStream.publish(false) not working on FMS server

  • February 23, 2009
  • 4 replies
  • 3496 views
Abstract: I tried to publish netstream I receive at one application under the different name to another application on the same server and then in the end of publishing I tried to remove stream using NetStream.publish(false) command

Here is a code that I use which explains the problem:

var nca = "rtmp://originApp/myInstance";

// When the application starts I opens new connection to another application
// which will be used later for publishing
application.onAppStart = function() {
publishedStreamsList = new Array();
// two parameters used to perform security check on other side
nc.connect(nca, "someIdentifierUsedToSecurityCheck", 12345);
nc.onStatus = function(info) {
if (info.code == "NetConnection.Connect.Success") {
} else {
if (! nc.isConnected) { trace("nc.onStatus - FME, failed"); }
}
}
}

// As soon as new client was connected I accepts connection
// and save reference to net connection opened to remote server on the level of this client
application.onConnect = function( p_client, p_autoSenseBW ) {
this.acceptConnection(p_client);
p_client.nc = nc;
}

// As soon as user publishes stream I create new stream to publish on another application on this server
// besides that I save this new stream in array to execute NetStream.publish(false) command when the user
// stop broadcasting the original one
application.onPublish = function (clientObj, streamObj) {
ns = new NetStream(clientObj.nc);
ns.streamName = "newName"; // save published stream name
ns.originName = streamObj.name; // save original stream name
publishedStreamsList.push(ns);
ns.attach(streamObj);
ns.publish("newName", "live");
}

// When user stops publishing I execute NetStream.publish(false) command and update array of published streams
Client.prototype.FCUnpublish = function( streamname ) {
stopPublishStream(streamname);
removeStreamFromList(streamname);
}

// Find stream which must be stoped
function stopPublishStream(originalStreamName) {

for(var i=0; i< publishedStreamsList.length; i++) {
if(publishedStreamsList .originName == originalStreamName) {
trace("stopPublishStream, originalStreamName - found");
publishedStreamsList
.publish(false);
}
}
}

// Update published streams list
function removeStreamFromList(streamName) {

var tempDir = new Array();
for(var i=0; i< publishedStreamsList.length; i++) {
if(publishedStreamsList .originName == streamName) {
} else {
tempDir.push(publishedStreamsList
);
}
}
publishedStreamsList = new Array();
for(i=0; i< tempDir.length; i++) {
publishedStreamsList.push(tempDir );
}
}
P.S. According to trace outputs everything works and also I able to see the stream after I republish it under the new name on other application, but when the user stops publishing, the stream i published on other application remains on server.
P.S.S. I use Client.prototype.FCUnpublish event, because the original stream published using FME.

I'll appreciate any help guys.

Igor Vasiliev aka The Helmsman
BlogTV Ltd.
www.blogtv.com
    This topic has been closed for replies.

    4 replies

    March 3, 2009
    The forum is playing with your head. I think Igor's code is in fact iterating through the list, but the forum turns [ i ] into the start of italics.
    Participating Frequently
    March 3, 2009
    I just took a quick look at your code. One thing i notice is this:

    for(var i=0; i< publishedStreamsList.length; i++) {
    if(publishedStreamsList.originName == originalStreamName) {
    trace("stopPublishStream, originalStreamName - found");
    publishedStreamsList.publish(false);
    }

    Looks like you're intent is to iterate the list, find the one you want, then unpublish. But your code looks incorrect. First, notice

    if(publishedStreamsList.originName == originalStreamName) {

    this is not checking the elements of publishedStreamsList, it is checking if there is a property on the list itself by the name of originName and checking if that is == originalStreamName. Don't you want to actually index into the list like this,

    if(publishedStreamsList .originName == originalStreamName) {

    Similarly, when you're trying to unpublish, you're not indexing into the list, you're trying to call a method, publish, on the list itself. Shouldn't this be like this,

    publishedStreamsList
    .publish(false);

    Are you even finding the NetStream you want to unpublish. I notice a trace statement in your code. Do you see that trace?
    March 4, 2009
    Actually I iterate through the list, I already mentioned the problems with posting the code on this forum. You need to see the link in order to view the correct code which works on FMS server.

    Now, regarding my problem, I found the solution using some workaround. Now I create new connection on the same server for any stream which I want to publish in another application on the same server, and save the reference to the NetConnection, NetStream and published StreamName into the array. Then as soon as I detect Client.prototype.FCUnpublish event on application which works opposite FME I close connection that corresponds to the stream I published on the another application on the same server which invokes StreamUnpublish and NetConnection close events which I can successfully get on the player side.

    This is possible because we don't have bounds on the amount of opened connection on FMS server and that I connect to another application on the same server (it means that there are no use of traffic).

    Thank you for your responses guys.
    If anyone need the source code which do it, I can publish a link to it.

    Sincerely,
    Igor Vasiliev aka The Helmsman
    BlogTV Ltd.
    www.blogtv.com
    February 25, 2009
    Maybe someone else will jump in here...

    Here's what I see: I don't see you calling nc.publish(false), I see you calling publishedStreamsList.publish(false); -- and isn't publishedStreamsList an array?
    February 26, 2009
    Yes, the problem is in forum parser. After I published the code, it was slightly changed by the forum parser.
    The original code you can view here: http://www.frozenmodule.com/adobeQuestion.txt

    A really appreciate guys for your desire to help me. Thank you very, very much.

    Obviously "attach code" function is disabled for posts in this forum. And looks like when I publish the code here as part of text message, the forum parser interprets content inside [] as command to show either link or emoticon or something else, and as a result of this the AS code looks incorrect.

    Thank you very much guys, but the question remains still open.

    Sincerely,
    Igor Vasiliev aka The Helmsman
    BlogTV Ltd.
    www.blogtv.com
    February 24, 2009
    Hi Igor,

    If you're using AS3, you'll need to call NetStream.close().

    HTH,
    Jody
    February 25, 2009
    This is not an AS 30, this is a script that I run on FMS. According to FMS 30 documentation, in order to stop publishing streaming on remote server I need to use NetStream.publish(false); command. Here is a reference I used: http://www.adobe.com/livedocs/flashmediaserver/3.0/hpdocs/help.html?content=00000349.html#274993

    Any other ideas?