Flash Media Server Developer Documentation

Multipoint publishing

To use multipoint publishing, you need to write both client and server-side code.

Note: See the LiveStreams sample, LiveStreams.as (in ActionScript 3.0) and main.asc (in Server-side ActionScript), at www.adobe.com/learn_fms_docs_en under the Developer Guide.

Note:

Write the client-side code

  1. In your client, publish a stream using NetStream.publish() and a stream name:
    private function publishLiveStream():void {
        var ns:NetStream = new NetStream(nc);
        ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        camera = Camera.getCamera();
        mic = Microphone.getMicrophone();
        if (camera != null && mic != null) {
            camera.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
            mic.addEventListener(ActivityEvent.ACTIVITY, activityHandler);
            ns.attachCamera( camera );
            ns.attachAudio( mic );
            // start publishing
            // triggers NetStream.Publish.Start
            ns.publish( "localNews", "record" );
        } else {
            trace("Please check your camera and microphone");
        }
    }
    
    

Write the server-side code

  1. In your main.asc file on the server, define an application.onPublish() event handler that accepts the stream name and connects to the remote server:
    // called when the client publishes
    application.onPublish = function( client, myStream ) {
        trace(myStream.name + " is publishing" );
        nc = new NetConnection();
        nc.onStatus = function (info) {
            if (info.code == "NetConnection.Connect.Success") {
                ns = new NetStream(nc);
                ns.setBufferTime(2);
                ns.attach(myStream);
                ns.publish( myStream.name, "live" );
            }
        nc.connect( "rtmp://xyz.com/myApp" );
        }
    
    }
    
    

    Calling NetStream.publish() publishes the stream from your server to the remote server.

  2. Handle events that occur on the NetStream object you used to publish from your server to the remote server:
    ns.onStatus = function(info) {
        if (info.code) == "NetStream.Publish.Start") {
            trace("The stream is now publishing");
            trace("Buffer time is : " + this.bufferTime);
        } 
    }
    
    

    Just as with publishing live streams from a user's computer, the NetStream.publish() method triggers a netStatus event with a NetStream.Publish.Start code.

  3. Define what happens when the client stops publishing:
    application.onUnpublish = function( client, myStream ) {
        trace(myStream.name + " is unpublishing"  );
    }