Hello Adobe geeks!
I am trying to destroy a NetStream published from client -- application.onUnpublish handler
but I get this error: TypeError: Stream.destroy is not a function
The following example destroys a stream called streamA:
// Get a stream.
streamA = Stream.get("clientStream1");
// Destroy the stream.
Stream.destroy(streamA);
Call Stream.destroy() to unlink and clean up a stream resource.
application.onUnpublish = function (client /*Client*/, stream /*Stream*/) {
trace("Application.onUnpublish > client " + client.userId + " stopped publishing " + stream.name);
Stream.destroy();
}
How can I remove a stream created by user?
Thanks!
T.
Hi,
Thanks for your interest.
Stream.destroy() is a server side function that is available through scripting on the server. I guess you are trying to use it on the NetStream object on the client side which is not possible.
You may need to make a server side stream object for your client's stream and as per the documentation resource you referred, you should be able to destoy the stream.
Hope it helps. Thank you !
Thank you for your reply.
In fact I am using this particular SSAS:
application.onUnpublish = function (client /*Client*/, stream /*Stream*/) {
trace("Application.onUnpublish > client " + client.userId + " stopped publishing " + stream.name);
Stream.destroy(stream);
}
this client side AS3:
sendMulticast = new NetStream(serverConnection, NetStream.CONNECT_TO_FMS);
sendMulticast.addEventListener(NetStatusEvent.NET_STATUS, _onSendMulticastNetStatus, false, 0, true);
sendMulticast.publish("multicast_" + m_nearClientId);
Thanks!
T.
Message was edited by: Tomas_Mirezko, added client side code
Thanks for the code snippet. Even though you are using the Stream.destroy on the server side, you are still trying to destroy a client side stream (which is passed to the onPublish event). I think the Stream.destroy would function only for streams that are made on the server side using Stream.get(). I am not 100 % sure of this but reading the docuementation reference you mentioned above on this thread seems that this is indeed the behavior.
So there is difference between (only in the way they are handled) server side and client side streams. You can create and 'attach' a server side stream like this :
s = Stream.get("serversidestreamj");
s.play("your client side stream ob");
s.anyfunction; (ex : s.record() etc).
and now, this 's' can be destroyed using Stream.destroy but not the client side one.
Let us know if this helps. Thank you !
I updated my code to use Stream.get() first, but it still seems not that Stream.destroy can't be executed, but that my installation doesn't even recognize the function.
SSAS code:
application.onUnpublish = function (client /*Client*/, stream /*Stream*/) {
trace("Application.onUnpublish > client " + client.userId + " stopped publishing " + stream.name);
var s = Stream.get(stream.name);
Stream.destroy(s);
}
error from admin console:
Application.onStatus > code: Application.Script.Error level: error Application.onStatus > + details: C:\Program Files\Adobe\Flash Media Server 4\applications\lobby2\room.asc: line 83: TypeError: Stream.destroy is not a function Sending error message: C:\Program Files\Adobe\Flash Media Server 4\applications\lobby2\room.asc: line 83: TypeError: Stream.destroy is not a function
Error happens when I reload an application and server is reading script file. Is it possible, that my installation doesn't have this method built-in? I've got FMSCore.exe File description: Adobe Flash Media Server 4.0.0.r1121
Reason why I am doing this: When I publish many client streams into one server application, they pile up (and I can see them in Admin console), I wanted to destroy and release resources for all unpublished streams. I understand that while I can see the streams in Admin console, they still exist in server's memory.
Edit #1: here is a screenshot after some clients connect and disconnect, application is empty, but streams are still reserved -- 
North America
Europe, Middle East and Africa
Asia Pacific