In this final chapter of Part III, you will learn how to create a FlashCom application and client that enable two users to conduct an audio/videoconference, which is recorded by the FlashCom application. A user can then open another client movie to watch any previously recorded session. Perhaps more than any other example in previous chapters, this application requires careful attention to the order of operationswhen streams and SharedObject instances are invoked and how properties are stored and retrieved. Among other techniques presented in this chapter, the uses of proxied SharedObject data and common stream file locations are discussed.
In order to build the application, you need to have access to a FlashCom server. Preferably, you should have a Developer installation of the FlashCom server on the same machine you are using to create the Flash documents.
An Overview of the Application
The conference application you are about to build must solve several problems that have not been explored in previous chapters and exercises. Before you go any further with the material in this section, try out the conference application at the following URL: http://www.mxbook.com/v1/ch13/
Before you enter the application, you may want to find another online friend who has a Webcam and a microphone and wants to participate in a chat with you. On the Web page at the book's Web site, click the conference recorder link. A Flash client movie (Figure 13.1) loads into the Web browser.
Figure 13.1 The conference recording client.
Two Input text fields are presented on the first screen, one from the conference's title and another for its room name (that is, the application instance's name). The title is preassigned with the current date. Type a room name into the appropriate field, and click the Proceed button.
You can only use alphanumeric characters and the underscore ( _ ) character in the room name. All other characters are prohibited in the field. If you are conducting a conference with another person, make sure that person uses the same room name that you entered.
When the next screen loads (Figure 13.2), you see some familiar UI elements discussed in previous chapters and examples, such as the SimpleConnect, ConnectionLight, SetBandwidth, and AVPresence components. Type a login name in the SimpleConnect component and click the Login button. Choose your preferred bitrate in the SetBandwidth instance. If you want to change the title of the conference session, change the title in the field at the bottom of the movie and click the Change button. In either of the AVPresence components, click the Send Audio/Video text link. Your audio and video will begin to stream to the FlashCom application instance, and any other user connected to this application instance will see your audio/video stream. If you have another friend participating in the chat, instruct him to begin streaming with the other instance of the AVPresence component. After you have spent a few moments conversing, close the Flash movie and instruct your friend to do so as well.
Figure 13.2 The chat frame of the recording client.
Go back to the original URL (http://www.mxbook.com/v1/ch13/) and click the conference retrieval link. This Flash client movie (Figure 13.3) has only one screen, where you can choose a previously recorded conference session in a ComboBox component. If necessary, log in to the FlashCom application by typing your name into the SimpleConnect instance and clicking the Login button. Choose the title of your conference session from the ComboBox instance. The audio/video streams from your conference will begin to play in the respective video windows of the client. You can also view any other videoconference recorded by other users of the application.
Figure 13.3 The conference retrieval client.
Streams recorded by public users of this example are frequently deleted from the FlashCom server used for the mxbook.com site. The degree of synchronization between the recorded streams largely depends on low latency values during the recording and playback of the streams. If the connection to the FlashCom server is slow, the two streams may play back with less-than- perfect synchronization.
While the operation of this Flash application may seem simple enough, several tasks must be accomplished in both client- and server-side ActionScript to accommodate these features. In the next two sections, you will examine the processes of this application.
Examining the User's Experience
To understand the goals of the application, each step of the application you tested in the last section is outlined. By looking at the tasks the user performs to interact with the application, you can better understand how to build the Flash client movie and FlashCom application code.
As with any multimedia project, the ability to define the process of a user interface is critical. Don't attempt to build an interface in any authoring tool until you have a plan. Even the most basic plan can save you hours, if not days or weeks, of development work. Granted, it's much simpler to deconstruct an existing example than it is to describe or map a concept from scratch. Most developers and UI designers create mock-ups in graphic design programs such as Macromedia FreeHand or Fireworks. You can even create paper mock-ups, with simple sketches of each user interface (or screen) within the application.
MAPPING THE CONFERENCE RECORDER PROCESS
Figure 13.4 illustrates the path a user takes to start a live conference session. This map begins to deconstruct the server-side operations within the Flash-Com application. The process involves two screens: a start screen where the user can specify a conference room and title, and a chat screen where the user can send and receive audio/video streams from another participant.
Figure 13.4 The process flowchart of the conference recording client.
CHARTING THE CONFERENCE RETRIEVAL PROCESS
The process for the second user interface is shown in Figure 13.5. This Flash client movie allows the user to connect to a FlashCom application and choose a previously recorded conference session from a combo box. When the selection is made in the combo box, the AV streams are presented to the user.
Figure 13.5 The process flowchart of the conference retrieval client.
Determining the Requirements
Now it's time to get down to brass tacks. You know what the application needs to do, but what factors do you need to consider to create such an application? What kind of application architecture do you need to construct that will allow several hundreds (if not thousands) of users to conduct chat sessions with one another?
MANAGING APPLICATION INSTANCES AND CONCURRENT SESSIONS
One of the objectives of this conference application is the ability to host several two-way chats for many simultaneous users. Therefore, each conference session needs its own application instance, just as you saw in the multiroom text chat example in Chapter 11. The name of the conference room is used as the instance name for the FlashCom application.While the conference recording client is engaged with one instance of the application, the default instance ( _definst_ ) needs to be available for users who want to view previously recorded sessions. In the next section, you will learn how information recorded from each application instance can be accessible by the default instance of the FlashCom application.
As you will learn later in this chapter, the actual name of the FlashCom application is conference. This name is referenced in the rtmp URI used in client- and server-side ActionScript code.
STORING INFORMATION FOR EACH SESSION
The conference retrieval client can retrieve the information for any recorded session. The retrieval client connects only to the default instance of the conference application on the FlashCom server. Hence, each recording session needs to save its information in a common namespace. For the conference application, the default application instance ( _definst_ ) is designated as this namespace.
There are three persistent remote SharedObject instances created by server-side ActionScript for each recording session (or application instance). Each of these instances creates an FSO file stored in the sharedobjects/_definst_ folder of the conference application.
av_1_timeTracker_so: This SharedObject instance creates a file that stores the recording information of the first user's AV stream. The details of the recording information are discussed in the next section. The name of the SharedObject FSO file is based on the following formula:
application instance name + "_" + stream number + "_" + current date
The instance name of the application is the same as the room name of the conference, and the stream number is either 1 or 2. The date information uses the following formula:
year + "_" + month + "_" + day + "_" + hour + "_" + minute
For example, if a person using the left AVPresence component in the Flash client movie connected to the application, the instance named family starts sending an AV stream on October 31, 2002 at 7:21 PM, and the FSO file will have the following name:
av_2_timeTracker_so: This SharedObject instance stores the recording information for the second user's AV stream. The second user is the person using the AVPresence component instance located on the right half of the Flash movie stage.
savedCalls_so: When each user has disconnected from an instance of the conference application (that is, when the application.clients.length property is less than 1 or equal to 0), the application instance stores the conference title, date (as established by the previous date formula), length (in milliseconds), and instance name. This information is saved as a new property name in the remote SharedObject file, savedCalls.fso, created by the instance. The name of this property uses the following formula:
application instance name + "_" + current date
The information stored in the savedCalls data is loaded into the conference retrieval client as soon as it loads. When a user selects a conference title in the combo box, the appropriate time tracker data is loaded from the other two remote SharedObjects.
Later in this chapter, you will learn about other temporary (non-persistent) remote SharedObject instances that are created to store other information used by the application instance.
Later in this chapter, you will learn about other temporary (non-persistent) remote SharedObject instances that are created to store other information used by the application instance.
Each instance of the conference application also records streamed audio and video from the AVPresence components to stored FLV files. You will learn more about the specific server-side ActionScript code to record streams later in this chapter. For now, it's important to understand that you can create virtual locations for stored streams on a FlashCom server. By default, if you create or record a stream within a specific application instance, the FLV file for that stream is saved within an instance folder of the streams folder for your application. For example, if you record a stream with a connection to the default instance of the conference application, the stream is saved in the following location:
If a Flash client movie wants to play a stream located in this folder, then the client must connect to the default instance of the application. If the movie is connected to another instance, only streams for that instance can be played. However, an XML configuration file for your FlashCom server allows you to specify virtual locations for stored streams. On your FlashCom server, locate the Vhost.xml file. With a default Windows installation of Flash Communication Server MX, this file is located in the following folder:
C:\Program Files\Macromedia\Flash Communication Server MX\conf \_defaultRoot_\_defaultHost_\Vhost.xml
Open this XML file in Macromedia Dreamweaver MX or your preferred XML document editor. If you scroll down to the <VirtualDirectory> node, the inserted comments tell you that you can specify virtual locations for streams. Later in this chapter, you create the following virtual path in this node, which adds a callStream alias name to your server's configuration:
The actual folder name in the physical path does not need to have the same name as the alias itself. You must restart your FlashCom server to register any newly added aliases.
When you create a virtual directory for a stream alias, you must specify the format aliasName;path. You need to provide a name for the stream alias, followed by a semicolon ( ; ) and the full path to the directory you want to use. You can use network paths as well, such as \\myLocalServer\myShareName\myFolder.
By adding this node to the <VirtualDirectory> node, you can make references to the callStreams alias in the stream name of a NetStream.publish() or Stream.get() method. For example, once the callStreams alias is created, the following client-side code creates an FLV file named myRecording in the callStreams folder of the conference application, where nc represents a valid NetConnection object reference and myCamera represents a Camera object:
myStream_ns = new NetStream(nc); myStream_ns.attachVideo(myCamera); myStream_ns.publish("callStreams/myRecording", "record");
Regardless of the application or application instance to which the nc object is connected, the myRecording.flv file is stored in the callStreams folder. This technique allows you to retrieve streams in the callStreams location from any application or application instance running on the FlashCom server. As such, you can create several common folders and aliases for streams, allowing you to save or play streams to and from other various locations, including networked drives.
As the Vhost.xml document's name suggests, stream aliases can be used by any application on the current virtual host domain of the FlashCom server. The Professional edition of FlashCom server allows one server to manage several virtual domains.
The intended purpose for saving SharedObject data in the _definst_ instance of the conference application and stream files to the callStreams alias is to enable the retrieval client movie to connect to just one application instance ( _definst_ ) to access information and streams for any recorded session. Regardless of the name of the application instance that was responsible for creating the session, the default instance of the application can access streams recorded by other application instances.
GATHERING INFORMATION FOR EACH SESSION
Most of the information stored in the three persistent remote SharedObjects mentioned in the previous section is created within the server-side Action-Script code of the conference application. Because a chat between two people occurs in real time, the application must track when each person begins publishing a stream and when that stream is stopped. This tracking (and subsequent saved data) is necessary for the chat to be replayed at a later time by the retrieval client.
In order to track the time, the application instance creates a property named startTime. This property is a Date object representing the time (in milliseconds) at which the first user clicks the Send audio/video text link within one of the AVPresence componentsor more exactly, when the server first receives the stream from that user's client. The conference session's length and the specific recording times of each user's streams can be determined by subtracting startTime from a new Date object. The onStatus() handler of the server-side Stream objects is used to capture the start and stop "moments" of each user's stream. Each set of start and stop times is saved as a separate object within a recordTimes array stored in each user's respective time tracker SharedObject (discussed in the previous section). You will learn more about these specific operations later in this chapter.
The server-side ActionScript code of the conference application also borrows information from the temporary remote SharedObject that was created for the AVPres-ence components. Each of these objects stores the user's login name (as entered in the SimpleConnect component instance). The user's name is retrieved from the respective SharedObject and stored in the user's recordTimes array.
The FlashCom Component Framework was introduced in the last chapter. Many of the Communication Components create remote SharedObjects that allow the components to share information among connected users, application instances, and other Communication Components.
The recording client also provides a text field for the conference's title. This text is stored (and synchronized) via another temporary remote SharedObject named sessionName. Any time a user changes the text within the title field in the Flash client and clicks the Change button, a property named title within the sessionName data is updated. The value of the title property is saved in the savedCalls SharedObject at the end of the recorded session.
RETRIEVING INFORMATION FOR ARCHIVED SESSIONS
When the retrieval client movie first loads, the movie connects to the default instance ( _definst_ ) of the conference application. Once a successful connection is made, the movie connects to savedCalls, the persistent remote SharedObject created (or modified) during a recorded session. Each named property of this object represents a recorded session, and the value of each property is an object with several other properties describing details of the session. One of these properties, confTitle, stores the title of the session (this value is actually retrieved from the SharedObject named sessionName, discussed in the previous section). The confTitle property from each session is used as the label property for each item in the ComboBox instance displayed in the retrieval client movie. The data property of each item is set to the respective property name of the savedCalls remote SharedObject. When a user selects a session's title in the combo box, this data property is used to retrieve the appropriate tracker SharedObject data for each recorded stream.
When the data for each user's recorded session is retrieved, a setInterval() function recreates the same timing mechanism used in the server-side Action-Script code. When the elapsed time of the client movie matches the start time of either user's recording session, the movie begins to play the saved stream. When the elapsed time matches the stop point of a user's recording, playback on that stream is stopped.
During a recording session, a user can start or stop publishing as many times as he or she deems necessary. Each start and stop point is saved in the recordTimes array for each user.