·您当前的位置:首页 > 技术教程 > AS2与AS3技术 >

[FMS]运用as3开发RTMFP协议的P2P程序(基础篇)(4)

时间:2014-01-02 17:05未知
First, create a sending NetStream: 首先创建一个发送NetStream: privatevarsendStream:NetStream; sendStream = new NetStream(netConnection,NetStream.DIRECT_CONNECTIONS); sendStream.addEventListener(NetS

First, create a sending NetStream:

首先创建一个发送NetStream:

  1. private var sendStream:NetStream;  
  2. sendStream = new NetStream(netConnection,NetStream.DIRECT_CONNECTIONS); 
  3. sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler); 
  4. sendStream.publish("media"); 
  5. sendStream.attachAudio(Microphone.getMicrophone()); 
  6. 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:

  1. private var recvStream:NetStream;  
  2. recvStream = new NetStream(netConnection, id_of_publishing_client); 
  3. recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler); 
  4. 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的终端接收媒体:

  1. var o:Object = new Object(); 
  2. o.onPeerConnect = function(subscriberStream:NetStream):Boolean{    
  3. if (accept)    {  
  4.      return true;     
  5. }   else   {  
  6.      return false;    
  7.  }} 
  8. 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客户端发送和接收两个流,建立一个完全连接网格。从互联网下载的能力普遍高于上传的能力,你必须要格外小心,不要超负荷用户终端的上行能力。

 

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.

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器