AVCastManager

Kind of class:public class
Package:com.smartfoxserver.v2.redbox
Inherits from:BaseAVManager < EventDispatcher
Version:1.0.0 for SmartFoxServer 2X
Author:The gotoAndPlay() Team
http://www.smartfoxserver.com
Classpath:com.smartfoxserver.v2.redbox.AVCastManager
File last modified:Thursday, 05 May 2011, 09:59:46
SmartFoxServer 2X RedBox Audio/Video Broadcast Manager.
This class is responsible for managing audio/video live casts inside the SmartFoxServer Room joined by the user, making it possible to create live web events or a/v conferences.
The AVCastManager handles the live cast publishing/playing to/from the Red5 server.
Unlike the other RedBox classes, the AVCastManager works on a Room basis to leverage the access control and moderation features of SmartFoxServer rooms.

NOTE: in the provided examples, avCastMan always indicates an AVCastManager instance.
Usage:
  • The most common usages for the AVCastManager class are video conference applications and live webcast applications (for example live online seminars).

    Video conference
    In this kind of application, each user publishes his own live stream and subscribes the streams coming from the other users in the same SmartFoxServer Room. The following workflow is suggested.
    1. The current user joins the room where the video conference takes place.
    2. The list of currently available streams (or "live casts") is retrieved by means of the getAvailableCasts method (in case the conference is already in progress).
      Calling this method also enables the reception of the RedBoxCastEvent.LIVE_CAST_PUBLISHED and RedBoxCastEvent.LIVE_CAST_UNPUBLISHED events which notify if another user started or stopped his own stream.
    3. Each live cast is subscribed by means of the subscribeLiveCast method and a Video object is displayed on the stage to attach the stream to.
      When a live cast is published (a new user joins the conference) or stopped (a user leaves the conference), a notification is received by means of the above mentioned events: the stream is subscribed / unsubscribed and displayed on / removed from the stage.
    4. The a/v stream for the current user is published by means of the publishLiveCast method and an additional Video object showing the user own camera stream is added on the stage; when the current user publishes his own stream, the other users receive the above mentioned events.
    5. To make the current user leave the conference, the unpublishLiveCast method is called. Also changing Room causes the user to leave the conference and the other users to be notified.

    Live webcast
    In this kind of application, a single user publishes his own live stream and all the other users in the same room subscribe it. The following workflow is suggested.
    1. The publisher joins the Room where the live webcast takes place.
    2. The a/v stream for the user is published by means of the publishLiveCast method and a Video object showing the user own camera stream is added on the stage; when the current user publishes his own stream, the other users already in the room receive the RedBoxCastEvent.LIVE_CAST_PUBLISHED event and the stream can be subscribed (see step 4).
    3. The webcast spectators join the room and retrieve the list of available streams (one item only if the publisher is already streaming, otherwise the list will be empty).
    4. If the live webcast is already started, it can be subscribed by means of the subscribeLiveCast method; otherwise the RedBoxCastEvent.LIVE_CAST_UNPUBLISHED event must be waited for before calling this method.
    5. On all the subscribers clients a Video object is displayed on the stage to attach the stream to.
Events broadcasted to listeners:
  • RedBoxCastEvent with type: LIVE_CAST_PUBLISHED
    • Dispatched when a user in the current room published his own live stream.
  • RedBoxCastEvent with type: LIVE_CAST_UNPUBLISHED
    • Dispatched when a user in the current room stops his own live stream.

Summary


Constructor
  • AVCastManager (sfs:SmartFox, red5Ip:String, useRTMPT:Boolean = false, debug:Boolean = false)
    • AVCastManager contructor.
Instance properties
Instance properties inherited from BaseAVManager
Instance methods
  • destroy : void
    • Destroy the AVCastManager instance.
  • getAvailableCasts : Array
    • Retrieve the list of available live broadcasts for the current Room.
  • stopPublishNotification : void
    • Stop receiving live cast published/unpublished events.
  • subscribeLiveCast (castId:String) : NetStream
    • Subscribe a live cast to receive its audio/video stream.
  • unsubscribeLiveCast (castId:String) : void
    • Unsubscribe a live cast to stop receiving its audio/video stream.
  • unsubscribeAllLiveCasts : void
    • Unsubscribe all currently subscribed live casts.
  • publishLiveCast (enableCamera:Boolean = true, enableMicrophone:Boolean = true) : NetStream
    • Start broadcasting the current user's live stream.
  • unpublishLiveCast : void
    • Stop broadcasting the current user's live stream.

Constructor

AVCastManager

public function AVCastManager (
sfs:SmartFox, red5Ip:String, useRTMPT:Boolean = false, debug:Boolean = false)

