How to return list of live streams to Flash client (ModuleGetLiveStreams)

Module to return list of live streams to Flash client.

Server-side:

package com.wowza.wms.example.module;

import java.util.Iterator;
import java.util.List;

import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;

public class ModuleGetLiveStreams extends ModuleBase {

	public void getLiveStreams(IClient client, RequestFunction function,
			AMFDataList params) {

		AMFDataObj streams = new AMFDataObj();

		List<String> list = client.getAppInstance().getPublishStreamNames();

		Iterator<String> iter = list.iterator();
		int i=0;
		while (iter.hasNext())
		{
			streams.put("stream_" + i++,iter.next());
		}
		sendResult(client, params, streams); 
	}
}
Client-side AS3:
 
nc.call("getLiveStreams", new Responder(function(streams:Object):void
{
	for( var item:String in streams )
	{
		trace(streams[item]);
	}
}));

Client-side AS3 for Flex (with Bindable ArrayCollection to bind to UI elements.)

[Bindable]
private var liveStreams:ArrayCollection = new ArrayCollection();

nc.call("getLiveStreams", new Responder(new function(streams:Object):void
{
	for( var item:String in streams )
	{
		var obj:ObjectProxy = new ObjectProxy(); // In Flex use ObjectProxy to populate Bindable ArrayCollection.
		obj.label = streams[item];
		obj.value = item;
		liveStreams.addItemAt(obj,0);
	}
}));
Client-side AS2 (from jiffyjiffy)
 
testObj = new Object();
testObj.label = "List Streams";
testObj.remoteCall = function()
{
nc.call("getLiveStreams", null, "liveStreamsParamsArray");
}

testObj.remoteCall();

//and defining the client object to be:

var ncClientObj:Object = new Object();
nc.client = ncClientObj;

ncClientObj.liveStreamsParamsArray = function(param1:Array)
{
for(var index:Number = 0;index<param1.length;index++)
{
//do stuff to param1[index] here
}

return param1;
}

Originally Published: 08-12-2011.

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