1 Reply Latest reply on Jan 26, 2009 11:07 AM by GOABONGA

    use on onPeerConnect  in my CLASS

    GOABONGA Level 1
      does the onPeerConnect look like onCuePoint ?

      why when i make an ClientClass with public function onPeerConnect anythink work ?
        • 1. Re: use on onPeerConnect  in my CLASS
          GOABONGA Level 1


          package
          {
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.events.NetStatusEvent;
          import flash.media.Camera;
          import flash.media.Video;
          import flash.net.NetConnection;
          import flash.net.NetStream;

          /**
          * ...
          * @author ...
          */
          public class Main extends Sprite
          {
          //
          private var _netConnection:NetConnection;
          private var _netStream:NetStream;
          //
          private var url : String = "rtmfp://stratus.adobe.com/ed36edc2c07149d59af096ce-443ab700b10c/";
          private var key : String = "2123154564654654";
          //
          private var video:Video ;
          private var cam:Camera;

          public function Main():void
          {
          trace('init app');
          video = new Video();
          cam = Camera.getCamera();
          video.attachCamera(cam);

          video.addEventListener(Event.ADDED_TO_STAGE, added);
          addChild(video);

          }
          public function added(e:Event):void
          {
          trace('added');
          stage.addEventListener(MouseEvent.CLICK, publish);

          }
          private function publish(e:MouseEvent):void
          {
          _netConnection = new NetConnection();
          _netConnection.addEventListener(NetStatusEvent.NET_STATUS, net_status);
          _netConnection.connect(url + "/" + key);

          }

          private function net_status(e:NetStatusEvent):void
          {
          trace(this+' net_status : ' + e.info.code);
          //
          if(e.info.code == "NetConnection.Connect.Success") {
          //trace('your uid : ' + _netConnection.nearID);
          trace(_netConnection.nearID);
          //dispatchEvent(new NetEvent(NetEvent.CONNECT));
          _netStream = new NetStream(_netConnection, NetStream.DIRECT_CONNECTIONS);
          _netStream.addEventListener(NetStatusEvent.NET_STATUS, net_status);
          //
          /*var c:Object = new Object();
          c.onPeerConnect = function(subscriber:NetStream):Boolean {
          trace('onPeerConnect invoked');
          //trace(subscriber.farID);
          trace(_netStream.peerStreams.length);

          if (accept){

          return true;
          }else{
          return false;
          }
          };*/
          _netStream.client = new MyClient();
          //
          _netStream.attachCamera(cam);
          _netStream.publish("chris");

          }
          if (e.info.code == "NetConnection.Connect.Failed") {
          //dispatchEvent(new NetEvent(NetEvent.ERROR));
          }
          }
          private var accept:Boolean = true;

          }

          }
          import flash.net.NetStream;
          class MyClient {

          public function onPeerConnect(subscriber:NetStream):Boolean {
          trace('onPeerConnect invoked');
          trace(subscriber.farID);
          /*
          if (accept){

          return true;
          }else{
          return false;
          }
          */
          return true;
          }
          }