Question
NetStream.publish(false) not working on FMS server
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
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