AVCastManager contructor.
Parameters:
sfs :
the SmartFox API main class instance.
red5Ip :
the Red5 server IP address (include the port number if the default one is not used).
useRTMPT:
connect to Red5 server using the HTTP-tunnelled RTMP protocol (optional, default is false); Red5 must be configured accordingly.
debug :
turn on the debug messages (optional, default is false).
Example:
  • The following example shows how to instantiate the AVCastManager class.
    var smartFox:SmartFox = new SmartFox();
    var red5IpAddress:String = "127.0.0.1";
    
    var avCastMan:AVCastManager = new AVCastManager(smartFox, red5IpAddress);

Instance methods

destroy

override public function destroy (
) : void

Destroy the AVCastManager instance.
Calling this method causes the interruption of all the playing streams (if any) and the disconnection from Red5.
This method should always be called before deleting the AVCastManager instance.
Example:
  • The following example shows how to destroy the AVCastManager instance.
    avCastMan.destroy();
    avCastMan = null;

getAvailableCasts

public function getAvailableCasts (
) : Array

Retrieve the list of available live broadcasts for the current Room.
The list is populated by the AVCastManager class as soon as it is instantiated and each time a new Room is joined.
When this method is called, the RedBoxCastEvent.LIVE_CAST_PUBLISHED and RedBoxCastEvent.LIVE_CAST_UNPUBLISHED events dispatching is enabled, in order to be notified when users in the current Room start/stop streaming.
In order to turn off events notification, the stopPublishNotification method should be called.
Returns:
Example:
  • The following example shows how to loop through the list of live casts available for the current Room.
    for each (var liveCast:LiveCast in avCastMan.getAvailableCasts())
    {
        // Subscribe live cast
        var stream:NetStream = avCastMan.subscribeLiveCast(liveCast.id);
    
        // Display a/v stream on stage
        ...
    }

publishLiveCast

public function publishLiveCast (
enableCamera:Boolean = true, enableMicrophone:Boolean = true) : NetStream

Start broadcasting the current user's live stream.
Calling this method causes the RedBoxCastEvent.LIVE_CAST_PUBLISHED event to be fired on the other users clients.
Audio and video recording mode/quality should be set before calling this method. In order to alter these settings, please refer to the flash.media.Microphone and flash.media.Camera classes documentation.
Also, the user must join a Room before calling this method.
Parameters:
enableCamera :
enable video live streaming; default value is true.
enableMicrophone:
enable audio live streaming; default value is true.
Returns:
  • The flash.net.NetStream object representing the user's outgoing stream.
Events broadcasted to listeners:
  • RedBoxCastEvent with type: LIVE_CAST_PUBLISHED
    • Dispatched when a user in the current room published his own live stream.
Throws:
Example:
  • The following example shows how to publish the current user's live stream.
    avCastman.publishLiveCast(true, true);

stopPublishNotification

public function stopPublishNotification (
) : void

Stop receiving live cast published/unpublished events.

subscribeLiveCast

public function subscribeLiveCast (
castId:String) : NetStream

Subscribe a live cast to receive its audio/video stream.
Parameters:
castId:
(String) the id of the LiveCast object to be subscribed.
Returns:
  • A flash.net.NetStream object.
Throws:
Example:
  • The following example shows how to subscribe a live cast when a publishing notification is received.
    avCastMan.addEventListener(RedBoxCastEvent.LIVE_CAST_PUBLISHED, onLiveCastPublished);
    
    // A user publishes his own live cast...
    
    function onLiveCastPublished(evt:RedBoxCastEvent):void
    {
        var liveCast:LiveCast = evt.params.liveCast;
    
        // Subscribe live cast
        var stream:NetStream = avCastMan.subscribeLiveCast(liveCast.id);
    
        // Display a/v stream on stage
        ...
    }
See also:

unpublishLiveCast

public function unpublishLiveCast (
) : void

Stop broadcasting the current user's live stream.
Calling this method causes the RedBoxCastEvent.LIVE_CAST_UNPUBLISHED event to be fired on the other users clients.
Events broadcasted to listeners:
  • RedBoxCastEvent with type: LIVE_CAST_UNPUBLISHED
    • Dispatched when a user in the current room stops his own live stream.
Example:
  • The following example shows how to unpublish a live cast.
    avCastMan.unpublishLiveCast();

unsubscribeAllLiveCasts

public function unsubscribeAllLiveCasts (
) : void

Unsubscribe all currently subscribed live casts.

unsubscribeLiveCast

public function unsubscribeLiveCast (
castId:String) : void

Unsubscribe a live cast to stop receiving its audio/video stream.
NOTE: when a user stops his own stream or leaves the current Room / disconnects from SmartFoxServer while his stream is in progress, the AVCastManager class automatically unsubscribes the live cast before dispatching the RedBoxCastEvent.LIVE_CAST_UNPUBLISHED event.
Parameters:
castId:
(String) the id of the LiveCast object to be unsubscribed.
Example:
  • The following example shows how to unsubscribe a live cast.
    avCastMan.unsubscribeLiveCast(liveCast.id);