Copy link to clipboard
Copied
I want to create an application to switch streams and republish them as single continious stream to the remote server.
In first step I tested "livestreams code" from the "Example of Multipoint publishing" on p. 184 of the "ADOBE®FLASHMEDIA SERVER 4.5® Developer’s Guide" where ns.publish method is used. It was successful.
I try stream.play method now.
I had written main.asc code like in the Stream.play() example on p. 162 of the "Server-Side ACTIONSCRIPT® Language Reference for ADOBE® FLASH® MEDIASERVER 4.5", but I have some problem in spite of this.
I try to broadcast to my local server (to URI - "localhost/studia") by two clients - by FMLE and by my "livestreams" application consequently (with stream name "livestream2") and retraslate it to remote server using my application "studia" on local one.
The connection between two servers (with application "live") appears in the remote server Admin Consol, but the stream from my local server do not come to it.
Here is my main.asc script:
application.myRemoteConn = new NetConnection();
application.myRemoteConn.onStatus = function(info){
trace("Connect " + info.code + "\n");
// Reply to all clients
for (var i = 0; i < application.clients.length; i++){
application.clients.call("onServerStatus", null, info.code, info.description);
}
};
// Use NetConnection object to remote server connect (the remote server works with other application wery well)
application.myRemoteConn.connect("rtmp://RemoteServer/live");
// Server stream estimation
application.myStream = Stream.get("livestream");
application.myStream = Stream.get("livestream");
if (application.myStream){
application.myStream.play("livestream2", 0, -1, true, application.myRemoteConn);
}
Why Stream.play() method do not work?
What I do wrong?
In that case, I recommend you a mix of solution..
Something like this will be interesting to check:
var tempSwitchingStream = Stream.get("myswitchingstream"); // create a temp live stream on local server app..
tempSwitchingStream.play(livestream1, 0, -1); // subscribe tempSwitching to livestream1.. i.e get content of livestream1 into it.. I may also switch to different streams into it..tempSwitchingStream will get content from the //switched stream
if(tempSwitchingStream) // if it exis
...Copy link to clipboard
Copied
This should be fine, but as per your code as I understand
You have a server -> "RemoteServer" which has application "live"
There is a stream being published on "RemoteServer" app "live" named "livestream2" from some source (may be FMLE)
and you are trying to pull the "livestream2" application to this server (where this script is hosted) from "RemoteServer" and play into the the "livestream" which will be on this server (where this application is hosted)..
Right??
So if There are server A and B.. A has application "live" and a stream "1" is being published on it through FMLE.
Now if you want a application "re-live" on server B and which pulls stream "1" from "A" and publishes a stream "2"
You may write this code in application "re-live"
application.myRemoteConn = new NetConnection();
application.myRemoteConn.onStatus = function(info){
trace("Connect " + info.code + "\n");
// Reply to all clients
for (var i = 0; i < application.clients.length; i++){
application.clients.call("onServerStatus", null, info.code, info.description);
}
};
// Use NetConnection object to remote server connect (the remote server works with other application wery well)
application.myRemoteConn.connect("rtmp://A/live");
// Server stream estimation
application.myStream = Stream.get("2");
if (application.myStream){
application.myStream.play("1", 0, -1, true, application.myRemoteConn);
}
Hope it helps
Copy link to clipboard
Copied
I want to clarify (excuse me that I wrote so vague):
This script is in the my local host.
I broadcast from FMLE livestream2 to application "studia" on the local host and I want retranslate the stream named livestream2 by this script (main.asc file in the application/studia folder in the local server) to the application "live" on remote server.
Copy link to clipboard
Copied
Ok , so the above method was basically for the "pulling/proxying" the stream from the some remote server to our local server..
As I understand by your clarification, you want to "push/retranslate" the stream from local server to the remote server...
In that case, you need to multi-point publish..
application.myRemoteConn = new NetConnection();
application.myRemoteConn.onStatus = function(info){
trace("Connect " + info.code + "\n");
// Reply to all clients
for (var i = 0; i < application.clients.length; i++){
application.clients.call("onServerStatus", null, info.code, info.description);
}
};
application.myRemoteConn.connect("rtmp://A/live");
ns = new NetStream(application.myRemoteConn); // create a netstream which will retranslate stream of my choice to this net connection.
// called when the server NetStream object has a status
ns.onStatus = function(info) {
trace("Stream Status: " + info.code)
if (info.code == "NetStream.Publish.Start") {
trace("The stream is now publishing");
}
}
ns.setBufferTime(2);
application.myStream = Stream.get("livestream2"); // get the object of livestream2 being published on this app
if(application.myStream) // if it exist
{
ns.attach(application.myStream); // subscribe my net stream to recieve data from livestream2
ns.publish( livestream, "live" ); // now net stream is getting data from livestream2, so publish that data with name "livestream" on the net connection.. Net stream already know about its NetConnection.. see above
}
Copy link to clipboard
Copied
O.K., Thank you, but can I switch the streams - livestream1, livestream2, livestream3 etc. (that are broadcasted in parallel by number of clients to my local server) for retranslation them consequently and continuously by ns.publish method? And What method I must to use for switching?
Tell me please!
Copy link to clipboard
Copied
In that case, I recommend you a mix of solution..
Something like this will be interesting to check:
var tempSwitchingStream = Stream.get("myswitchingstream"); // create a temp live stream on local server app..
tempSwitchingStream.play(livestream1, 0, -1); // subscribe tempSwitching to livestream1.. i.e get content of livestream1 into it.. I may also switch to different streams into it..tempSwitchingStream will get content from the //switched stream
if(tempSwitchingStream) // if it exist
{
ns.attach(tempSwitchingStream); // subscribe my net stream to recieve data from tempSwitchingStream
ns.publish( livestream, "live" ); // now net stream is getting data from tempSwitchingStream, so publish that data with name "livestream" on the net connection.. Net stream already know about its NetConnection.. see above
}
Did you get the point?? I created a temp stream which may switch stream in its play method and then I am pushing this temp stream to remote server...
However this is little tricky.. Majorly, in most case similar to yours, people write applications on the remote server application to pull the stream and there switch the pulled stream in play method as described in first discussed method..
Copy link to clipboard
Copied
Thank you!
But explain me please, what is "myswitchingstream" in the string "var tempSwitchingStream = Stream.get("myswitchingstream");"?
Where is it must be defined? And where it will be used below in the main.asc code?
I tested this version of code with your point:
var nc;
var ns;
application.onConnect = function(client) {
application.acceptConnection(client);
trace(" client " + client.id + " is connected");
}
// Called when a client disconnects
application.onDisconnect = function(client) {
trace(" client " + client.id + " is disconnected " + new Date());
}
// Called when the client publishes
application.onPublish = function(client, myStream) {
trace("livestream" + " is published by " + application.name);
if (application.name == "livestreams/_definst_"){
trace("The stream is retranslated to: rtmp://remote_host/live");
nc = new NetConnection();
nc.connect( "rtmp:///remote_host/live" );
ns = new NetStream(nc);
// called when the server NetStream object has a status
ns.onStatus = function(info) {
trace("Stream status is: " + info.code)
if (info.code == "NetStream.Publish.Start") {
trace("now livestream is retranslated");
}
}
ns.setBufferTime(2);
var tempSwitchingStream = Stream.get("myswitchingstream"); // create a temp live stream on local server app..
tempSwitchingStream.play(livestream1, 0, -1); // subscribe tempSwitching to livestream1.. i.e get content of livestream1 into it..
if(tempSwitchingStream) // if it exist
{
ns.attach(tempSwitchingStream); // subscribe my net stream to recieve data from tempSwitchingStream
ns.publish( livestream, "live" ); // now net stream is getting data from tempSwitchingStream,
//so publish that data with name "livestream" on the net connection..
//Net stream already know about its NetConnection.. see above
}
}
}
application.onUnpublish = function( client, myStream ) {
trace("Ретрансляция потока livestream остановлена");
}
The application "studia" in my local server has started, but application "live" on remote server does not started and the stream "livestream" does not appear in the administration console log of it.
Where is mistake?
Copy link to clipboard
Copied
"myswitchingstream" is name of the live stream that has been created by you from this application.
Stream.get("X") woks this way-
1. in case livestream with name "X" exist on the server, returns you the reference of it..
2. in case livestream with name "X" doesn't exist on the server, creates a livestream on the server with name "X" and returns you a reference of it..
So in this case, you are creating a livestream "myswitchingstream" on the server and providing it the data from "livestream1" by asking the reference of "myswtichingstream" (which is "tempSwitchingStream" ) to susbscribe to "livestream1" in play method.
Hope this is clear.. You may actually subscribe to (play) "myswitchingstream" from client outside the way you can play "livestream1" .. NetConnection "rtmp://localServer/studia" and stream name "myswitchingStream"..
If you are seeing the connection to "live" appliction on remote server, check the application log of the studia application (inside logs/_defVhost_/studia/application00.log) or core logs inside
Though, I guess in nc.connect .. it should be rtmp://remote_host/live and not rtmp:///remote_host/live (Note number of slashes) ... but I may be wrong.. Just correct this and restart the application..
Copy link to clipboard
Copied
Thank you!
About 3 slashes: this error is only in my last message, but in the main.asc file URL is correct... Sorry!
I broadcasted by FMLE "livestream1" and tested connection with "myswitchingstream" of application "studia" (rtmp://localhost/studia/myswitchingstream) by a copy of the FLVPlayback component - no connection.
The stream "livestream1" appears in the administration console and is perfomed at about 650 mbit/sec.
Connection with rtmp://localhost/studia/livestream1 also does not exist, but connection with rtmp://localhost/live/livestream (when I broadcast to this URL) - is sucсessful.
In the log file (logs/_defVhost_/studia/application00.log) server writes " Sending error message: Method not found (releaseStream)", "Sending error message: Method not found (FCPublish)", "Sending error message: Method not found (FCUnpublish)", but I am not sure, that this is a reason of the our application disfunction.
What is the root of this problem in your opinion?
Copy link to clipboard
Copied
I suggest you to debug, using traces.. Traces must appear in the application log..
For example check if this trace is comming " trace("livestream" + " is published by " + application.name);" if yes, then check for trace("The stream is retranslated to: rtmp://remote_host/live"); .. You may add more trace statements and check which part of application is not working..
For eample once thing I can suspect is check
if (application.name == "livestreams/_definst_"){ |
is your applications name actually livestreams/_definst_ .. I guess it is "studia/_definst_" .. If you are unsure put a trace to print application name..
Copy link to clipboard
Copied
Thank you very mach for your help.
I still debug this code.
I try to trace and subscribe to (play) "myswitchingstream", "livestream1";
"livestream1" is played well,
"myswitchingstream" - unfortunetly unsuccessfully (does not be played);
livestream - also, - does not reach the remote server,
and I don`t undestand why.
Local server log is:
Adobe Flash Media Encoder connected from 127.0.0.1
livestream published by application studia/_definst_
The stream is retranslated to URL: rtmp://Remote_Host/live
myStream.name = myswitchingstream
ns.attach = true
Stream status: NetStream.Connect.Success
Sending error message: Method not found (onBWDone).
Stream status: NetStream.Publish.Start
The stream livestream is retranslated now.
=================================
I have some questions for understanding your point.
One of them:
What parameter I must to write in the handler "application.onPublish" to the streamObj position?
- It was "myStream" erlier (application.onPublish = function(client, myStream), you can look it above).
Is it tempSwitchingStream now?
If it the same parameter (tempSwitchingStream) must be placed in the next strings:
application.onPublish = function(client, tempSwitchingStream) {
tempSwitchingStream = Stream.get("myswitchingstream");
tempSwitchingStream.play("livestream1", 0, -1);
if(tempSwitchingStream) {
ns.attach(tempSwitchingStream); } }
application.onUnpublish = function( client, tempSwitchingStream ) { trace("retranslation of stream livestream was stoped "); }
If yes, may I replace it by "myStream"?
Why ns.attach(tempSwitchingStream) does not work?