0

我正在尝试更改fitcDemoRed5 应用程序的源代码,并在让它连接到服务器之前以某种方式验证用户名,但我不知道如何开始!
我的意思是我不知道客户端连接时将调用哪个方法以及如何从客户端应用程序获取用户名。
我会把源代码带到这里,以便有人可以帮助我。

package org.xyz;

import java.util.List;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IClient;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.Red5;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.api.service.IServiceCapableConnection;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IPlayItem;
import org.red5.server.api.stream.IPlaylistSubscriberStream;
import org.red5.server.api.stream.IStreamAwareScopeHandler;
import org.red5.server.api.stream.ISubscriberStream;


public class Application extends ApplicationAdapter
  implements IPendingServiceCallback, IStreamAwareScopeHandler
{
  protected static Log log = LogFactory.getLog(Application.class);

  public boolean appStart(IScope scope)
  {
    return true;
  }

  public boolean appConnect(IConnection conn, Object[] params)
  {
    IServiceCapableConnection service = (IServiceCapableConnection)conn;
    log.info("Client connected {} conn {}");
    service.invoke("setId", new Object[] { conn.getClient().getId() }, this);
    return true;
  }

  public boolean appJoin(IClient client, IScope scope)
  {
    log.info("Client joined app {}");

    IConnection conn = Red5.getConnectionLocal();
    return true;
  }

  public void streamPublishStart(IBroadcastStream stream)
  {
    if (log.isDebugEnabled()) {
      log.debug("stream broadcast start: {}");
    }
    IConnection current = Red5.getConnectionLocal();
    for (Set<IConnection> connections : this.scope.getConnections())
      for (IConnection conn : connections) {
        if (conn.equals(current))
        {
          continue;
        }

        if ((conn instanceof IServiceCapableConnection)) {
          ((IServiceCapableConnection)conn).invoke("newStream", new Object[] { stream.getPublishedName() }, this);

          if (log.isDebugEnabled())
            log.debug("sending notification to {}");
        }
      }
  }

  public void streamRecordStart(IBroadcastStream stream)
  {
  }

  public void streamBroadcastClose(IBroadcastStream stream)
  {
  }

  public void streamBroadcastStart(IBroadcastStream stream)
  {
  }

  public void streamPlaylistItemPlay(IPlaylistSubscriberStream stream, IPlayItem item, boolean isLive)
  {
  }

  public void streamPlaylistItemStop(IPlaylistSubscriberStream stream, IPlayItem item)
  {
  }

  public void streamPlaylistVODItemPause(IPlaylistSubscriberStream stream, IPlayItem item, int position)
  {
  }

  public void streamPlaylistVODItemResume(IPlaylistSubscriberStream stream, IPlayItem item, int position)
  {
  }

  public void streamPlaylistVODItemSeek(IPlaylistSubscriberStream stream, IPlayItem item, int position)
  {
  }

  public void streamSubscriberClose(ISubscriberStream stream)
  {
  }

  public void streamSubscriberStart(ISubscriberStream stream)
  {
  }

  public List<String> getStreams()
  {
    IConnection conn = Red5.getConnectionLocal();
    return getBroadcastStreamNames(conn.getScope());
  }

  public void resultReceived(IPendingServiceCall call)
  {
    log.info("Received result {} for {}");
  }
}
4

1 回答 1

1

尽管 Red5 提供了这样做的方法: 如何使用 Red5 API 识别发布者和消费者, 但我需要使用数据库以不同方式识别它们,所以这是我的方法。假设您已经将数据库与 red5 中的用户相关表连接起来。如果没有,官方教程是一个很好的起点: http ://www.red5tutorials.net/index.php/Tutorials:MySQL_and_Red5 虽然该教程是针对 MySQL 的,但您可以为您的数据库使用适当的 JDBC 驱动程序。

首先,您需要使用 as3 在 Flash 中 NetConnection 的 connect() 中从客户端发送一个用户 ID:

var nc:NetConnection = new NetConnection();
var userID:String = "foo";
nc.connect("rtmp://" + ipAddrOfRed5Server + "/fitcDemo", userID);

在 Red5 中:

public boolean appConnect(IConnection conn , Object[] params )
{
    try { 
         String uID = (String)params[0];             
         //Run a query here to check if the user exists in the DB. 
             // If not, you can call rejectClient("Not an existing user!");
             // Once authenticated here, your normal logic follows
    }
    } catch(Exception e){
        e.printStackTrace();
        log.error("Error handling User connect"); 
    }       
    return true;

}
于 2012-05-24T07:24:32.443 回答