Noman Ur Rehman
Noman Ur Rehman

Reputation: 11

Webcam pool using Flash Media Server

I have an application where users can log in and connect to the Flash media server. Once they have been connected, anyone can view their webcam.

For example, lets say Bob and Sally log on to the website and their cameras are now being streamed. Bob can view Sally's webcam stream at http://www.example.com?cam=sally and Sally can view Bob's webcam stream at http://www.example.com?cam=bob

Upvotes: 1

Views: 1119

Answers (1)

Tamas Gronas
Tamas Gronas

Reputation: 573

Use this code to broadcast webcam stream to FMS:

    var nc : NetConnection = new NetConnection( );
        nc.client = this;
        nc.addEventListener(NetStatusEvent.NET_STATUS, statusHandler );
        nc.connect( "rtmp://your-fms-server-url/your-application" );

    var cam : Camera = Camera.getCamera( );
        cam.setMode( 640, 480, 20 );

    var ns : NetStream;

    function statusHandler ( eventOBJ : NetStatusEvent )
    {
        if ( eventOBJ.info.code == "NetConnection.Connect.Success" )
        {
            ns = new NetStream( nc );
            ns.attachCamera( cam );
            ns.publish( "your-stream-name" );
        }
    };

The receiver is simliar, except a few lines:

    // to the declaration section:
    var video : Video = new Video( );

    // code in the statusHandler method:
    if ( eventOBJ.info.code == "NetConnection.Connect.Success" )
    {
        ns = new NetStream( nc );
        ns.play( "your-stream-name", -1 );
        video.attachNetStream( ns );    
        addChild( video );
    }

And you simply pass the name of the desired stream in flashvars. For example if you use this url: www.yourdomain.com/chat.php?cam=Sally, in this case pass the cam parameter to the SWF client, and use in the following form:

    ns.play( this.loaderInfo.parameters.cam , -1 );

Upvotes: 1

Related Questions