RTMP Application Code Generation

This page is complementary for the WebORB code generation feature for the RTMP applications. The feature generates Flex/AIR project files and sample code demonstrating the following functionality: 

  • Video Broadcast
  • Video Recording
  • Remote Shared Objects
  • Data Push from Server
  • Server Method Invocation

The last two items ("Data Push from Server" and "Server Method Invocation") require deployment of the application specific server-side code. The code is already pre-packaged with WebORB, so it is only a matter of setting up the configuration. The configuration steps are documented below. 

WebORB for Java Instructions

An implementation of the server-side class for the data push and client-to-server call functionality is shown below. For data push the class contains the StartDataPush() and EndDataPush() methods which will be invoked from the client (Flex/AIR) side to correspondingly start or stop the data push activity.

The same class contains the methods for the client-to-server invocations. The methods are EchoString and EchoArrayCollection:

 
package weborb.examples.rtmpdemo;
 
import org.red5.server.api.IConnection;
import org.red5.server.api.service.IServiceCapableConnection;
import weborb.messaging.WebORBApplication;
 
import java.util.*;
 
class DataPushTask extends TimerTask
{
  private AppHandler appHandler;
 
  DataPushTask( AppHandler appHandler )
  {
    this.appHandler = appHandler;
  }
 
  public void run()
  {
    this.appHandler.doDataPush();
  }
}
 
public class AppHandler extends WebORBApplication
{
  private Timer timer;
 
  public void StartDataPush()
  {
    timer = new Timer();
    timer.scheduleAtFixedRate( new DataPushTask( this ), 0, 1000 );
  }
 
  public void EndDataPush()
  {
    if( timer != null )
      timer.cancel();
  }
 
  protected void doDataPush()
  {
    Collection<Set<IConnection>> connections = scope.getConnections();
    Object[] args = new Object[] { "Server time is " + System.currentTimeMillis() };
 
    for( Set<IConnection> connectionSet : connections )
      for( IConnection connection : connectionSet )
        if( connection instanceof IServiceCapableConnection )
          ((IServiceCapableConnection) connection).invoke( "setLogText", args );
  }
 
  ///// METHODS FOR THE CLIENT-TO-SERVER INVOCATIONS
 
  public String EchoString( String str )
  {
    return str;
  }
 
  public ArrayList<String> EchoArrayCollection( ArrayList<String> list )
  {
    return list;
  }
}

The code shown above is already included in the WebORB for Java distribution. It is available in WEB-INF/lib/weborbexamples.jar. The code must be registered as a server-side application handler for the messaging application used to generate the client code.

  1. Locate and open in a text editor the application deployment descriptor file corresponding to the application for which the client code was generated. The application descriptor is an XML file typically with the "-web" suffix in the file name.
  2. The file contains the following line:
     <bean id="XXXXX.handler" class="weborb.messaging.WeborbApplication" singleton="true" />
  3. Replace the value of the "class" attribute with the name of the application handler shown above: "weborb.examples.rtmpdemo.AppHandler" so the configuration line looks as shown below:
     <bean id="XXXXX.handler" class="weborb.examples.rtmpdemo.AppHandler" singleton="true" />
  4. Save the file. Restart WebORB and the client-side application. 

WebORB for .NET Instructions

An implementation of the server-side class for the data push and client-to-server call functionality is shown below. For data push the class contains the StartDataPush() and EndDataPush() methods which will be invoked from the client (Flex/AIR) side to start or stop the data push activity.

The same class contains the methods for the client-to-server invocations. The methods are EchoString and EchoArrayCollection:

using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
 
using Weborb.Messaging.Api;
using Weborb.Messaging.Api.Service;
using Weborb.Messaging.Server.Adapter;
 
namespace Weborb.Examples.RTMPDemo
{
  public class AppHandler : ApplicationAdapter
  {
    private Timer timer;
 
    public void StartDataPush()
    {
      if( timer != null )
      {
        if( !timer.Enabled )
          timer.Enabled = true;
 
        return;
      }
 
      timer = new Timer();
      timer.Elapsed += new ElapsedEventHandler( Timer_Elapsed );
      timer.Interval = 1000;
      timer.Enabled = true;
      timer.Start();
    }
 
    public void EndDataPush()
    {
      if( timer != null )
        timer.Enabled = false;
    }
 
    void Timer_Elapsed( object sender, ElapsedEventArgs e )
    {
      DoDataPush();
    }
 
    private void DoDataPush()
    {
      IEnumerator<IConnection> en = scope.getConnections();
      Object[] args = new Object[] { "Server time is " + DateTime.Now.ToLongTimeString() };
 
      while( en.MoveNext() )
      {
        IConnection conn = en.Current;
 
        if( ( conn is IServiceCapableConnection ) )
          ( (IServiceCapableConnection) conn ).invoke( "setLogText", args );
      }
    }
 
    ///// METHODS FOR THE CLIENT-TO-SERVER INVOCATIONS
 
    public String EchoString( String str )
    {
      return str;
    }
 
    public List<String> EchoArrayCollection( List<String> list )
    {
      return list;
    }
  }
}

The code shown above is already included in the WebORB for .NET distribution. It is available in the bin/weborb.dll assembly. The code must be registered as a server-side application adapter for the messaging application used to generate the client code.

  1. Locate the folder corresponding to the messaging application for which the client-side code was generated. The folder must be present under the /Applications directory located in the root of the virtual directory where WebORB is running.
  2. If the message application folder does not contain the application configuration file (app.config), create a plain text file with the following contents. Otherwise, make sure the application-handler element contains the name of the class as shown below:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <application-handler>Weborb.Examples.RTMPDemo.AppHandler</application-handler>
    </configuration>
  3. Save the file and restart the application pool with the application where WebORB is running.