flashactionscript-3clientp2pnetstream

NetStream.client custom callback handler problem


I'm trying to add a custom callback handler to a NetStream client in a p2p application. The problem is, when I add such a handler, the NetStream Client doesn't function as it did before. It seems the NetStream.client object is changed. I know the default object is this. But changing the client to this doesn't solve the problem.

The remoteControlStream, is the incoming stream. And the localControl stream is the stream being published

This is the localControlStream that's being send by the peer, and received as remoteControlStream:

private function initLocalControlStream():void{
     localControlStream = new NetStream(nc, NetStream.DIRECT_CONNECTIONS);
     localControlStream.addEventListener(NetStatusEvent.NET_STATUS, localControlHandler);
     localControlStream.publish(myPeerID+"control");

     var localControlStreamClient:Object = new Object();

     localControlStreamClient.onPeerConnect = function(callerns:NetStream):Boolean{
          txtTest.text = "peer connected";
          if(side=="host"){
                farPeerID = callerns.farID;
                if(!allreadyConnected){
                     initRemoteControlStream();
                     allreadyConnected = true;
                 }
           }

          return true;
     }
     localControlStream.client = localControlStreamClient;
}

This is the NetStream that's receiving the stream:

private function initRemoteControlStream():void{
     txtTest.text = "setting up remote stream";
     if(side=="client"){
           farPeerID = this.parameters.hostFingerprint;
     }

     remoteControlStream = new NetStream(nc, farPeerID);
     remoteControlStream.addEventListener(NetStatusEvent.NET_STATUS, remoteControlHandler);

     remoteControlStream.client.test = new function():void{
           txtTest.text = "Callback handler working";
     }  

     remoteControlStream.play(farPeerID+"control");

     remoteControlStream.client = this;
}

I add the handler to the remotecControlStream like this (as above):

remoteControlStream.client.test = new function():void{
     txtTest.text = "Callback handler working";
}

The onPeerConnect method of the localControlStream doesn't get called when I connect when the above handler is added. When I remove the that handler, the onPeerConnect method gets called.

Anyone who has some advice/idea's. Obviously the problem is the NetStream.client.

Your help is very much appreciated.

Gerard


Solution

  • it's stratus, right? i used the following model: on NetStatusEvent.NET_STATUS 'NetConnection.Connect.Success' of NetConnection located Main.connection i called the following function of static Streams class:

    `        public static function initOut(): void {
                streamOut = new NetStream(Main.connection, NetStream.DIRECT_CONNECTIONS);
                var peerConnected:Object = new Object();
                    peerConnected.onPeerConnect = function(subscriberStream : NetStream) : Boolean {
                        var oo:RecievingObject = new RecievingObject();
                        subscriberStream.client = oo;
                        if(!streamIn){ initIn((subscriberStream as NetStream).farID); }                    
                        return true;
                    }
                streamOut.client = peerConnected;            
                streamOut.addEventListener(NetStatusEvent.NET_STATUS, onOutStatus);            
                streamOut.attachCamera(Camera.getCamera());
                streamOut.attachAudio(Microphone.getMicrophone());
                streamOut.publish('media'); 
            }`
    

    here is the initIn function:

            public static function initIn(id: String): void {
            streamIn = new NetStream(Main.connection, id);
            streamIn.client = new RecievingObject();
            streamIn.addEventListener(NetStatusEvent.NET_STATUS, onInStatus);
            streamIn.receiveVideo(true);
            streamIn.receiveAudio(true); 
            streamIn.play('media');
            VideoWindow.initIn(streamIn);
            Mixer.initSound(streamIn);
        }
    

    and the RecievingObject class:

    public class RecievingObject extends Object
    {
    
        public function RecievingObject() 
        {
    
        }
    
        public function message(str: String):void {
            ChatWindow.addText('>> ' + str);
        }
    
        public function onPeerConnect(ns: NetStream): Boolean {
           // trace(ns.farID);
            return true;
        }
    
    }