NetStream.client定制回调处理程序问题 [英] NetStream.client custom callback handler problem

查看:195
本文介绍了NetStream.client定制回调处理程序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义回调处理程序添加到NetStream客户端的P2P应用。问题是,当我加入这样的处理程序,将NetStream客户端不会像以前那样发挥作用。它似乎是NetStream.client对象被改变。我知道默认的对象是这样的。但改变客户端这并没有解决问题。

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.

该remoteControlStream,是输入流。而本地控制流的流出版

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

这是一个正在被发送给对端的localControlStream,并收到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;
}

这是NetStream中收货流

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;
}

我添加了处理程序,像这样的remotecControlStream(同上):

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

在localControlStream的onPeerConnect方法,当我连接时,上述处理程序添加不会被调用。当我删除了该处理程序时,onPeerConnect方法被调用。

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.

任何人谁拥有一些建议/想法的。问题显然是是NetStream.client

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

您的帮助是非常AP preciated。

Your help is very much appreciated.

杰拉德

推荐答案

它的层云,对不对? 我用下面的模式: 在 NetStatusEvent.NET_STATUS '值为NetConnection.Connect.Success的NetConnection 位于 Main.connection 我称为静态类的以下功能:

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'); 
        }`

这里是 initIn 功能:

        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);
    }

RecievingObject 类:

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;
    }

}

这篇关于NetStream.client定制回调处理程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