• How to block a duplicate publish stream (ModuleBlockDuplicateStreamNames)

    You can override releaseStream to authorize a stream that is being published. This module checks to see if a stream with the same name is already being published and does not publish it if there is such a stream. If a stream with the same name is not in the process of being published, the new stream will take precedence, and clients subscribing to that stream will start seeing the new, second stream.

    Note: This module has been removed from the Wowza Module Collection because the same functionality has been added to Wowza Streaming Engine™ software. See Source Security > Duplicate Stream Names. The source code has been retained here for reference.
    package com.wowza.wms.example.module;
    
    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.*;
    import com.wowza.wms.util.*;
    import com.wowza.wms.application.*;
    
    public class ModuleBlockDuplicateStreamNames extends ModuleBase
    {
    	IApplicationInstance appInstance = null;
    	
    	public void onAppStart(IApplicationInstance appInstance)
    	{
    		this.appInstance = appInstance;
    	}
    	
    	public void publish(IClient client, RequestFunction function, AMFDataList params)
    	{
    		String streamName = extractStreamName(client, function, params);
    		if (isDuplicateStream(client, streamName))
    		{
    			getLogger().info("ModuleBlockDuplicateStreamNames.publish["+appInstance.getContextStr()+"]: Stream name is already in use: "+streamName);
    			IMediaStream stream = getStream(client, function);
    			sendStreamOnStatusError(stream, "NetStream.Publish.BadName", "Stream name is already in use: "+streamName);
    		}
    		else
    			invokePrevious(client, function, params);
    	}
    
    	public void releaseStream(IClient client, RequestFunction function, AMFDataList params)
    	{
    		String streamName = extractStreamName(client, function, params);
    		if (!isDuplicateStream(client, streamName))
    			invokePrevious(client, function, params);
    	}
    
    	public String extractStreamName(IClient client, RequestFunction function, AMFDataList params)
    	{
    		String streamName = params.getString(PARAM1);
    		if (streamName != null)
    		{
    			String streamExt = MediaStream.BASE_STREAM_EXT;
    			
    			String[] streamDecode = ModuleUtils.decodeStreamExtension(streamName, streamExt);
    			streamName = streamDecode[0];
    			streamExt = streamDecode[1];
    			
    			streamName = streamName.split("\?")[0];
    		}
    
    		return streamName;
    	}
    	
    	public boolean isDuplicateStream(IClient client, String streamName)
    	{
    		if (streamName != null)
    			return client.getAppInstance().getStreams().getStream(streamName) != null;
    		
    		return false;
    	}
    
    }
    Add this module last in the list of modules in the /conf/[app-name]/Application.xml file.

    <Module>
    	<Name>ModuleBlockDuplicateStreamNames</Name>
    	<Description>ModuleBlockDuplicateStreamNames</Description>
    	<Class>com.wowza.wms.example.module.ModuleBlockDuplicateStreamNames</Class>
    </Module>

    Wowza media server server software and all components, including modules, source code, and other related items offered on this page, are copyrighted (c) 2006-2014 by Wowza Media Systems, LLC, all rights reserved, and are licensed pursuant to the Wowza Media Software End User License Agreement.
    Originally Published: 02-26-2014.
    Updated: For Wowza Streaming Engine 4.2 on 06-23-2014.

    If you're having problems or want to discuss this article, post in our forum.