Red5 - 从应用程序服务器调用客户端方法不起作用

时间:2015-08-14 06:11:14

标签: flex invoke red5

如何从red5-service-1.0.5-RELEASE appliocation中的应用程序调用客户端flex方法。

and my jdk version is 1.8(64-bit).flex 4 ,as3

 package org.red5.demos;

        import org.red5.server.adapter.ApplicationAdapter;
        import org.red5.server.api.IConnection;
        import org.red5.server.api.scope.IScope;
        import org.red5.server.api.service.IServiceCapableConnection;
        import org.red5.server.api.stream.IServerStream;

        /**
         * @author user
         *
         */
        public class Application extends ApplicationAdapter {

            private IScope appScope;
            private IServerStream serverStream;

            @Override
            public boolean appStart(IScope app){

                super.appStart(app);
                System.out.println("hello demo start");
                appScope=app;
                return true;
            }


            @Override
            public boolean appConnect(IConnection conn,Object[]obj){  

                IScope appScope=conn.getScope();

                System.out.println("appConnect");

                callient(conn); //appConnect and calling client method

                return super.appConnect(conn, obj);

            }


            private void callient(IConnection conn){
                if(conn instanceof IServiceCapableConnection){
                    System.out.println("connect to flash side");    
                    ((IServiceCapableConnection) conn).invoke("yourFunctionInFlash");   // involing client side method ,but print "connect to flash side"
                }
            }

    //disconnected
            @Override
            public void appDisconnect(IConnection conn){
                    if(appScope==conn.getScope() && serverStream!=null){
                        serverStream.close();
                    }
                super.appDisconnect(conn);
            }
        }

和我的flex端代码,在我的演示中,连接到red5服务器应用程序后,netStatus信息成功。

        <?xml version="1.0" encoding="utf-8"?>
        <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                               xmlns:s="library://ns.adobe.com/flex/spark" 
                               xmlns:mx="library://ns.adobe.com/flex/mx"                         creationComplete="windowedapplication1_creationCompleteHandler(event)">


            <fx:Script>
                <![CDATA[
                    import mx.events.FlexEvent;
                    import mx.graphics.codec.JPEGEncoder;

                    private var cam:Camera;
                    private var netConnection:NetConnection;
                    private var netStream:NetStream;**strong text**

                    protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                    {               
                        netConnection=new NetConnection();
                        netConnection.client = { onBWDone: function():void{} };         
                                    netConnection.addEventListener(NetStatusEvent.NET_STATUS,connectionServerHandler);          
                        netConnection.connect("rtmp://192.168.61.132/Hello","ssl");//connect to Hello App
                    }

                    public function sayHello(reponder:String):void{
                        trace(reponder+"from server side ");
                    }

                    public function yourFunctionInFlash():void{
                        trace("hello");  //get message from server side
                    }

                    private function connectionServerHandler(event:NetStatusEvent):void{
                        trace(event.info.code);  //it work success 
                    }

                ]]>
            </fx:Script>

        </s:WindowedApplication>

 but now ,flex side yourFunctionInFlash()method doesn't work,and server side also print "connect to flash side"message?>>> is any other I have missed?


        thank you a lot .

1 个答案:

答案 0 :(得分:0)

方法Mongoose: users.remove({}) {} here Mongoose: users.insert({ name: 'bob', _id: ObjectId("55cda4dc40f2a8fb0e5cdf8b"), lectures: [], __v: 0 }) Saved: { "__v": 0, "name": "bob", "_id": "55cda4dc40f2a8fb0e5cdf8b", "lectures": [] } Mongoose: users.findAndModify({ _id: ObjectId("55cda4dc40f2a8fb0e5cdf8b") }) [] { '$addToSet': { lectures: { faculty: 'Nancy Wagner', day: 'Monday', topic: 'Fluid Mechanics', subject: 'physics', _id: ObjectId("55cda4dc40f2a8fb0e5cdf8c") } } } { new: true, upsert: false, remove: false } Modified: { "_id": "55cda4dc40f2a8fb0e5cdf8b", "name": "bob", "__v": 0, "lectures": [ { "faculty": "Nancy Wagner", "day": "Monday", "topic": "Fluid Mechanics", "subject": "physics", "_id": "55cda4dc40f2a8fb0e5cdf8c" } ] } 应在yourFunctionInFlash对象中定义。在您的情况下,您应该指定netConnection.client。在调用客户端方法之前,还要在后端调用netConnection.client = this