Search code examples
actionscript-3flashapache-flexflash-media-server

FMIS display an away screen during streaming session


I am wondering if this is possible and maybe some code examples if it is. I am trying to have the presenter during a live address be able to hit a button when he is away. This button will then trigger a jpg or some kind of image on the clients side that says he is currently away and to also have it mute the presenter's microphone? Anyone have any ideas how this would be possible in FMIS 4 and AS3?


Solution

  • Yes, this is do-able. There's a bit of code to write. Here's a break down:

    • Client for presenter makes a NetConnection and then publishes a NetStream to FMS.
    • When presenter hits away button:
      1. Presenter's client sets microphone gain to 0
      2. Presenter's client uses NetStream.send() to send a message to all subscribing clients. The message is basically the name of a function and some arguments that all subscribing clients should execute. In this case, the function would display/hide the "away" image.
    • then do the reverse when the presenter returns

    [Edit] Adding some code to clarify how to use NetStream.send():

    The presenter code:

    private function onAwayButtonClick(event:Event):void
    {
        stream.send("toggleAwayImageDisplay"); // stream is a NetStream you created elsewhere
        mic.gain = 0; // mic is the Microphone you attached to the stream
    }
    

    The subscriber code

    When creating the NetStream, use the client property so it knows where to find the function "toggleAwayImageDisplay" we specified above:

    private function someMethodThatCreatesNetStream(netConnection:NetConnection):void
    {
        stream = new NetStream(netConnection);
        // you could use any object here, as long as it has the method(s) you are calling
        stream.client = this;
    
        // this might be nicer, you can reference functions from any class this way
        // the key in this client object is a function name
        // the value is a reference to the function
        // var client:Object =
        //     { toggleAwayImageDisplay: toggleAwayImageDisplay,
        //       doSomethingElse: anotherObject.doSomethingElse }; 
        // stream.client = client;
        // be careful about memory leaks though :)
    }
    
    private function toggleAwayImageDisplay():void
    {
       // now show or hide the image
    }