FMS (Flash Media Server) Video Chat
Here’s a quick way to setup a Flash Media Server chat room. This process only allows for two users to video chat over Flash Media Server, and was the start of a larger project that I was involved with.
Setting Up the Flash Media Server Application
It really what you are going to use in terms of either a FMS hosting company, or your own. Most of the FMS hosting companies use the same techniques when setting up their servers for users, but that might not always be true. In general, you simply need to make sure that you setup a new Application so that the chat has somewhere to store the published stream, and so that other flash files connected to the same Application can find that stream.
I use the hosting service provided by Influxis.com. It’s not as powerful as hosting my own FMS installation, but it definately does the trick for anything small or for testing.
If you use Influxis, or are going to after reading this article, here’s how to setup an Application on your server. As I mentioned, this may vary from host to host, but it’s generally the exact same process.
1) Login to your account, and choose the “File Admin” tab.
2) Click “Add New Application”.
3) Give your application a name. This can be anything you want.
4) You can leave “Include the standard main.asc file” turned on.
5) Hit Continue.
6) Copy and paste the rtmp address into the NetConnection connect portion of both of our users fla files.
client_nc.connect("rtmp://fms-server/app-name/");
You will need to replace “rtmp://fms-server/app-name/” with the rtmp address that the Influxis interface has provided you with. If you don’t use Influxis, you probably already know how your server is setup, and how to reference your new Application folder.
Now, I have two flash files that connect to the same application on the FMS. Each one publishes to a stream called “live”. There are two video objects on the stage that act as a preview of yourself, and the live camera from the other user. (The small video object on the left is your preview, and the larger on the right is the person you are talking to.)
Here is the code for the “user_1″ swf file:
stop();
//setup the camera and mic for streaming
mycam = Camera.get();
mycam_audio = Microphone.get();
//control the cameras mode and quality
mycam.setMode(320,240,30);
mycam.setQuality(10000,100);
//attach a live preview of the camera to the
//video object that is setup on the stage
cam_feed.attachVideo(mycam);
cam_feed.attachAudio(mycam_audio);
//connect to the Flash Media Server
client_nc = new NetConnection();
client_nc.connect("rtmp://fms-server/app-name/");
cam_ns = new NetStream(client_nc);
//attach our camera video and audio to the net stream
cam_ns.attachVideo(mycam);
cam_ns.attachAudio(mycam_audio);
//publish to our Flash Media Server as a
//live stream called user_1
cam_ns.publish("user_1", "live");
//bring in user_2's video/audio
in_ns = new NetStream(client_nc);
in_ns.play("user_2");
//attach user_1's published audio and video
//so we can see them in the larger chat window
live_feed.attachVideo(in_ns);
live_feed.attachAudio(in_ns);
And here is the code for the “user_2″ swf file:
//setup the camera and mic for streaming
mycam = Camera.get();
mycam_audio = Microphone.get();
//control the cameras mode and quality
mycam.setMode(320,240,30);
mycam.setQuality(10000,100);
//attach a live preview of the camera to the
//video object that is setup on the stage
cam_feed.attachVideo(mycam);
cam_feed.attachAudio(mycam_audio);
//connect to the Flash Media Server
client_nc = new NetConnection();
client_nc.connect("rtmp://fms-server/app-name/");
cam_ns = new NetStream(client_nc);
//attach our camera video and audio to the net stream
cam_ns.attachVideo(mycam);
cam_ns.attachAudio(mycam_audio);
//publish to our Flash Media Server as a
//live stream called user_2
cam_ns.publish("user_2", "live");
//bring in user_1's video/audio
in_ns = new NetStream(client_nc);
in_ns.play("user_1");
//attach user_1's published audio and video
//so we can see them in the larger chat window
live_feed.attachVideo(in_ns);
live_feed.attachAudio(in_ns);
You’ll notice the only difference between the two is how the streams are being published. User_1′s stream publishes to “user_1″ and User_2 publishes to “user_2″. Each then streams in the others live stream while also showing their own stream as a preview for the other user.
Upload the user_1 and user_2 folders to your server (it doesn’t matter where they go on your server, just be sure you know how to get to them using your browser), and browse to them in two separate tabs, or windows. You will then get the same results that I have in the screen shot below.
So by creating an application folder on your FMS server, you can instantly chat with anyone. It’s not extremely robust, but with a little more work, it could turn into a full application.
Here’s a screen shot with me chatting with myself
to give you an idea of what we are accomplishing.






