19- Add Code to your Red5 Application

  1. CREATE NEW CLASS THAT EXTENDS APPLICATIONADAPTER: Open eclipse, right click on your red5 project, (testapp for example), and select New, then select Class. In the Package field, type in a package name (com.testapp for example...its probably best to use the same one you typed into the command prompt when creating the project). In the Name field, type in the name for your class, the convention is to name it Application.java (the class that extends ApplicationAdapter is usually called Application.java). Then for the Superclass field, click on the Browse.. button next to it, then type in org.red5.server.adapter., and you can choose between ApplicationAdapter or MultithreadedApplicationAdapter. Most of the time, you'll want to choose MultithreadedApplicationAdapter, so that your application can accept multiple connections at the same time. So click on MultithreadedApplicationAdapter and click on OK button, then click Finish button.
  2. And now it has created a new class called Application which extends MultithreadedApplicationAdapter in the com.testapp package. (notice if you expand Java Resources: src folder in the project explorer, and then expand com.testapp package, you will see the Application.java class) You can override any of the functions in MultithreadedApplicationAdapter, but you don't have to. Any function you put inside this Application class, will be accessible to your client app. So if you put an "add" function like below:
    public int add(int a, int b)
    	return a+b;
    Then you can call it from your client app, with code like this:
    nc.call("add", responseHandler, 2, 3);
  3. Expand the www folder in your project, then expand the WEB-INF folder, and open red5-web.xml, find the web.handler bean, and make sure that the class= is set to the right path of your class that extends ApplicationAdapter.
    For example, if your class that extends ApplicationAdapter is called Application and it is in the com.testapp directory, then the web.handler bean's class should be set to com.testapp.Application. Like so:
    <bean id="web.handler" class="com.testapp.Application" />
  4. If you open red5-web.properties inside www/WEB-INF, you will see the contextPath is equal to testapp (by convention it will be the same as the project name). This is the name used by the client app to connect in the rtmp path (for example rtmp://localhost/testapp).

    NOTE: if you open web.xml and logback-testapp.xml, you will also see testapp within them... all these things need to match so it's best to leave it alone.

    TIP: if you open the xml files, and they are in Design mode, click on the Source tab at the bottom of the file and it will be easier to modify and work with.
« Back to Home