Search code examples
actionscript-3flashstreamnetstreamrtmfp

NetStream.send not working with NetGroup in RTMFP


We are running a Cumulus server to do a live voice and text chat.

The setting is that each client can post data to each other client in the same NetGroup via group.post(). Unfortunately, that function is extremely slow (half a second delay, at least), so we switched to using NetStream.send to call functions on other clients, passing the data through that. This works almost instantly.

However, we are now trying to build separate chat rooms, using different NetGroups. But when doing so, NetStream.send() doesn't work anymore, the functions are never called on the other clients, and no voice data is transferred. Basically, the whole publishing NetStream seems to be not working any more.

We have the following setup to establish a NetGroup and a publishing stream on each client:

var gspec:GroupSpecifier = new GroupSpecifier("Group1");
gspec.multicastEnabled = true;
gspec.postingEnabled = true;
gspec.serverChannelEnabled = true;
gspec.objectReplicationEnabled = true;
gspec.routingEnabled = true;

_group = new NetGroup(_netConnection, gspec.groupspecWithAuthorizations());
_group.addEventListener(NetStatusEvent.NET_STATUS, handleNetGroupStatus);

_sendStream = new NetStream(_netConnection, gspec.groupspecWithAuthorizations()); 
_sendStream.addEventListener(NetStatusEvent.NET_STATUS, handleNetStreamStatus);
_sendStream.client = this;
_sendStream.attachAudio(_mic); 
_sendStream.publish("media");

And the following code is used to listen to the "media" stream:

case "NetGroup.Neighbor.Connect":
  var netStream :NetStream = new NetStream(_netConnection, p_netStatusEvent.info.peerID);
  netStream.addEventListener(NetStatusEvent.NET_STATUS, handleNetStreamStatus); 
  netStream.client = this;
  netStream.play("media");
break;

The NetGroup connection itself works, and "NetGroup.Neighbor.Connect" is called on each client when a neighbor connects. But the _sendStream itself simply doesn't work. No data is received, no function called.

It does work when the publishing NetStream is constructed in the following way:

_sendStream = new NetStream(_netConnection, NetStream.DIRECT_CONNECTIONS); 

However, we only want the NetStream to send to a single NetGroup, and according to the Adobe Documentation, using gspec.groupspecWithAuthorizations() in the constructor should allow exactly that.

Are we missing something here?


Solution

  • I found the answer:

    You also have to make the receiving NetStream listen to gspec.groupspecWithAuthorizations() instead of p_netStatusEvent.info.peerID.

    This does work. Unfortunately, this makes voice chat impossible, as it is incredibly slow (as slow as NetGroup.post()) and introduces many sound artifacts.

    So, we'll have to find another solution for different chat rooms...