Skip to main content
Participant
November 2, 2010
Question

NetStream.client custom handler problem

  • November 2, 2010
  • 1 reply
  • 542 views

Hi all,

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

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    November 3, 2010

    Sorry i have not got in detail but i am just wondering why are you using

    remoteControlStream.client.test = new function():void{

    instead of

    remoteControlStream.client.test = function():void{

    Do we need "new" keyword?