Chapter 5. Managing Streams


Streams are a way to organize and manage the flow of data over a network connection. Audio, video, and ActionScript data can all be carried within a stream. Data within each stream flows in only one direction, but streams can carry more than one type of data, and multiple streams can be created within a single network connection. In many applications, a stream will carry audio and video from a Flash movie to the FlashCom Server while other streams will carry audio and video from the server to the movie. Within a Flash movie the NetStream class is used to create and manage streams, while on the server the Stream class is used.

Audio and video data is transferred over a network connection by attaching it to a stream. In FlashCom 1.5.2, a stream can contain only one audio and one video channel. A movie that creates a stream within a network connection and uses the stream to send data is publishing data, while a movie that creates a stream to receive data is a subscriber . A movie must create separate streams within a connection in order to both publish and subscribe at the same time. Streams can also carry more traditional data such as strings, numbers , and objects and are FlashCom's primary method for storing very large quantities of any kind of data on the server. FlashCom streams can be recorded and saved to disk by FlashCom in Flash Video format (FLV) files.

The client-side NetStream class can be used to publish or subscribe to a stream. The Stream class is used on the server to manage or republish streams that are being published by a remote movie or that have already been stored as FLV or MP3 files on a server.

Flash movies must use both a NetConnection and a NetStream object to publish a stream to a specific application instance. Within the instance, the stream is associated with a unique relative URI that identifies the stream, which other movies can use to subscribe. In this way, the application instance acts like a hub that provides a stream namespace. A stream is published to it so that it can be subscribed to by any movie connected to the instance. Chapter 5 shows two Flash movies connected to an instance of the courseChat application named algebra101 . Each movie has created two separate NetStream objects named out_ns and in_ns . Each movie is publishing a live stream with a unique URI and has subscribed to (or is playing) another stream. A live stream is a stream that is currently being published by a movie. As the stream data arrives at the server, it is immediately sent to any movie that subscribes to it. The location of each stream's relative URI is shown within the server in Figure 5-1, and the arrows indicate the direction data is flowing within each stream.

Figure 5-1. Illustration of the use of the publish( ) and play( ) methods and the stream namespace within an application instance

It is also possible to share live streams between application instances. Just as one Flash movie can connect to an application instance in order to subscribe to a stream, an application instance can also connect to another instance in order to subscribe to that instance's streams. In turn , the subscribing instances can make streams available to movies that connect to them. FlashCom instances subscribe using the server-side Stream class, as opposed to Flash movies, which subscribe using the client-side NetStream class.

Similarly, streams can be shared between FlashCom Servers by having an instance on one server connect to an instance on another and then subscribe to the other's streams, as shown in Figure 5-2. The server-side Stream class cannot be used to publish video or audio from sources connected to the server. Live video and audio capture must be done within a Flash movie and published to the server using the NetStream class. However, the server-side Stream class can be used to manage streams published by movies, create server-side playlists, and provide fine-grained access control to streams.

Figure 5-2. Chaining a stream between application instances running on separate FlashCom Servers

It is possible to subscribe to two types of streams: live and recorded . Both exist in the same namespace within an application instance. When movies subscribe to a live stream, each subscriber is sent its own copy of the stream data as it arrives from the publisher. When movies subscribe to a recorded stream, each movie can begin playing the stream from the beginning or randomly access different parts of the recorded stream at any time. When a movie publishes a stream, it can also be recorded on the server. As a stream is being recorded, it can be subscribed to as a live streamin which case each movie is sent a copy of the same stream data as it arrives from the publisher at the server. A stream that is being recorded can also be played as a recorded streamin which case movies will receive copies of what is on disk and will not be sent the live data as it arrives at the server. Streams can also be live-onlyin which case they are not recorded.



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net