作者:Jozsef Vass
?? 译者:巴巴鲁
(请转载时注明和改编时出处,谢谢)
这次翻译篇比较长,也比较有用的文章,也很重要的文章,算是元旦给FLASH FUNS的礼物吧!
Adobe Flash Player 10 and Adobe AIR 1.5 introduce a new communications protocol, Real-Time Media Flow Protocol (RTMFP), whose low latency, end-to-end peering capability, security, and scalability make it especially well suited for developing real-time collaboration applications by not only providing superior user experience but also reducing operators' costs.
Adobe Flash Player 10 和 Adobe AIR 1.5 引入了一个新的通讯协议,Real-Time Media Flow Protocol (RTMFP) , 其低延迟,端到端的对等功能,安全性和可扩展性使它特别适合开发实时协作应用,不仅提供{zy1}的用户体验,而且运营商降低成本。
Earlier versions of Flash Player use (RTMP) and require Adobe Flash Media Server (FMS) for interactive collaboration applications (such as Adobe Acrobat Connect Pro) or audio/video streaming. While RTMP is an excellent choice for streaming media, shared objects, or remoting, it has limited ability of meeting real-time requirements of interactive audio and video communications.
早前的Flash Player 版本使用 (RTMP) 需要Adobe Flash Media Server (FMS) 提供合作应用( 例如 Adobe Acrobat Connect Pro) 或者音频视频流。RTMP 是streaming media, shared objects, 和 remoting 连接的{zy1}选择, 它满足实时性要求的交互式音频和视频通信的能力有限。
In order to use RTMFP, Flash Player endpoints must connect to an RTMFP-capable server, such as the service or a future version of FMS. Stratus is a hosted rendezvous service that aids establishing communications between Flash Player endpoints. Unlike FMS, Stratus does not support media relay, shared objects, scripting, etc. So by using Stratus, you can develop applications only where Flash Player endpoints are directly communicating with one another.
为了能够使用RTMFP ,Flash Player 客户端必须连接到一个支持RTMFP 协议的服务器,例如 服务器或者是新版本的FMS 。Stratus 是一台用于Flash Player 客户端间通信的主机。不同于FMS, Stratus 不支持视频转播,shared objects, 脚本,等。 因此,使用 Stratus ,只可以开发 Flash Player 的客户端直接相互交流的应用程序。
Flash Player is already the market leader in online video distribution over the web. With the introduction of RTMFP and advanced media compression technologies, Flash Player 10 is well positioned as the leader in real-time communications as well.
Flash Player 已经在web 视频领域占有重要的市场份额。 由于采用 RTMFP 和先进的媒体压缩技术,将有利于 Flash Player 10 处于实时通信的{lx1}地位。
In this article, I first highlight the benefits of using RTMFP in real-time communications applications. Second, I describe the new ActionScript 3.0 API for managing direct end-to-end RTMFP connections. Finally, I present our VideoPhone sample application.
在这篇文章中,我首先强调在即时通讯领域使用RTMFP 的优势。其次,我将要介绍直接管理点对点RTMFP 管理所对应的新的ActionScript 3.0 API 。{zh1},我介绍我们的VideoPhone 应用实例。
Requirements
要求
In order to make the most of this article, you need the following software and files:
为了使用文中的文件,你需要以下软件和文件:
Flex Builder 3
Note: Please follow the instructions in to install Flex Builder 3.0.2. This also includes Flex SDK 3.2, which is required to build applications targeting Flash Player 10. Although you may also use Adobe Flash Professional CS4 for development, this article instructs how to build a sample application using Flex Builder 3.
注意:请按照 指南中的方法去安装Flex Builder 3.0.2. 这里面包括Flex SDK 3.2, 这是为了建立 Flash Player 10 应用。尽管你也可以使用Adobe Flash Professional CS4 作为开发工具,但这篇文件指导你如果使用Flex Builder 3 建立一个简单的应用.
Flash Player 10
Sample files:
- (ZIP, 13K)
Prerequisite knowledge
预备知识
Familiarity with ActionScript 3.0 and Flex Builder is required.
熟悉ActionScript 3.0 和 Flex Builder 是必要的。
Benefits of RTMFP
RTMFP 的好处
Real-Time Media Flow Protocol (RTMFP) is a new communications protocol
introduced in Flash Player 10 and also available in AIR 1.5. One of its major
differentiators from Real-Time Messaging Protocol (RTMP), which is based on the
Transmission Control Protocol (TCP) and exclusively used in previous versions
of Flash Player, is that RTMFP is built on User Datagram Protocol (UDP).
Real-Time Media Flow Protocol (RTMFP) 是一个引入到Flash Player 10 和 in AIR 1.5 新的通讯协议。同Real-Time Messaging Protocol (RTMP) 的主要不同点之一是,RTMP 基于传输控制协议 (TCP) 和 先前版本的Flash Player ,RTMFP 建立在 User Datagram Protocol (UDP) 协议.
While TCP provides reliable data delivery (well applicable for file transfer, e-mail, etc.), it does not provide any end-to-end delay guarantees. Reliable data transmission in TCP is achieved by re-transmission of lost data, which introduces latency. Because minimizing end-to-end delay is one of the most important goals in real-time communications (a few hundred milliseconds' delay may render a conversation unusable), TCP is not well suited for this purpose. Transmission error resilience and recovery form an integral part of most advanced audio and video compression techniques—such as Speex audio and H.264 video codec, both available in Flash Player 10. Reliable delivery provided by TCP is therefore not needed. As a result, UDP, which provides an efficient and rapid data delivery, is popularly used in real-time collaboration applications where minimizing end-to-end delay is of paramount importance. Another advantage of UDP over TCP that it enables end-to-end peering—that is, direct data transmission between two clients located behind network address translators (NATs).
TCP 提供了可靠的数据传输(也适用于文件传输,电子邮件等) ,它没有提供任何端到端延迟保证。可靠的数据传输的 TCP 实现了重新传输丢失的数据,其中包括了延迟。 由于尽量减少端到端延迟是实时通信 (几百毫秒的延迟可能使一个会话不可用)中最重要的一个目标,TCP 是不适合用于这一目的。传输错误复原和恢复不可分割的组成部分,{zxj}的音频和视频压缩技术,如Speex 音频和H.264 视频编解码器,可同时在Flash Player 10 。 因此,可靠的交付所提供的 TCP 没有必要的。因此, UDP 连接,它提供了一个高效,快速的数据传输,是普遍使用的实时协作应用,尽量减少端到端延迟是至关重要的。 另一个优势在于 UDP 连接,它使端到端的对等,也就是说,数据直接的传输客户之间后面网络地址转换( NAT ) 。
When compared to RTMP, RTMFP provides the following advantages for real-time communications:
当同RTMP 做对比,RTMFP 提供下列高级的即时通讯:
- Low latency: Since RTMFP is built on top of UDP, it provides minimal latency for real-time communications. It is important to note that RTMFP provides both reliable and unreliable service. When sending data between two Flash Player instances (for example, using the NetStream.send() method), reliable data transmission is used. When sending Speex audio between two Flash Player instances, unreliable delivery is used, providing the smallest possible latency.
- 低延迟:一但 RTMFP 建立起了UDP ,它将给即时通讯提供最小的延迟。重要的是要注意RTMFP 提供了可靠和不可靠的服务。当在两个Flash Player 实例之间发送数据的时候(例如,使用NetStream.send() 方法),可靠的数据传输被使用。当在两个Flash Player 实例之间发送Speex 音频的时候,不可靠的交互方式被使用,以提供最小的延迟。
- End-to-end media delivery: Media is sent directly between two Flash Player instances without routing through a central relay server. When compared to RTMP, where all data is sent through Flash Media Server, RTMFP not only further reduces end-to-end delay, but also eliminates costs associated with a central data relay, thus lending itself to extremely scalable deployments.
- 点对点媒体传输: 媒体直接发送给两个 Flash Player 的情况下,不通过路由,而是通过一个中央中继服务器。当同 RTMP 相比发现,在所有通过 Flash Media Server 传送的数据, RTMFP 不仅进一步降低了端到端的延迟,而且也xx了中央数据中继的相关开销,因此,有助于自身的可扩展性部署。
-
Data
prioritization:
Audio is
transmitted with higher priority than video and non-time critical data
(such as instant message, etc.). This can significantly enhance user
experience over a bandwidth constrained communications channel.
- 数据的优先次序:音频传输具有较高优先于视频和非时间关键数据(如即时信息等) 。这可以通过带宽通信通道的限制大大提高在用户体验。
All of these features represent tremendous benefits for real-time communications, providing a significantly greater user experience than is achievable with earlier versions of Flash Player.
所有这些功能代表了应用于实时通信的巨大优势,提供了一个极大的用户体验,其成就比早期版本的Flash 播放器的效应更为巨大。
Firewall traversal
穿越防火墙
RTMFP is built on top of UDP, which enables direct connection between
clients even if they are located behind NATs or firewalls. In order for RTMFP
to work, your firewall must be configured to allow outgoing UDP traffic. While
this is the case with most consumer or small office/home office (
SOHO) firewalls, many corporate firewalls block UDP
traffic altogether.
RTMFP 是建立在UDP 连接的基础上,使客户端直接的通信,即使它们位于NATs( 译者注: 是一个网络协议允许客户端后面的 NAT (网络地址转换) ,以找出其公共地址,类型的 NAT 是延迟和互联网方面的端口相关的网络地址转换,尤其本地端口。此信息是用来建立 UDP 连接(用户数据报协议)之间的沟通 两个主机都是延迟的 NAT 路由器。该议定书是指在 RFC 3489 ) 或防火墙。为了RTMFP 工作,您的防火墙必须配置为允许即将发出的UDP 通信。大多数的消费者或小型办公室/ 家庭办公室( SOHO )的防火墙是这种情况,许多企业防火墙xx阻止UDP 通信。
One solution is to configure Flash Player to use a TURN proxy (Traversal Using Relays around NAT). Flash Player supports IETF Internet Draft draft-ietf-behave-turn-08 without authentication. If the network administrator configures a TURN proxy that allows outgoing UDP, Flash Player can be configured by adding the following line in mms.cfg (for more information on Flash Player configuration and the location of mms.cfg, please read the ):
一种解决办法是配置的 Flash Player 使用转向代理 (遍历周围可用的 NAT ) 。 Flash Player 的支持 IETF 的因特网草案 draft-ietf-behave-turn-08 。如果网络管理员配置转向代理,允许即将发送的 UDP 连接, Flash 播放器可以增加在 mms.cfg 的配置(更多的信息 Flash Player 的配置和位置 mms.cfg ,请阅读 ) :
RTMFPTURNProxy=ip_address_or_hostname_of_TURN_proxy
Direct UDP traffic is always attempted and the TURN proxy is only used as a backup: it is used for UDP traffic that cannot flow between Flash Player and Stratus (in case of UDP blocking firewall) or between Flash Player endpoints.
直接UDP 通信总是被尝试,转向代理只是用来作为备份:它是用于UDP 通信,不能在Flash Player 和Stratus (如UDP 协议封锁防火墙)之间或Flash Player 的端点之间流动。
Even if your firewall enables outgoing UDP traffic, it is possible that end-to-end peering cannot be established due to a combination of firewalls. When one endpoint is located behind a so-called "symmetric firewall," end-to-end communications may not be possible. (For a classification of firewalls, please see the entry on Wikipedia.) In this situation, you may use a TURN proxy to aid firewall traversal.
即使你的防火墙使即将发送的 UDP 通信的用,可能和你对应端的防火墙不能够允许通过。当一个端点设在一个所谓的 “ 对称的防火墙, ” 的后面,端到端的通信可能是不可以实现。 (对于多种防火墙,请进入维基百科参阅 。 )在这种情况下,你可以使用转代理援助你防火墙穿越。
?
?
Flash Player instances must connect to the
(using rtmfp://stratus.adobe.com) in order to communicate
with one another. Stratus is a hosted rendezvous service that helps Flash Player
instances contact one another even if they are located behind NATs. Although
connecting to Stratus service is very similar to connecting to Flash Media
Server, Stratus does not provide any of the typical Flash Media Server features
(media relay, shared objects, remoting, etc.). Flash Player endpoints must stay
connected to Adobe Stratus during the entire time of communication. In order to
access Stratus, you will need a developer key that is generated when you create
your Adobe Developer ID.
Flash Player
实例必须连接到
(使用rtmfp
: /
/ stratus.adobe.com
) ,用以彼此的通讯。 Stratus
是提供会合服务的主机,帮助Flash Player
实例间的互相联系,即使它们位于NATs
的后面。虽然连接到Stratus
服务非常相似连接到Flash Media Server
,Stratus
没有提供任何Flash Media Server
典型的功能(媒体中继,共享对象,远程等)
。 Flash Player
客户端必须保持在整个通讯期间一直与Adobe
Stratus
连接。为了获得Stratus
,您将需要您从Adobe
公司申请来的开发密钥。
RTMFP support is being planned for future version of Flash Media Server
(no release date). With Flash Media Server, it will be possible to enable
communications between Flash Player 9 or earlier clients (using RTMP) and Flash
Player 10 clients (using RTMFP).
RTMFP
支持正在计划添加到未来版本的
Flash Media Server
(无发行日期)
。这样
Flash Media Server
,将有可能同
Flash Player 9
或更早的客户(使用
RTMP
)通信和
Flash Player 10
个客户端(使用
RTMFP
)
通信。
安全
RTMFP provides secure communications between endpoints. It uses a 128-bit
AES with the key negotiated using the
key exchange method. However, it does not provide strong endpoint
authentication such as SSL or RTMPS. To aid endpoint authentication, RTMFP and
ActionScript expose
to application developers. These nonces are
available at both communicating Flash Player endpoints and are guaranteed to
match. By verifying these nonces, end users can ensure that there is no
man-in-the-middle attack. These nonces can also be used to develop key
continuity mechanism.
RTMFP
提供终端设备之间的安全通信。它的密钥采用128
位AES
谈判使用
密钥交换方法。不过,这并不提供强大的终端认证,如SSL
或RTMPS
。为了帮助端点认证,
RTMFP
和ActionScript
揭露给应用开发者
。这些nonces
可在双方沟通的Flash
Player
的终点,并保证比赛。通过核实这些nonces
,最终用户可以确保没有人在中间攻击。这些nonces
还可以用来开发关键的连续性机制。
It is important to note that Flash Player only enables sending media from
your microphone and webcam devices to other Flash Player endpoints that
subscribe to your media streams. Flash Player does not relay data on behalf of
any other Flash Player endpoints (such as in a multicast scenario).
重要的是要注意到, Flash
播放器不仅从您的麦克风和摄像头设备发送媒体,其他的Flash Player
端点订阅您的媒体流。代表Flash
播放器并不中继任何其他Flash Player
的端点数据(如在一个多播的情况) 。
For more information on RTMFP, please read the FAQ on Adobe Labs:
对于更多关于RTMFP
的信息,请阅读Adobe Labs
上的帮助:
There is a new ActionScript 3.0 API
in Flash Player 10 to support RTMFP. Connecting to the Stratus service and
creating end-to-end media streams are analogous to working with Flash Media
Server. Please note that you must use ActionScript 3.0 with either Flash
Professional CS4 or Flex Builder 3 targeting Flash Player 10 or AIR 1.5.
有一个新版本的ActionScript 3.0API
支持Flash Player 10
的RTMFP
。连接到Stratus
错服务和创造端到端媒体流的方法类似于Flash Media Server
的工作方法。请注意,您必须使用的ActionScript 3.0
或者Flash Professional CS4
或Flex Builder 3
构建目标于Flash Player 10
或AIR 1.5
。
As I mentioned before, first you
must connect to the Adobe Stratus service:
正如我前面提到的,首先你必须连接到Adobe
公司Stratus
的服务:
The developer key is issued when
you sign up for an Adobe Developer Connection account and is available on the
service site.
开发者钥匙是你通过登陆你的Adobe
公司开发者帐户申请得到,这个申请在
服务的网站。
Upon successful connection to
Stratus, you get a
在成功连接到
Stratus
,你得到
NetConnection.Connect.Success
事件。失败可能有几个方面的原因。如果您提供了一个无效的开发者或不正确的钥匙指定地址,您将收到
NetConnection.Connect.Failed
。如果你的防火墙阻挡即将发送的
UDP
通信,您会收到的
NetConnection.Connect.Failed
事件后,
90
秒超时。
After successfully establishing a
connection to the Stratus service, you are assigned a unique 256-bit peer ID (
在成功建立连接的
Stratus
服务中,您被分配一个独特的
256
位
peer ID
(
NetConnection.nearID
)
。其他
Flash Player
的端点必须知道这个
peer ID
,以便收到您发表的音频
/
视频流。
Flash Player
或
Stratus
的服务是如何将这些
ID
在需要通讯的
Flash Player
客户端内传递,不在文章讨论范围内。对于交换
ID
,你可以使用一个
XMPP
协议的服务或一个简单的网络服务,如视频电话样本应用程序。
Direct communications between Flash
Player instances is conducted using unidirectional
Flash Player
实例直接通讯使用单向网流渠道。也就是说,如果你想双向语音交谈,每个
Flash Player
的端点必须建立一个发送
First, create a sending
首先创建一个发送 This means that
这意味着,媒体作为一个端到端的流发布。由于Stratus
不能中继媒体,您只可以发布端到端的流。从您的设置管理器选择本地默认设备发出的流媒体将包括音频和视频。
Note:
Audio/video is not sent out until another Flash Player
endpoint subscribes to your
注:音频
/
视频无法发送,直到另一
Flash
Player
的客户端订阅您的媒体流。
Now, create the receiving
现在,创建接收 At this point, you hear audio and
you can create a
在这一点上,你听到声音,你可以创建一个视频对象显示视频。为了创造接收
高级主题
The publisher has fine control over
which endpoint can receive its published stream. When a subscriber attempts to
receive a published stream, the
发布者有良好的控制权而接收端可以接收其发布的流。当一个用户试图获得发布的流时,onPeerConnect
()方法被调用(默认简单执行返回true
)对发布的 On the publisher side, the 在发布方,
NetStream.peerStreams
属性中拥有所有订阅发布的实例。例如,使用
sendStream.send
()将发送相同的数据到所有用户。您可以使用下面的方法将信息发送到一个特定的用户:
The
NetConnection.maxPeerConnections
属性指定被允许连接发布者的peer
流的数量。默认值是设定为8
但在实践中,这取决于您的应用程序时,必须考虑到大多数互联网服务供应商提供非对称互联网接入服务的许可。图1
说明了直接和三个Flash Player
的实例通讯 。每个Flash Player
客户端发送和接收两个流,建立一个xx连接网格。从互联网下载的能力普遍高于上传的能力,你必须要格外小心,不要超负荷用户终端的上行能力。
Figure 1.
End-to-end connections using the Stratus service
图1?
使用Stratus
服务点对点连接
The
NetConnection.unconnectedPeerStreams
属性是一个没有相关发布的
NetStreams
数组。当一个发部流同一个订阅流相互竞争时,订阅
Exploring the Video Phone sample application
探索视频电话示例应用程序
We have developed a
for illustrating how to use end-to-end capabilities
of Flash Player 10. It is also available as part of this article.
我们已经开发了一个
,说明如何使用Flash Player 10
的端到端能力 。它也可作为部分文章。
The Video Phone sample application relies on a simple HTTP service to
exchange the Flash Player peer ID. The script is provided as part of the
package (reg.cgi). This web service does not provide any user authentication.
After Flash Player successfully connects to Stratus, it registers its peer ID
with the web service. When making a call, the Video Phone caller uses this web
service to look up recipient's peer ID.
该视频电话示例应用程序依赖于一个用于交流Flash Player peer ID
简单的HTTP
服务。提供的一部分该脚本,封装在( reg.cgi
) 。这种网络服务不提供任何用户认证。在Flash
播放器成功地连接到Stratus
,但其peer ID
的网络服务。当创建一个呼叫电话时,视频电话呼叫使用此网络服务来查找收件人的peer
ID
。
Adobe runs this web service exclusively for the hosted Video Phone sample.
When you build your own Video Phone sample, you must run your own web service
and specify WebServiceUrl in VideoPhoneLabs.mxml. You should override the
AbstractIdManager class to implement your own peer ID exchange mechanism—using,
for example, XMPP, Google Apps, or the Facebook framework.
Adobe
公司运行这一网络服务专门提供视频电话样本。当您建立自己的视频电话样本,则必须运行您自己的网络服务,并在 VideoPhoneLabs.mxml
指定WebServiceUrl
。您应该使用自己重写的AbstractIdManager
类来执行自己的peer ID
身份证交流机制,例如, XMPP
协议,谷歌应用服务,或Facebook
的框架。
The following steps are necessary to build a Video Phone sample
application (for more details, please see ReadMe.txt included in the package):
下列是建立一个视频电话示例应用程序的必要步骤(更多详情,请参阅ReadMe.txt
包中包含) :
1.?????
Host a web service
for the peer ID exchange using the provided reg.cgi Python script.
1.
使用主机网络服务提供的
peer ID
的
reg.cgi
Python
脚本。 2.?????
Update to Flex
Builder 3.0.2 to target Flash Player 10 or AIR 1.5.
2.
更新的Flex Builder 3.0.2
配置,
并对应开发于Flash Player 10
或AIR 1.5
环境下。
3.?????
Create a new Flex
project.
3.
创建一个新的 Flex
项目。
4.?????
Add the source
files from the package (VideoPhoneLabs.mxml, AbstractIdManager.as,
HttpIdManager.as, IdManagerError.as, and IdManagerEvent.as) to the project src
folder.
4.
添加源文件的包(
VideoPhoneLabs.mxml
,
AbstractIdManager.as
,
HttpIdManager.as
,
IdManagerError.as
,并
IdManagerEvent.as
)的项目源文件夹中。
? 5.?????
Configure your
project with Flex SDK 3.2 and target Flash Player 10 or AIR 1.5.
5.
调试你的项目配制为Flex
SDK 3.2
同时发布对象为Flash Player 10
或 AIR 1.5.
6.?????
Specify your
Stratus developer key in DeveloperKey in.
6.?
在VideoPhoneLabs.mxml
文件中替换DeveloperKey
为您的Stratus
开发密钥。
7.?????
Specify the URL
for the web service in WebServiceUrl in.
7.?
在VideoPhoneLabs.mxml
文件中替换WebServiceUrl
为指定的web service
。
The Video Phone sample application uses the phone model. The call
establishment procedure is implemented using end-to-end NetStream.send()
messages. Since you can use the NetStream.send() method only on an established
NetStream, Video Phone publishes a so-called "listener stream" (with
a fixed name) to which other Flash Player endpoints can connect. When client A
(the caller) wishes to communicate with client B (A calls B), he or she
subscribes to client B's listener stream. At this point, client B is notified
of the peer ID of the caller (using the onPeerConnect() method) and subscribes
to client A's media stream. Through this media stream, client A notifies client
B about his or her user-friendly name (using the NetStream.send() method),
which is presented to the user to either accept or reject the call. If the call
is accepted, client B publishes the media stream and two-way communications is
established.
该视频电话示例应用程序使用的手机模型。呼叫建立程序执行是使用端到端 NetStream.send
()的信息。既然你可以使用NetStream.send
( )方法只对指定的NetStream
,视频电话发表其他Flash Player
客户端可以连接的所谓的
Security
ActionScript 3.0 API supporting
RTMFP
ActionScript 3.0 API
支持 RTMFP
private const StratusAddress:String = "rtmfp://stratus.adobe.com";
private const DeveloperKey:String = "your-developer-key";
private var netConnection:NetConnection;
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS,
netConnectionHandler);
netConnection.connect(StratusAddress + "/" + DeveloperKey);
NetConnection.Connect.Success
event. There could be
several reason for connection failure. If you provide an invalid developer key
or incorrectly specify Stratus address, you'll receive
NetConnection.Connect.Failed
.
If your firewall blocks outgoing UDP traffic, you'll receive the
NetConnection.Connect.Failed
event after a 90-second timeout.
NetConnection.nearID
).
Other Flash Player endpoints must know this peer ID in order to receive your
published audio/video streams. It is out of the scope of Flash Player or the
Stratus service how these peer IDs are exchanged among Flash Player endpoints.
For exchanging peer IDs, you may use an XMPP service or a simple web service,
as the
does.
NetStream
channels. That is, if you want two-way voice conversation, each Flash Player
endpoint must create a sending
NetStream
and a receiving
NetStream
.
NetStream
和接收
NetStream
。
NetStream
:
NetStream
:
private var sendStream:NetStream;
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);
sendStream.publish("media");
sendStream.attachAudio(Microphone.getMicrophone());
sendStream.attachCamera(Camera.getCamera());
media
is published as an end-to-end stream. Since Stratus cannot relay media, you can
publish only end-to-end streams. This stream will include both audio and video
from your local default devices chosen by the Settings Manager.
media
stream.
NetStream
:
NetStream
:
private var recvStream:NetStream;
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
recvStream.play("media");
Video
object to display video. In order to create the
receiving
NetStream
,
you must know the 256-bit peer ID of the publisher (
id_of_publishing_client
).
In order to receive audio/video, you must know the name of the stream being
published.
NetStream
,您必须知道发布者的
256
位
peer ID
(发布客户端的
id_
)
。为了接收音频
/
视频,您必须知道被发布出来的流的名字。
Advanced topics
onPeerConnect()
method is invoked
(default implementation simply returns
true
) on the published
NetStream
.
The publisher could disallow certain Flash Player endpoints to receive its
media:
NetStream
。发布者可以禁止某些Flash Player
的终端接收媒体:
var o:Object = new Object();
o.onPeerConnect = function(subscriberStream:NetStream):Boolean
{
??
if (accept)
???
{
?????
return true;
???
}
??
else
??
{
?????
return false;
???
}
}
sendStream.client = o;
NetStream.peerStreams
property holds all the subscribing instances of the publishing NetStream
.
For example, using sendStream.send()
will send the same data to all
subscribers. You can use the following to send information to a specific
subscriber:
sendStream.peerStreams[i].send()
NetConnection.maxPeerConnections
property specifies the number of peer streams that are allowed to connect to
the publisher. The default value is set to 8 but, in practice, depending on
your application, you must consider that most ISPs provide asymmetric Internet
access. Figure 1 illustrates the direct communication among three instances of
Flash Player. Each Flash Player endpoint sends and receives two streams,
creating a fully connected mesh. Since Internet download capacity is generally
much higher than upload capacity, you must be extra careful not to overload the
end-user's uplink.
NetConnection.unconnectedPeerStreams
property is an array of
NetStreams
that are not associated with a publishing
NetStream
yet. When a publishing stream matches a subscribing stream name, the
subscribing
NetStream
is moved from this array to the publishing
NetStream.peerStreams
array.
NetStream
从
NetStream.peerStreams
的数组中移除。