首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

red5 scope跟context 实践

2012-06-30 
red5 scope和context 实践SCOPE在Red5 中是以树的形式组织的。对于叶子结点,我们称之为BasicScope,如果有子

red5 scope和context 实践

SCOPE在Red5 中是以树的形式组织的。对于叶子结点,我们称之为BasicScope,如果有子结点的Scope,就叫Scope。 Red5当中有两种预定义的BasicScope,SharedObject Scope 和 BrodcastStream Scope。对于每一个应用来说,顶层是WebScope,而GlobalScope是Root结点,每一个Scope都有一个名称,如下。
?
GlobalScope(default) --> WebScope(oflaDemo) --> Scope(room0) --> BroadcastStream(live0), SharedObject(so1)
??????????????????????????????????????????? --> Scope(room1) --> SharedObject(so0)
???????????????????? --> WebScope(fitcDemo) --> Scope(room1) --> BroadcastStream(live0)

对于客户端来说,不可以连接GlobalScope和BasicScope,其它的Scope是可以连接的。对于WebScope的子Scope是可以自动创建的,比方说 客户端连接oflaDemo/lobby0/room0 ,如果lobby0/room0都没有创建的话,服务端会自动创建起来。

Scope提供了资源解析和注册服务的功能,它也能够管理当前连接到该Scope的连接对象。

Context 被绑定在Scope对象当中,为Scope对象提供额外的服务。IContext.getScope()可以获取Context对象实例。由于Context包装了Spring的 application context,因此通过spring的查找bean能够很快得到预先被加载的服务对象。Scope对象还提供了 "clientRegistry", "serviceInvoker", "persistenceStore", "mappingStrategy" 等等服务。在red5当中主要用到这两种上下文对象Default和Web两种上下文。

The scope handler methods are:
· start – Called only once, when a scope is created for the first time.
· connect – Called right before every connection to a scope.
· join – Called right before the client enters the scope.
· leave – Called right after a client leaves the scope.
· disconnect – Called just after the connection is disconnected from the scope.
· stop – Called right before a scope is destroyed. When this is called at application level, the application will be stopped. If called at room level,
it will simply stop handling on that scope.· addChildScope – Called just before a child scope is added.
· removeChildScope – Called right after a child scope is removed.
· serviceCall – Called when a service method is requested.

The application adapter methods are:
· appStart – Called on the first request for an application or room.
· appConnect – Called when a connection is made to an application.
· appJoin – Called every time a client joins an application.
· appLeave – Called when a client leaves an application.
· appDisconnect – Called when a connection disconnects from an application.
· appStop – Called when an application is destroyed, this occurs when an application is stopped.
· roomStart – Called the only once when a room is started.
· roomConnect – Called on every connection to a room.
· roomJoin – Called every time a client joins a room.
· roomLeave – Called when a client leaves a room.
· roomDisconnect – Called when a connection disconnects from a room.
· roomStop – Called when a room is disposed.

An incoming connection will proceed through the following steps:
1. roomStart is called for the requested scope if the connection is the first connection to the
scope
2. connect is called on the application scope
3. appConnect is called
4. appJoin is called
5. connect is called on the room scope
6. roomConnect is called
7. roomJoin is called

A connection which is disconnecting from our application will go through the following steps:
1. disconnect is called on the room scope
2. roomDisconnect is called
3. leave is called on the room scope
4. roomLeave is called
5. disconnect is called on the application scope
6. appDisconnect is called
7. leave is called on the application scope
8. appLeave is called


假设服务端启动了一个red5serv的应用,客户端连接该应用时rtmp://localhost/red5serv/lobby0/room0 并离开服务器。

服务器启动
start 创建red5serv应用时调用
appStart 启动时调用一次

客户端连接rtmp://localhost/red5serv/lobby0/room0

start lobby0创建时调用
roomStart? lobby0创建完成后调用
start? room0?? 创建时调用
roomStart room0?? 创建时调用

connect???? 连接
appConnect? 连接red5serv应用
join??????? 加入
appJoin???? 加入red5serv应用
connect???? 连接
roomConnect 连接lobby0
join???? 加入
roomJoin??? 加入lobby0
connect???? 连接
roomConnect 连接room0
join??????? 加入
roomJoin??? 加入room0
disconnect? 断开
roomDisconnect 断开room0
leave?????????? 离开
roomLeave???? 离开room0
stop????????? 停止
roomStop????? 停止room0
disconnect???? 断开
roomDisconnect 断开lobby0
leave????????? 离开
roomLeave????? 离开lobby0
stop?????????? 停止
roomStop?????? 销毁lobby0
disconnect???
appDisconnect 断开应用
leave?????? 离开?
appLeave????? 离开应用red5serv

热点排行