This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
158
|
Chapter 5: Managing Streams
that streams will be unintentionally overwritten or deleted. Here are a few ways to
allocate relative URIs to streams to avoid name conflicts:
In live video conference and chat systems, use each user’s unique username or
ID to name the stream that each user publishes. If each user publishes more than
one stream, use sequence values appended to the user’s name. In some cases, the
instance name of a movie clip can be appended to the user’s name.
Use directory names to group streams. For example, each user could record
streams to his own directory named after his unique username. You can extend
this idea even further by controlling write access to certain directories using a
server-side script. For example, if a unique username is assigned to each user,
then the code
client.writeAccess = "/" + userName; will restrict the Flash
movie represented by the
client object from writing to anything unless it is
within the user’s own directory.
Use remote method calls to request unique names from the server. See Chapters
8 and 9 on remote method calls and shared objects. Examples include sequence
numbers generated on the server and validating user-suggested stream URIs
before they are used to make sure only one user can use a URI.
Append a timestamp or other unique sequence value to a stream name.
Publishing Streams in Detail
The NetStream.publish( ) method can be used to publish live or recorded streams and
to append data onto the end of an already recorded stream. To control how a stream
is published, pass the string “live”, “record”, or “append” as the second parameter.
For example, to append onto an already recorded stream:
out_ns = new NetStream(nc);
out_ns.publish("private/brian/greeting", "append");
When “live” or “record” is used, any previously recorded stream with the same
stream URI is deleted. When “append” is used, data is appended onto the end of a
preexisting stream. If a recorded stream at the same URI does not already exist,
“append” creates the stream as though “record” was passed.
The stream will be saved as an .flv file within a subdirectory of the streams folder
associated with the application instance. For example, assuming a Flash movie is
connected to the instance
albegra101 of an application named courseChat and that
the relative URI of a published stream is:
private/brian/greeting
a file named greeting.flv will be created within this directory:
.../applications/courseChat/streams/algebra101/private/brian

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.