Red5 Plugin

This plugin is written for the Groovy on Grails web application framework, and intends to make it relatively easy to add Flash Server capabilities to a Grails project. The goals of this plugin are as follows:

  • Provide an simple mechanism to develop new flash server applications with Red5 in Grails
  • Provide Red5 applications the ability to use the infrastructure services of Grails i.e., GORM, Services, Domain Classes, Bean Builders, etc.
  • Create Red5 applications with Groovy
  • Provide an object model that tracks the activity of Flash Communication, streams, rich iteration, etc.
  • Tie Red5 applications into a Spring Security model provided by Grails to secure flash remoting and stream applications
  • Provide a deep integration between Grails and Red 5
  • Use open source technologies

To achieve these goals, the plugin directly integrates Red5 into a Grails war/application. For the first revision of the plugin, the focus is on the core integration of Red5 and providing a simple process for developing a new Red5 application in Grails. Later revisions will provide advanced analytics on the Flash Communication activity as well as tying these applications into a Spring Security model.

Features
The initial revision of the plugin focuses on the core integration with Red5. As such it provides these features:

Current Features

  • Grails artifact that implements a Red5 application which allows the Red5 app to use the GORM
  • A Grails target that simplfies creation of a new Red5 application
    • create-red5-app
  • Red5 demo applications setup. Included to test the correct installation of the plugin as well as a reference application to demo the functionality provided by Red5
  • Configuration by convention setup of Red5 scopes/context

We are also planning several more features to be released in the near future.

Planned Features

  • Flash communication analytics
  • Spring Security integration to secure streams and remoting apps

Requirements

This plugin was built using the Groovy on Grails version 1.0 RC1 and the v0.6.3 release of Red5. We will make every effort to update the plugin to the final 1.0 release and with future upgrades of the Red5 code base. The plugin has also been tested against Groovy 1.0 and the latest release candidate for Groovy 1.1.

Installation

  1. Download the latest version of the plugin using the link below:
    grails-red5-0.1.zip (30 MB)
  2. Install the plugin:
    grails install-plugin <path to your downloaded plugin zip>
  3. Startup the project
  4. Test the installation by viewing movies here - http://localhost:8080/<projectname>/plugins/red5-0.1/demos/ofla_demo.swf

PLEASE NOTE: The default installation will only handle RTMP connections. To tunnel over http (RTMPT) you will need to modify your development environment to serve the web application on the root context (remove <projectname> from the url) or setup a web server to front grails which forwards traffic to the url with project name in it. Click here for instructions to run the grails dev environment as context root.

 

Upon review and acceptance from the Grails community we will move the plugin to the official Grails plugin repository located at http://svn.codehaus.org/grails-plugins/.

Project modifications

On installation the plugin creates two folders in the grails project. The first folder is called "red5" under the grails-app directory. The red5 folder holds Red5 application artifacts. The second folder is called "streams" under the web-app directory. This folder is used by the Red5 demo application called oflaDemo to hold FLV files for streaming or that have been recorded. An example of the project directory structure after a properly installed plugin is given below:

...
grails-app\controllers
grails-app\domain
grails-app\jobs
grails-app\red5 //place for custom Red5 apps
grails-app\services
grails-app\taglib
grails-app\utils
grails-app\views
...
web-app\js
web-app\plugins
web-app\streams //some sample FLV’s are copied here on installation
...

Target(s)

Additionally, on installation, the plugin adds a new target that facilitates the setup of a new Red5 application groovy class. The target is named "create-red5-app". When executing this target, the command prompt will ask for a new name of the Red5 application. This will determine the name of the application class created under grails-apps\red5. For example, if I entered "Test" at the command prompt the following groovy class would be created under the red5 folder:

import org.red5.server.adapter.ApplicationAdapter;

class TestRed5App extends ApplicationAdapter {

    //TODO: insert remoting methods

}

PLEASE NOTE: This class is a singleton. Developers should be careful when storing state in class member variables.

Red5 Scope/Context Configuration By Convention

The default installation of the plugin creates the spring configuration for global, root, echo, SOSimple and oflaDemo scopes/context. When creating a brand new Red5 application in Grails using the create-red5-app target, the plugin will add a new Red5 scope/context configuration to spring using the naming convention of the groovy class. For example, the "TestRed5App" application described above would have the following spring configuration created for it on startup:

beans {

    //my grails test app
    ‘web.context.Test‘(org.red5.server.Context) { bean ->
        scopeResolver=ref("red5.scopeResolver")
        clientRegistry=ref("global.clientRegistry")
        serviceInvoker=ref("global.serviceInvoker")
        mappingStrategy=ref("global.mappingStrategy")
    }

    ‘web.scope.Test‘(org.red5.server.WebScope) { bean ->

        bean.initMethod="register"
        server=ref("red5.server")
        parent=ref("global.scope")
        context=ref("web.context.Test")
        handler=ref("web.handler.Test)
        contextPath="/Test"
        virtualHosts="*,localhost, localhost:8080, 127.0.0.1:8080"
    }

    ‘web.handler.Test‘(TestRed5App){}

}

Flash applications can then connect to this Red5 Application via RTMP://locahost/Test.  Additionally, if you need finer control of the context and scope setup, you can override the default setup. To do this, add a resources.groovy file under the folder grails-app\conf\spring\ and use the Grails bean build syntax (see above) to configure the scope and context. For more information about configuring scopes please see the Red5 documentation.

Remoting

To connect to the Red5 application created above use following actionscript code:

var connecturl = "rtmp://localhost/Test";
trace(connecturl);

//setup new NetConnection to execute methods
var nc = new NetConnection();
nc.connect(connecturl);

//setup status checker in flash
nc.onStatus = function(obj){

    for(e in obj)
        trace(e + " : " + obj[e]);
}

//setup remote method handler in flash
nc.onResult = function(obj){

    //TODO: handle remote method result
}

//call remote method
nc.call("<remote method name>", nc);

Licensing

This plugin code is open source and is licensed under the Apache License, version 2.0 (http://www.apache.org/licenses/LICENSE-2.0).

Please see Red5 documentation for the Red5 licensing - http://osflash.org/red5

Feedback

The Grails community has been an amazing resource during our own development with the Groovy and Grails framework and we welcome (and hope for) feedback from the community on the design and purpose of the plugin as well as possible usability and performance enhancements. We’re constantly checking the Grails Mailing Lists for comments and feedback on the plugin. You can also reach us using Contact Us or by emailing us at info@cantinaconsulting.com.