通过Stratus 服务器在Flash Player中使用RTMFP 开发 点对点应用(二)

Stratus service

Stratus 服务器

Flash Player instances must connect to the Adobe
Stratus service
(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实例必须连接到Adobe
Stratus service
(使用rtmfp /
/ stratus.adobe.com
) ,用以彼此的通讯。 Stratus是提供会合服务的主机,帮助Flash Player实例间的互相联系,即使它们位于NATs的后面。虽然连接到Stratus服务非常相似连接到Flash Media ServerStratus没有提供任何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

通信。

Security

安全

RTMFP provides secure communications between endpoints. It uses a 128-bit
AES with the key negotiated using the Diffie-Hellmann
key exchange method. However, it does not provide strong endpoint
authentication such as SSL or RTMPS. To aid endpoint authentication, RTMFP and
ActionScript expose secure nonces 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 提供终端设备之间的安全通信。它的密钥采用128AES谈判使用Diffie-Hellmann密钥交换方法。不过,这并不提供强大的终端认证,如SSLRTMPS 。为了帮助端点认证,
RTMFP
ActionScript揭露给应用开发者secure
nonces
。这些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 上的帮助:

ActionScript 3.0 API supporting
RTMFP

ActionScript 3.0 API 支持 RTMFP

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 10RTMFP 。连接到Stratus错服务和创造端到端媒体流的方法类似于Flash Media Server的工作方法。请注意,您必须使用的ActionScript 3.0或者Flash Professional CS4Flex Builder 3 构建目标于Flash Player 10AIR 1.5

As I mentioned before, first you
must connect to the Adobe Stratus service:

正如我前面提到的,首先你必须连接到Adobe公司Stratus的服务:

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);

The developer key is issued when
you sign up for an Adobe Developer Connection account and is available on the
Adobe
Stratus beta
service site.

开发者钥匙是你通过登陆你的Adobe公司开发者帐户申请得到,这个申请在Adobe
Stratus beta
服务的网站。

Upon successful connection to
Stratus, you get a
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.

在成功连接到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 (
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
Video
Phone sample application
does.

在成功建立连接的Stratus服务中,您被分配一个独特的256peer ID NetConnection.nearID 。其他Flash Player的端点必须知道这个peer ID,以便收到您发表的音频/视频流。Flash PlayerStratus的服务是如何将这些ID在需要通讯的Flash Player客户端内传递,不在文章讨论范围内。对于交换ID ,你可以使用一个XMPP协议的服务或一个简单的网络服务,如视频电话样本应用程序。

Direct communications between Flash
Player instances is conducted using unidirectional
NetStream
channels. That is, if you want two-way voice conversation, each Flash Player
endpoint must create a sending
NetStream and a receiving NetStream.

Flash Player实例直接通讯使用单向网流渠道。也就是说,如果你想双向语音交谈,每个Flash Player的端点必须建立一个发送NetStream和接收NetStream


First, create a sending 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());

This means that 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.

这意味着,媒体作为一个端到端的流发布。由于Stratus不能中继媒体,您只可以发布端到端的流。从您的设置管理器选择本地默认设备发出的流媒体将包括音频和视频。

Note: Audio/video is not sent out until another Flash Player
endpoint subscribes to your
media stream.

注:音频/视频无法发送,直到另一Flash
Player
的客户端订阅您的媒体流。

Now, create the receiving NetStream:

现在,创建接收NetStream

private var recvStream:NetStream;
 
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
recvStream.play("media");

At this point, you hear audio and
you can create a
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,您必须知道发布者的256peer ID(发布客户端的 id_ 。为了接收音频/视频,您必须知道被发布出来的流的名字。

Advanced topics

高级主题

The publisher has fine control over
which endpoint can receive its published stream. When a subscriber attempts to
receive a published stream, the
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:

发布者有良好的控制权而接收端可以接收其发布的流。当一个用户试图获得发布的流时,onPeerConnect ()方法被调用(默认简单执行返回true )对发布的NetStream。发布者可以禁止某些Flash Player的终端接收媒体:

var o:Object = new Object();
o.onPeerConnect = function(subscriberStream:NetStream):Boolean
{
   if (accept) 
   {
      return true; 
   }
   else
   {
      return false; 
   }
}
sendStream.client = o; 

On the publisher side, the 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:

在发布方, NetStream.peerStreams属性中拥有所有订阅发布的实例。例如,使用sendStream.send ()将发送相同的数据到所有用户。您可以使用下面的方法将信息发送到一个特定的用户:

sendStream.peerStreams[i].send()

The 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.maxPeerConnections属性指定被允许连接发布者的peer流的数量。默认值是设定为8但在实践中,这取决于您的应用程序时,必须考虑到大多数互联网服务供应商提供非对称互联网接入服务的许可。图1说明了直接和三个Flash Player的实例通讯 。每个Flash Player客户端发送和接收两个流,建立一个完全连接网格。从互联网下载的能力普遍高于上传的能力,你必须要格外小心,不要超负荷用户终端的上行能力。

End-to-end connections using the Stratus service

Figure 1. End-to-end connections using the Stratus service

1  使用Stratus服务点对点连接

The 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.

NetConnection.unconnectedPeerStreams属性是一个没有相关发布的NetStreams数组。当一个发部流同一个订阅流相互竞争时,订阅NetStreamNetStream.peerStreams的数组中移除。

Exploring the Video Phone sample application

探索视频电话示例应用程序

We have developed a sample
video phone application
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 IDreg.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 10AIR 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客户端可以连接的所谓的听众流(在这里我们这样叫它)。当客户端(调用者)希望与客户B通讯( A呼叫B) ,他或她订阅客户B的听众流。在这一点上,客户端B的通知访问者peer ID 的来电(使用onPeerConnect ()方法) ,并订阅客户A的媒体流。通过这个媒体流,客户端A通知客户B对他或她的好友用户的名称(使用NetStream.send ( )方法) ,用户可以选择接受或拒绝呼叫。如果要求被接受,客户端B发布的媒体流和双向通信将要被成立。

Where to go from here

何去何从

In this article, I presented some of the most exciting features of the new
RTMFP protocol along with an overview of the new ActionScript 3.0 API. After
reading this article, you should have a good understanding of how to use this
revolutionary protocol. I hope you will be developing blockbuster applications
using the end-to-end and advanced media capabilities of Flash Player 10 and AIR
1.5.

在本文中,我介绍了一些最令人激动的特点,新的RTMFP协议连同概述了新的ActionScript 3.0API 。在阅读本文,您应该很好地理解如何使用这一革命性的协议。我希望你能利用端到端的和先进的媒体功能的Flash Player 10AIR 1.5开发了不起的应用。

原文地址:http://www.adobe.com/devnet/flashplayer/articles/rtmfp_stratus_app.html

 

Advertisements

One response to this post.

  1. 真的很不错,谢谢啊

    回复

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: