Liverepeater-edge play() problem with invalid stream

Hi, i have a problem in my wowza plataform.

For example:

I have 1 origin server and 1 edge server.

In my edge server i have rtmp://HOST…

When the edge call the origin url if the stream is not valid is possible to give a error “rtmp Failed to play streamname; stream not found”.

I had a plugin that overwrites plays in the edge servers:

public void play(IClient client, RequestFunction function,
			AMFDataList params) {
		if (!ret.getStatus()) {
		
			client.rejectConnection("NetConnection.Connect.Rejected.");
			client.shutdownClient();
		} else {
			ModuleCore.play(client, function, params);
		}

It sounds like you might be looking to dynamically resolve the origin. If this is the case, you might checkout the following IMediaStreamNameAliasProvider2 interface.

One way to check if an origin stream is running is to ask the origin using a Module or HTTPProvider. For example, with a module like this on the origin, a Flash RTMP client could connect to the origin and find out if the stream is live.

package test;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.MediaStreamMap;
public class ModuleCheckStream extends ModuleBase {
	public void isStreamLive(IClient client, RequestFunction function,
			AMFDataList params) {
				
		Boolean streamExists = false; 
		String streamName = getParamString(params, PARAM1);
		
		client.getAppInstance().getPublishStreamNames().contains(streamName);
		
		MediaStreamMap streams = client.getAppInstance().getStreams();
		IMediaStream stream = streams.getStream(streamName);
		
		if (stream != null)
			streamExists = true;
		
		sendResult(client, params, streamExists);
		
	}
}

Or use an HTTPProvider

package test;
import java.io.*;
import java.util.List;
import java.util.Map;
import com.wowza.wms.application.IApplicationInstance;
import com.wowza.wms.http.*;
import com.wowza.wms.logging.*;
import com.wowza.wms.vhost.*;
public class HTTPOriginStreamCheck extends HTTProvider2Base {
	public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
		if (!doHTTPAuthentication(vhost, req, resp))
			return;
		
		String retStr = "false";
		String streamName = "myStream";
		String app = "live";
		
		req.parseBodyForParams(true);
		Map<String, List<String>> params = req.getParameterMap();
		if (params.containsKey("app")) 
			app = params.get("app").get(0);
		
			if (params.containsKey("streamname")) 
				streamName = params.get("streamname").get(0);
				
				IApplicationInstance appInstance = vhost.getApplication(app).getAppInstance("_definst_");
				if (appInstance.getPublishStreamNames().contains(streamName))
				{
					retStr = "true";
				}
		try {
			OutputStream out = resp.getOutputStream();
			byte[] outBytes = retStr.getBytes();
			out.write(outBytes);
		} catch (Exception e) {
			WMSLoggerFactory.getLogger(null).error(
					"HTTPOriginStreamCheck: " + e.toString());
		}
	}
}

Richard

Or you could use resolvePlayAlias in the IMediaStreamNameAliasProvider2 and use the same method to see the stream is published. In this case you will look on the edge. This would give you the opportunity to send a message to the Flash RTMP client (which you can listen for with the NetConnection NetStatusEvent handler), and/or return another stream instead

public String resolvePlayAlias(IApplicationInstance appInstance,
			String name, IClient client) {
		getLogger().info("Resolve Play Flash: " + name);
		
		if (!appInstance.getPublishStreamNames().contains(name))
		{
			sendClientOnStatusError(client, "error.code", "description");// you are sending to the NetConnection in this case rather than the NetStream, which is a little awkward, but if the client is custom you can do whatever you want with notifications 
// OR (instead of line above), you could create a server-side stream and return a reference to it, or have one running (using the scheduler) for this purpose and just return the name 		
			Stream stream = Stream.createInstance(appInstance, "newStream"); // this might already exist, a looping server-side stream you use for filler.
			stream.play("mp4:sample.mp4", 0, -1, true);
			return "newStream";
		}
		
		return name;
	}