《Red5 用户参考手册》之四:入门第三章 迁移指南
官方最新《Red5 用户参考手册》全套下载地址
本文档介绍了 Macromedia Flash 通信服务器/Adobe Flash 媒体服务器和 Red5 之间的 API 差异,目的是帮助我们将现有的应用转移至 Red5。
如果你还没有基于 Red5 的应用,请先阅读有关创建一个新的 Red5 应用程序的文档。
程序回调
当实现一个服务端的程序时,最重要的功能之一就是通知客户是否连接成功并等待应用程序的新实例的创建的通知。
IScopeHandler 接口
Red5 将这些行为指定在 IScopeHandler 接口 http://dl.fancycode.com/red5/api/org/red5/server/api/IScopeHandler.html。请阅读 API 文档来获得详细信息。
ApplicationAdapter 类
鉴于有些方法可能会在一个请求中多次被调用到(比如,连接可能会被客户端连接到的树中的每一个域都调用一次),类 ApplicationAdapter http://dl.fancycode.com/red5/api/org/red5/server/adapter/ApplicationAdapter.html 定义了附加方法。
这个类经常被用来作为新应用的基类。
以下是 FCS/FMS 的 application 类和 Red5 的 ApplicationAdapter http://dl.fancycode.com/red5/api/org/red5/server/adapter/ApplicationAdapter.html 类的方法的一个简单对比。
FCS / FMSRed5onAppStartappStart \\ roomStartonAppStopappStop \\ roomStoponConnectappConnect \\ roomConnect \\ appJoin \\ roomJoinonDisconnectappDisconnect \\ roomDisconnect \\ appLeave \\ roomLeave
app 相关方法是由主应用进行调用,room 相关方法则由应用程序的 room(比如,实例)来调用。Red5 支持两种不同的方式来从一个被调用的方法中访问当前连接。连接可以用于获取活动客户端以及他连接到的域。第一种可能性(方式)就是使用"神奇的"Red5http://dl.fancycode.com/red5/api/org/red5/server/api/Red5.html 对象:
import org.red5.server.net.remoting.RemotingClient; import org.red5.server.net.remoting.IRemotingCallback; public class CallbackHandler implements IRemotingCallback { void errorReceived(RemotingClient client, String method, Object[] params, Throwable error) { // An error occurred while performing the remoting call. } void resultReceived(RemotingClient client, String method, Object[] params, Object result) { // The result was received from the server. } } String url = "http://server/path/to/service"; RemotingClient client = new RemotingClient(url); Object[] args = new Object[]{"Hello world!"}; IRemotingCallback callback = new CallbackHandler(); client.invokeMethod("service.remotingMethod", args, callback);