Wowza Community

Calling flash.net.Responder functions

I make a call to my Wowza application like this:

var myResult:Object = new Object();

myResult.onResult = function(result:Object) : void {

Alert.show(“callback function worked”, “title”);

}

_connection.fmsConnection.call(“changeUserSO”, new Responder(myResult.onResult), mode);

However, my Responder function never gets called on the callback. What do I need to do in my Java code to make this work?

Thanks in advance.

You need a sendResult call in the server-side method, something like this:

public void changeUserSO(IClient client, RequestFunction function,
			AMFDataList params) {
		getLogger().info("changeUserSO");
		AMFDataObj returnObj = new AMFDataObj();
		returnObj.put("hello", "hello from wowza");
		sendResult(client, params, returnObj);
	}

Client-side:

var myResult:Object = new Object();
myResult.onResult = function(result:Object) : void {
trace(result.hello);
}

Richard

Are you doing AS1 or AS3 client-side coding? What does the rest of the client side code look like? You may want to disect our ServerSideModules example which covers this topic in great detail.

The server-side of what you are doing looks correct. You have not provided enough information on the client-side to see if this is setup properly. It should look something like:

This is assuming AS3:

var nc:NetConnection;
// create a connection to the wowza media server
nc = new NetConnection();
function doSomethingResult(returnStr:String)
{
	trace("doSomething: "+returnStr);
	callResult.text = "doSomething: "+returnStr;
}
// trace status information
function ncOnStatus(infoObject:NetStatusEvent)
{
	trace("nc.onStatus: "+infoObject.info.code+" ("+infoObject.info.description+")");
	
	// when we connect to the server...
	if (infoObject.info.code == "NetConnection.Connect.Success")
	{
		// call our server side function
		nc.call("doSomething", new Responder(doSomethingResult), "test param1");
	}
}
nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
// connect
nc.connect("rtmp://localhost/mymodules");

Charlie

There is not a server-side NetConnect.call in Wowza. There is IClient.call or IApplicationInstance.broadcastMsg

To do IClient.call or IApplicationInstance.broadcastMsg you need to set up callback methods on the NetConnection object.

The best reference for all of this is the ServerSideModules example that ships with Wowza in the /examples folder. This includes a Flash application and Wowza Application Module, a working reference.

Richard

Thanks for the tip. Still no luck, but trying to make sure that everything is setup right on my side first, and then I’ll report back.

Hi Richard,

I’m trying to do something similiar, I’ve added a module to extend videochat and I’d like to use nc.call() from Flash to return the number of clients currently connected to the server.

In my server-side code I have the following function…

public void doSomething(IClient client, RequestFunction function,

AMFDataList params) {

getLogger().info(“doSomething”);

IApplicationInstance appInstance = client.getAppInstance();

int tmp = appInstance.getClientCount();

AMFDataObj returnObj = new AMFDataObj();

returnObj.put(“count”, tmp);

sendResult(client, params, returnObj);

and in my client-side code I have the following…

var myResult:Object = new Object();

myResult.onResult = function(result:Object) : void {

trace(result.count);

}

Can you tell me the correct way to use nc.call in this scenario, and whether I am making a mistake somewhere because I just can’t seem to get this to hang together…

Thanks,

kivanchi

Hi Charlie,

Thanks for your reply, that was extremely helpful. I’m using AS3 on the client-side. Having looked at your example and then finally realised that I also had a typo in my Apllication.xml file, I finally got this working as expected…nothing very interesting for you but thought I’d conclude the thread anyway…

So, the server-side code is exactly the same as above.

the flash file has the addition of an “updateButton” to the stage, as well as a dynamic text input named “clientCount”.

as far as the client-side code goes, it’s the original videochat.fla file with

updateButton.addEventListener(MouseEvent.CLICK, updateList);

added to startCamera(),

and then…

function doSomethingResult(returnStr:Object)

{

clientCounter.text = "count: "+returnStr.count;

}

function updateList(e:MouseEvent){

if(connect.connectButton.label==“Stop”){

nc.call(“doSomething”, new Responder(doSomethingResult), “test param1”);

}

}

hi Charlie

I am trying to use nc.call method too and I have some problems

on server side:

nc.call(“vidRes”,null,int(activeRes[0]),int(activeRes[1]));

on client side:

nc = new NetConnection();

var netClass : ncCall = new ncCall();

nc.connect(connectUrl);

nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);

nc.client = netClass;

netClass.addEventListener(resEvent.RES, chngRes);

on netClass class:

package {

import flash.display.MovieClip;

import SubFolder.resEvent;

import flash.display.Sprite;

import flash.events.Event;

import flash.net.NetStream;

public class ncCall extends MovieClip{

public function vidRes(w : int, h : int) {

trace("calll "+w);

dispatchEvent(Event(new resEvent(resEvent.RES, w, h)));

}

}

}

dispatch event supposed to return w and h but even the traces wont return;

can you help me about that