0 Replies Latest reply on Dec 23, 2011 2:36 AM by Marauder64r

    Problem with .onPeerConnect


      Hi! I have a problem with .onpeerconnect, it's fired only one time. For example, I connect first user, then second, onpeerconnect fired, and I have two users connected, then I connect third user, and onpeerconnect fired only for second user. If I connect fourth user onpeerconnect fired for third, also another problem: when somebody disconnected I have not one but two fired events "NetStream.Connect.Closed". Why does it's all heappen?


      Here is my source:


      import flash.events.NetStatusEvent;

      import flash.media.Camera;

      import flash.media.Microphone;

      import flash.net.NetConnection;

      import flash.net.NetStream;



      import mx.collections.ArrayCollection;

      import mx.controls.Alert;



      public var c:Camera;

      public var outgoingstream:NetStream;

      public var incomingstream:NetStream;


      public var myPeerID:String;



      public var ip:String;




      private var countuser:int;



      private const CIRRUS_ADDR:String = "rtmfp://p2p.rtmfp.net/";

      private const DEVELOPER_KEY:String = "6dd5260c9c1f5d29328241af-3339d1bd7ff5";



      public var nc:NetConnection;



      //public var farPeerID:String;



      public function cirrusconnect():void {

                nc = new NetConnection;

                nc.maxPeerConnections = 6;

                nc.addEventListener(NetStatusEvent.NET_STATUS, netHandler);





      private function netHandler(event: NetStatusEvent):void{


                          case "NetConnection.Connect.Success":

                                    myPeerID = nc.nearID




                          case "NetConnection.Connect.Failed":

                                    Alert.show('Connection error');


                          case "NetStream.Connect.Success":

                                    //Alert.show('шлем поток');


                          case "NetStream.Publish.Start":


                          case "NetStream.Connect.Closed":

                          var obj:Object = findObjectByAttribute(users, "stream", event.info.stream);

                                    if(obj == null){









      private function sendstream():void{ // только для сервера

                outgoingstream = new NetStream (nc, NetStream.DIRECT_CONNECTIONS);

                var camera:Camera = Camera.getCamera();



                var mic:Microphone = Microphone.getMicrophone();






                var client: Object = new Object();

                client.onPeerConnect =

                          function(callerNS:NetStream):Boolean {

                                    var sendobj:Object = new Object;

                                    sendobj.name = username;

                                    sendobj.rating = rating;

                                    sendobj.id = myPeerID;

                                    callerNS.send('hello', sendobj);


                                    return true;


                outgoingstream.client = client;





      private function connectcheck(id:String):void{

                var i:int = usersid.getItemIndex(id);

                if (i == -1){









      private function connectnew(farPeerID:String):void{


                incomingstream = new NetStream(nc, farPeerID);


                var o:Object = new Object();

                o.hello = function(obj:Object):void {

                          if(obj.id == incomingstream.farID){


                                              {name:obj.name, rating:obj.rating, stream:incomingstream, id:incomingstream.farID})


                                    if(seating == false){


                                              seating = true; //Убрать ситинг при уходе из комнаты




                incomingstream.client = o;




      private function closestream(exitstream:NetStream):void{




                var str:Object = findObjectByAttribute(users, "stream", exitstream);







      private function findObjectByAttribute(arrayCollection:ArrayCollection,

                                                                                                   attributeName:String, value:NetStream):Object{

                for each (var object:Object in arrayCollection) {


                                    return object;



                return null;