2

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..

Onur Yıldırım
  • 32,327
  • 12
  • 84
  • 98

2 Answers2

2
     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

Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
1

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*/);
www0z0k
  • 4,444
  • 3
  • 27
  • 32
  • of course I need the published string there.. question is how do I get the stream name.. as I asked.. – Onur Yıldırım Jan 30 '11 at 01:58
  • @ radgar - how are you going to use it? – www0z0k Jan 30 '11 at 03:38
  • @ radgar - i mean `NetStream` doesn't have a `name` property, it uses a string id to publish/play and has a `farID`/`nearNonce` if over rtmfp/rtmpe – www0z0k Jan 30 '11 at 09:43
  • I need to inform the receiver peer about the publisher's stream name so the receiver can play the stream. And I have to do this for each peer in the conversation. So; what would be the best way to pass these stream names between peers? SharedObject? Object replication? group.post()? Ex: if I use remote SharedObject; it seems to be a good way but how do I seperate remote sharedobjects on the server so each conversation has it's seperate list of stream names..BTW if I use SharedObjects than I guess I better to listen to the Sync event in stead of NetStream.Connect.Success? – Onur Yıldırım Jan 30 '11 at 12:35
  • @ radgar - at the moment you need to know this name your stream is already connected so you can use `NetStream.send('nameReciever', name);` and a custom class for `NetStream.client` with `private function nameReciever(name:String):void{/*...*/}`. You can also ask for names looping through `NetStream.peerStreams`. and maybe it's possible to make stream name equal to `NetStream.farID` – www0z0k Jan 30 '11 at 12:58
  • Thanks for your time but I think the send() method of the NetStream can only be received if it is being played on the other end. So It won't help if I send the name of the stream that way.. I think I'll go with remote SharedObject. – Onur Yıldırım Jan 31 '11 at 09:53
  • @ radgar - did you try to make name equal to `stream.nearNonce` when publishing and `stream.play(NetStream(e.info.stream).farID)` on the other side? – www0z0k Jan 31 '11 at 10:22