How to get the name of the stream (RTMFP NetGroup Problem, Flex/AS3)

3.6k views Asked by At

I'm implementing a peer-to-peer video conference application in Flex using the new RTMFP protocol and NetGroups..

Let's say the name of the group is Group1. What I want to do is; When a new peer connects to Group1; create a new video display for each joining peer and play his/her stream right away.

I listen to the NetStatus event of the NetConnection and on "NetStream.Connect.Success"; I want to add the new peer and play his/her stream.

But my problem is:

How will I know the name of the stream so I can play that stream for that joining peer. NetStream.Connect.Success will only give me event.info.stream property but I cannot find the name of the stream to be played for that particular peer.

Here is the short version of the code:

private function connect():void
{
    var conn:NetConnection = new NetConnection();
    conn.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
    conn.connect(rtmfpServer);
}

private function setupGroup():void
{
    var gspec:GroupSpecifier = new GroupSpecifier("Group1");
    gspec.multicastEnabled = true;
    gspec.postingEnabled = true;
    gspec.serverChannelEnabled = true;
    var group:NetGroup = new NetGroup(conn, gspec.groupspecWithAuthorizations());
    group.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
}

protected function onNetStatus(e:NetStatusEvent):void
{
    switch (e.info.code)
    {
        case "NetConnection.Connect.Success": //connected to the server
        setupGroup(); //create and connect to the group
        break;

        case "NetGroup.Connect.Success": //connected to the group
        publishMyVideo(); //create a player for my own video and publish it to the group
        break;

        case "NetStream.Connect.Success": //a new stream is connected
        if (NetStream(e.info.stream) != myStream) //if this is not my own stream; it's a new joining peer...
        {
            createPlayerForPeer(); //Create a video player for each joning peer
            playPeersVideo(); //what is the stream name to play?
        }
        break;
    }
}

Any help is appreciated.. thanks..

2

There are 2 answers

7
www0z0k On

streamIn = new NetStream(conn, NetStream(e.info.stream).farID

//...
streamIn.receiveVideo(true);
streamIn.receiveAudio(true); 
streamIn.play(/*here you need to use the string you pass to NetStream.publish() on the other side*/);
0
Umair Aamir On
     case "NetGroup.MulticastStream.PublishNotify":
          trace(event.info.name)
          break;

     case "NetGroup.MulticastStream.UnpublishNotify":
      trace(event.info.name)
      break;

You can get stream name from the above code.....you will publsh your stream with some name and that name will appear here, I think when NetStream.Connect.Success fires then this info also appears not sure......cheers