0 Replies Latest reply on Oct 20, 2011 3:01 PM by Marauder64r

    Access, question

    Marauder64r Level 1

      Hi! I am new in cirrus development... I've made some functions with netgroups, and i have a question how can i make access form.. For example one user already in group, another one want to join, while he trying to do this, first user see form with data of the second user, and two buttons - allow, deny. He press allow, and second user join to group

       

      My code example:

      import flash.events.MouseEvent;

      import flash.events.NetStatusEvent;

      import flash.media.Camera;

      import flash.media.Microphone;

      import flash.media.Video;

      import flash.net.GroupSpecifier;

      import flash.net.NetConnection;

      import flash.net.NetGroup;

      import flash.net.NetStream;

       

       

      import mx.collections.ArrayCollection;

      import mx.controls.Alert;

      import mx.controls.Text;

      import mx.core.UIComponent;

      import mx.rpc.events.ResultEvent;

      import mx.utils.Base64Encoder;

       

       

      import spark.components.BorderContainer;

      import spark.components.TextArea;

       

       

       

       

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

      private const DEVELOPER_KEY:String = "";

      public var myCamera:Camera = new Camera;

      public var netconnection:NetConnection = new NetConnection;

       

       

      [Bindable]

      private var user:String;

      private var netGroup:NetGroup;

      public var groupSpecifier:GroupSpecifier;

      private var outgoingStream:NetStream;

      [Bindable]

      private var connected:Boolean = false;

      public var uic:UIComponent;

      public var streamarr:Array = new Array;

       

       

      public function initAll():void{

                boxer.addEventListener('setupGroup', onSetupGroup);

       

                myCamera = Camera.getCamera();

                if (myCamera == null){

                          Alert.show('Подключите камеру');

                }else{

                          myCamera.setMode(640,480,60);

                          mycam.attachCamera(myCamera);

                }

                netconnection.maxPeerConnections = 20;

                netconnection.addEventListener(NetStatusEvent.NET_STATUS,

                          netHandler);

                netconnection.connect(CIRRUS_ADDR+DEVELOPER_KEY);

      }

       

       

      private function netHandler(event: NetStatusEvent):void{

       

       

                switch(event.info.code){

                          case "NetConnection.Connect.Success":

                                    Alert.show("connected")

                                    break;

                          case "NetConnection.Connect.Failed":

                                    Alert.show('Проблема с подключением \n' +

                                              'Возможно проблема связана с настройками файервола');

                                    break;

                          case "NetGroup.Connect.Success":

                                    initstream();

                                    //Alert.show("netgroup")

                                    break;

                          case "NetGroup.Neighbor.Connect":

                                    seemystream();

                                    //Alert.show("somebody connect")

                                    break;

                          case "NetStream.Connect.Success":

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

                                    sendstream();

                                    break;

                          case "NetGroup.SendTo.Notify":

                                                        ifexiststream(event.info.message.value);

       

                                    break;

                          case "NetStream.Publish.Start":

                                    break;

       

       

       

                }

      }

      public function setupGroup(userid:String):void{

       

                groupSpecifier = new GroupSpecifier(userid);

                groupSpecifier.multicastEnabled = true;

                groupSpecifier.postingEnabled = true;

                groupSpecifier.serverChannelEnabled = true;

                groupSpecifier.objectReplicationEnabled = true;

                groupSpecifier.ipMulticastMemberUpdatesEnabled = true;

                groupSpecifier.routingEnabled = true;

       

       

                netGroup = new NetGroup(netconnection,groupSpecifier.groupspecWithAuthorizations());

                netGroup.addEventListener(NetStatusEvent.NET_STATUS,netHandler);

                user = netconnection.nearID;

                streamarr.push(user);

      }

      private function initstream():void{

       

                outgoingStream = new NetStream (netconnection,groupSpecifier.groupspecWithAuthorizations());

                outgoingStream.addEventListener( NetStatusEvent.NET_STATUS, netHandler);

      }

       

       

       

       

      private function sendstream():void{

                var camera:Camera = Camera.getCamera();

                camera.setMode(640,480,40);

                camera.setQuality(16384,60);

                var mic:Microphone = Microphone.getMicrophone();

                outgoingStream.attachAudio(mic);

                outgoingStream.attachCamera(camera);

                outgoingStream.publish( user );

       

       

      }

      private function askchatting():void{

                //"imnew" +

      }

      private function seemystream():void{

                var message:Object = new Object();

                message.value = user;

                message.destination = netGroup.convertPeerIDToGroupAddress(netconnection.nearID);

                netGroup.addEventListener(NetStatusEvent.NET_STATUS, netHandler);

                netGroup.sendToAllNeighbors(message);

      }

       

       

      private function ifexiststream(streamid:String):void{

                var i:int = streamarr.indexOf(streamid);

                if (i == -1){

                          Alert.show('init');

                streamarr.push(streamid);

                playstream(streamid);

                          }

       

      }

      private function playstream(streamid:String):void{

                var incomingstream: NetStream = new NetStream (netconnection,groupSpecifier.groupspecWithAuthorizations());

                var video: Video = new Video(320,240);

                video.attachNetStream(incomingstream);

                uic = new UIComponent;

                uic.width = 320;

                uic.height = 240;

                incomingstream.play( streamid );

                uic.addChild(video);

                camwindow.addElement(uic);

      }