Overview

Authentication is the process of providing credentials to a remote process, having those credentials verified and given access to the requested resource. In the context of Red5 Pro, these credentials are typically collected via a form, attached to the connection and sent to the server whereby you can handle them. In the connection handler, you can choose to verify these credentials using a database and then either accept the connection or deny the connection. The clientside SDKs can then handle the result of this process when the server sends back the response.

Download the Red5 Pro Server Download the latest Red5 Pro Server!

Register A Red5 Pro Account

If you have not done so already, register for an account at https://account.red5pro.com.

* A Trial Account allows for up to 10 concurrent connections, while the Professional license has no connection limit.


Requirements

The following are required to setup the Red5 Pro Server and to follow along with this example:

The Red5 Pro server requires Java 1.7+ or higher. Install Java 1.7+ or higher if not already installed on your machine.


Red Pro Server Installation

  1. Download the Red5 Pro server from the downloads section of the Red5 Pro Accounts site.
  2. Unzip into a location on your local system. For the purposes of this tutorial, we will unzip the Red5 Pro server to: /Users/red5pro-user/red5pro on OSX or /home/red5pro-user/red5pro on Linux.
  3. Start the Red5 Pro server: •  On OSX & Linux: Open Terminal, cd into your Red5 Pro install directory and issue this command: ./red5.sh •  On Windows: Navigate to the Red5 Pro install directory in a File Browser and double-click on red5.bat
  4. After the server has started, open a web browser and navigate to http://localhost:5080
  5. If the server has started successfully, you should see the default landing page for the Red5 Pro server install •  The landing page can be found at /webapps/root/index.jsp of your Red5 Pro installation. You can modify or remove it as desired. For now, we will use it to navigate around and demonstrate what the Red5 Pro server can do!

Eclipse IDE

For the examples, we will be demonstrating how to set up the project in the Eclipse IDE. The steps for setup should be transferrable to the IDE of your choice, as it is the code and method of deployment that we will be more focused on.

Source Code

The source for this example can be checked out from the following Github repository: https://github.com/red5pro/red5pro-dev-series.git

Video Walk-Through

This documentation has an accompanying video walk through that you can follow as you are developing.

Create a Red5 Pro Application


Setup Workspace

In this section, you will setup your workspace by cloning the github repository, downloading our iOS SDk and setting up Eclipse.

Watch a demonstration of the current section
  1. Clone the Developer Series Github Repository
    1. Open a browser window and navigate to https://github.com/red5pro/red5pro-dev-series
    2. Click on the green Clone or download button to the right of the page
    3. Click on the Copy to clipboard icon to the right of the git URL
      View Screenshot
  2. Download Red5 Pro Streaming SDK for iOS.
    1. Open a browser, navigate and login to your account https://account.red5pro.com/login
    2. On the left side menu, click Downloads
    3. Scroll down and click on the download link for Download the Streaming SDK v#.#.# for iOS
    4. Once it finishes downloading, Expand the file.
  3. Open Eclipse to a clean workspace and import the example project
    1. Open Eclipse
    2. Create a new workspace. ie: /Users/daccattato/eclipse-workspace
    3. Click Launch
  4. Import the example projec
    1. Right-Click inside the Project Explorer and select Import > import...
    2. Expand the Maven folder and select Existing Maven Projects
    3. Click Browse to the right of the Root Directory: field
    4. Navigate to where you cloned the repository and select the subdirectory 04-creating-a-red5-pro-application
    5. Under the Projects: list, select the example/pom.xml
    6. Click Finish and let Maven resolve any errors you receive
  5. Verify that your workspace has no errors

Configure Security

Watch a demonstration of the current section
  1. In the Project Explorer view, expand example > src > main > webapp > WEB-INF
  2. Open red5-web.xml
  3. Below the web-handler bean add the following security bean

       <bean id="authDataValidator" class="com.red5pro.server.plugin.simpleauth.datasource.impl.Red5ProFileAuthenticationValidator" init-method="initialize">
         <property name="context" ref="web.context" />
         <property name="dataSource" value="/WEB-INF/simple-auth-plugin.credentials" />
       </bean>
    
       <bean id="simpleAuthSecurity" class="com.red5pro.server.plugin.simpleauth.Configuration" >
             <property name="active" value="true" />
             <property name="rtmp" value="true" />
             <property name="rtsp" value="true" />
             <property name="rtc" value="true" />
             <property name="rtmpAllowQueryParamsEnabled" value="true" />
         <property name="allowedRtmpAgents" value="*" />
       </bean>
    
  4. The authDataValidator bean above defines a custom credentials file that should be visibile from $RED5_HOME/webapps/example/WEB-INF. Let's set that up
    1. Copy the example credentials file located in $RED5_PRO_HOME/conf/simple-auth-plugin.credentials
    2. Switch back to Eclipse and expand example > src > main > webapp > WEB-INF
    3. Paste the copied file in the WEB-INF folder
  5. Add authentication credentials

    1. Open the simple-auth-plugin.credentials file
    2. Place your cursor at the bottom on a blank line
    3. Enter testuser testpass as the contents of the line. Usernames and Passwords are separated by a blank space. You can add more credentials with each Username/Password pair on a new blank line like so:

         #Simple auth credentials file
         #[ Add username and password as key-value pair separated by a space (one per line) ]
         #Example: testuser testpass
         #Wed Feb 22 18:22:07 IST 2017
         testuser testpass
      
  6. Save the file

