Home > > [轉]通過Stratus 伺服器在Flash Player中使用RTMFP 開發 點對點應用(二)

[轉]通過Stratus 伺服器在Flash Player中使用RTMFP 開發 點對點應用(二)

2010年1月9日星期六
 

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 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 ) 通信。

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 提供終端設備之間的安全通信。它的密鑰採用128位AES談判使用Diffie-Hellmann密鑰交換方法。不過,這並不提供強大的終端認證,如SSL或RTMPS 。為了幫助端點認證, 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 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的服務:

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服務中,您被分配一個獨特的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 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,您必須知道發佈者的256位peer 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數組。當一個發部流同一個訂閱流相互競爭時,訂閱NetStream從NetStream.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 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客戶端可以連接的所謂的「聽眾流」 (在這裡我們這樣叫它)。當客戶端(調用者)希望與客戶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.0的API 。在閱讀本文,您應該很好地理解如何使用這一革命性的協議。我希望你能利用端到端的和先進的媒體功能的Flash Player 10和AIR 1.5開發了不起的應用。



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

0 Responses to "[轉]通過Stratus 伺服器在Flash Player中使用RTMFP 開發 點對點應用(二)"