This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Hello Video!
|
19
Admin Service is started whenever FlashCom is started and provides both adminis-
trative services and application monitoring, control, and debugging services. You can
connect directly to the Admin Service using one of two Flash movies provided with
FlashCom. In the FlashCom 1.5.2 release, you’ll find them in the flashcom_help\
html\admin subdirectory of the installation directory. The Administration Console
(admin.swf) movie can be used to update license information, start and stop applica-
tion instances, and review server diagnostic information. The Communication Appli-
cation Inspector (app_inspector.swf) can be used to start and stop application
instances, monitor application instance resources, and display trace( ) statement out-
put. To use either movie, start the movie and log in to the Admin Service using the
administrator username and password that you defined when you installed the
server. Macromedia provides information on using the Administration Console and
Communication App Inspector in Managing Flash Communication Server and Devel-
oping Communication Applications, both available from:
http://www.macromedia.com/support/flashcom/documentation.html
The Communication Application Inspector is particularly useful while developing
and debugging applications as covered in Chapter 4 under “Using the App Inspector
to Run Scripts.” You can also create your own Flash movies and communication
applications that connect to the Admin Service. Chapter 10 describes the services
that are available via the Admin Service and how to use the Server Management API.
Hello Video!
I’d like to dive in and take you through building a very simple video conference
application. The application is designed to demonstrate many of the different things
described in this chapter, such as publishing and playing streams and updating and
responding to changes in a shared object. If you don’t understand all the code as I
walk through it, don’t worry. The idea is to provide a quick tour to building a com-
munication application. The rest of the book explains everything in much greater
detail. Although a premade video chat application already exists, this is good expo-
sure to the concepts and operations you’ll need when you build your own applica-
tions.
Setting Up helloVideo on the Server
Creating the helloVideo application on the server requires you find the applications
directory and add a subdirectory named helloVideo. After the default installation on
my system, the applications directory is located at:
C:\Program Files\Macromedia\Flash Communication Server MX\applications
Once you create the helloVideo subdirectory, you have created a FlashCom applica-
tion. Now you need to provide the application with its unique server-side behavior.
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
20
|
Chapter 1: Introducing the Flash Communication Server
Create a plain text file named main.asc and save it into the helloVideo directory. You
can use any plain text editor such as the one included with Flash MX Professional
2004 or Dreamweaver MX 2004. Example 1-1 shows the source code you should add
to the main.asc file.
You can also download the source files for the helloVideo example from the book’s
web site (http://www.flash-communications.net). The main.asc file will be loaded,
compiled, and run by the server when the first client attempts to connect to a
helloVideo instance. The application.onAppStart( ) method will be called once after
the file is executed. From then on, whenever a movie tries to connect, the applica-
tion.onConnect( ) method will be called, and when a movie disconnects, application.
onDisconnect( ) will be called.
The main.asc file listed in Example 1-1 is designed to do three things:
Only four clients are allowed to connect at any time. So the application creates
four unique user ID values, assigns one to each client when it connects, and
reclaims the ID when the client leaves.
It notifies each client of its ID by calling a remote method of the client after the
connection succeeds.
It updates a shared object when a client arrives or leaves so that all the other cli-
ents know who is connected and the name of each client’s stream to play.
The application does not use Flash Remoting to connect to an authentication data-
base or directory server. It is a simple demonstration program and is not designed for
security. See Chapter 18 for information on designing and building secure
Example 1-1. The main.asc file for the helloVideo application
idPool = ["guest_1", "guest_2", "guest_3", "guest_4"];
application.onAppStart = function ( ) {
users_so = SharedObject.get("users");
};
application.onConnect = function (client, name) {
if (idPool.length <= 0) {
application.rejectConnection(client, {msg:"Too many users."});
}
client.id = idPool.pop( );
application.acceptConnection(client);
client.call("setID", null, client.id);
users_so.setProperty(client.id, name);
};
application.onDisconnect = function (client) {
idPool.push(client.id);
users_so.setProperty(client.id, null);
};

Get Programming Flash Communication Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.