Call Flash Function On All Clients From Server

I am trying to execute a function for every viewer from Wowza and this is my first try at ActionScript so I need a little guidance.

On the server side I have this:

public void myFunction(){
                IMediaStream stream = this.appInstance.getStreams().getStream("myStream");
		String callback = "testCuePoint";
		String data = "this is a test";
		stream.sendDirect(callback, data);
	}

And this is what I have on the client side:

var nsPlayClientObj:Object = new Object();
nsPlayClientObj.testCuePoint = function(data:String):void
{
	trace("cuepoint data: " + data);
};

I took this from this thread and put it in the “function Player()” code block sample player provided in the examples folder. I have a feeling that’s not where it’s supposed to go but again, this is my first time coding in AS so I’m just feeling my way around.

I’ve looked at the “ServerSideModule” within examples but all those examples are making calls that originate from a flash client. I want the call to originate from the server. I did find one thread on here that has exactly what I’m looking for but I didn’t understand his client-side code. ie where does that go in the player code? Is that all there is to it?

Take another look at the ServerSideModule example, because there are server to client call examples there that you can refer to.

Richard

Assuming you are using PushPublish, I’m not sure but try setting PushPublisherRTMP.sendOnMetaData() to true.

There is not another PushPublish setting that will affects the data channel.

Richard

IMediaStream.sendDirect() should work for RTMP clients playing back from an edge, but I don’t IClient.broadcastMsg() will work with Live Stream Repeater, where clients are connecting to the edge.

Richard

Hi,

You have two different methods that are trying to send a function call to the clients. One sends the call to the NetConnection.client object and the other sends the call to the NetStream.client object.

	public void sayHello(){
		this.appInstance.broadcastMsg("sayHello");
	}

This will be received on the player side with the following code that connects a handler to the NetConnection.

var ncClientObj:Object = new Object();
netConnection.client = ncClientObj;
ncClientObj.sayHello = function():void
{
	msg.text = "TEST SUCCESSFUL!";
}

BroadcastMsg will send the message to all rtmp clients that are connected to the appInstance, including players and publishers, no matter what stream they are viewing or publishing.

The second method that sends the function call to the stream

	public void sayHello(){
		this.stream = this.appInstance.getStreams().getStream("myStream");
		stream.send("sayHello");
	}

requires a handler on the NetStream.

var nsClientObj:Object = new Object();
netStream.client = nsClientObj;
nsClientObj.sayHello = function():void
{
	msg.text = "TEST SUCCESSFUL!";
}

You can also use stream.sendDirect as per your original post. The difference is that with send, the messages are sent to the clients using an external call whereas with sendDirect, the message is inserted into the stream as data. If recording the stream then the data will also be recorded.

Send or sendDirect will only be sent to rtmp players that are connected to the stream. It will not be sent to publishers or players on any other streams.

On the client side, the two client objects (NetConnection.client & NetStream.client) are very similar so it is easy to overlook.

On the server, streams associated with rtmp clients do not have NetConnection objects which is why stream.getNetConnection() returns null. In these streams, the client is the same as the netConnection. NetConnection on Wowza is only used when making outgoing connections to other servers (MediaCasters or PushPublishing etc).

Roger.

I got some more time to work on this but I’m running into 2 issues:

  1. I can successfully call appInstance.broadcastMsg(“sayHello”) when the flash client uses “rtmp://localhost/myApp”. When I use “rtmp://cdn.mydomain.com/myApp” appInstance.broadcastMsg does not work.

  2. I have not been able to use stream.send(“sayHello”) successfully with either “rtmp://localhost/myApp” or “rtmp://cdn.mydomain.com/myApp”.

When debugging my server module code I noticed that the stream’s netconnection attribute is null in both cases (I mention this because I assume it shouldn’t be but I don’t know how to fix that). See below for my server and client side code

Server:

        //for clarity I've put both versions of this function here. I usually just comment out the code I don't need before compiling.
	public void sayHello(){
		this.appInstance.broadcastMsg("sayHello");
	}
        
	public void sayHello(){
		this.stream = this.appInstance.getStreams().getStream("myStream");
		stream.send("sayHello");
	}

Client:

var ncClientObj:Object = new Object();
nc.client = ncClientObj;
ncClientObj.sayHello = function():void
{
	msg.text = "TEST SUCCESSFUL!";
}
nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
var url:String = "rtmp://localhost/myApp/";
nc.connect(url);

Thanks Richard and Roger you’ve both provided very useful info I just have one last question.

Currently our CDN is pulling from our server so we aren’t using the PushPublish module, do we have to push to use broadcastMsg or send/sendDirect? Right now we’re just looking for Server to Client but we’ll eventually want 2-way server to client communication.

Using PushPublish is on my to-do list (mostly to save on bandwidth) so I’d be willing to pursue that avenue if it also helps with Server to Client communication.