Configure WebRTC Authentication

Watch a demonstration of the current section
  1. Inside of eclipse expand the folder example > src > main > webapp
  2. open publisher.html and add the connectionParams object inside of publisher.init(...)

          // Initialize
        publisher.init({
            protocol: 'ws',
            host: 'localhost',
            port: 8081,
            app: 'example',
            streamName: 'mystream',
            iceServers: iceServers,
            tcpMuxPolicy: 'negotiate',
            connectionParams: {username: "testuser", password: "testpass"}
          })
    
  3. open subscriber.html and add the connectionParams object inside of publisher.init(...)

           // Initialize
        subscriber.init({
            protocol: 'ws',
            host: 'localhost',
            port: 8081,
            app: 'example',
            streamName: 'mystream',
            iceServers: iceServers,
            subscriptionId: 'subscriber-' + Math.floor(Math.random() * 0x10000).toString(16),
            rtcpMuxPolicy: 'negotiate',
            connectionParams: {username: "testuser", password: "testpass"}
          })
    

Configure iOS Authentication

Watch a demonstration of the current section
  1. Open your Xcode project that you setup in the 3rd Video of the series www.youtube.com/watch?v=blRq4aUjbd8&list=PLl9CIHBHdK7aUHA52ZaCkX_JX_oL17Fgf&index=3
  2. Make sure you edit the SDK licensekey in your config and add the _config.parameters and set the username and password. Last, make sure you change the config.host and set config.contextName to example
         func getConfig()->R5Configuration{
             // Set up the configuration
             let config = R5Configuration()
             config.host = "192.168.0.8"
             config.port = 8554
             config.contextName = "example"
             config.`protocol` = 1;
             config.buffer_time = 0.5
             config.licenseKey = ""
             config.parameters = "username=testuser;password=testpass;"
             return config
         }
    

Package And Deploy

Watch a demonstration of the current section
  1. Right-Click the example application from the Project Explorer
  2. Select Run As > Maven install
  3. Deploy the Application
    1. From the Project Explorer view, expand example > target
    2. Right-Click the example folder and select Copy
    3. From your file system, navigate to $RED5PRO_HOME/webapps/_
    4. Paste the copied example folder into the webapps directory

Start Server

Watch a demonstration of the current section
  1. Open a command prompt and navigate to $RED5_PRO_HOME
  2. Issue the following command sudo ./red5.sh

Verify Server Startup

  1. Open a browser and navigate to http://localhost:5080/

Test WebRTC Authentication

Watch a demonstration of the current section
  1. Open a browser and navigate to http://localhost:5080/example/publisher.html to publish a stream
  2. Open a browser and navigate to http://localhost:5080/example/subscriber.html to subscribe to the stream
  3. If the authentication went smoothly you should be seeing a stream

Test iOS Authentication

Watch a demonstration of the current section
  1. Make sure your device is selected and unlocked, then click Run
  2. When the application loads on your device, check the logs to see that the publisher connected properly
  3. Optionally set an incorrect username or password and see the publisher fail on it's connection

Conclusion

Congratulations! You have just added connection level authentication to your example Red5 Pro Server Application!

This tutorial only scratched the surface of what is capable with live streaming on the Red5 Pro Server. We hope you go forth and start stretching the limits :)


Troubleshooting

The following sections may aide in troubleshooting any issues may come across in trying the previous examples.

If you have further questions, please contact us at red5pro@infrared5.com

Required open ports

The following default ports are required to be open in order to allow for Live Streaming and Second Screen:

  • 5080 : default web access of Red5
  • 1935 : default Red5 RTMP port
  • 8554 : default RTSP port
  • 8088 : default Second Screen Client registry
  • 6262 : default Second Screen Host registry