1 Reply Latest reply on Mar 29, 2010 8:51 AM by danraeder

    How to capture the video from the connected peerID? PLZ Help

    satheeshpallath12 Level 1

      Hai,

       

      I'm doing p2p application.I want to get the video of the connected peer.How can we capture the video of connected peerID?when i did  sample application, text chat is working but for camera and microphone not able to get the video of connected peerID.Actually i want to get the video of other person connected to me.now i'm getting my video.

       

      Can anyone help me?

       

      i requires the code for captureing the video and voice of connected peer....

       

       

       

      Ad.Thanx

        • 1. Re: How to capture the video from the connected peerID? PLZ Help
          danraeder

          Here is an example:  http://www.adobe.com/devnet/flashmediaserver/articles/p2p_apps_stratus_lccs.html

           

          Apparently, this only works when the other party knows the peerID.  I've been reading about PHP and mySQL integration for the peerID exchange, but have yet to try this.

           

          Here is the relevant code in flex builder 4:

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"              
              xmlns:s="library://ns.adobe.com/flex/spark"            
              xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024"
              minHeight="768">
              <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
              </fx:Declarations>
             
              <fx:Script>
                  <![CDATA[
                     /**
                     *
                     * P2P
                     *
                     */
                     public const SERVER_ADDRESS:String = "rtmfp://stratus.adobe.com/";           
                     public const DEVELOPER_KEY:String = "YOUR-DEVELOPER-KEY";                      
                     private var conn:NetConnection;           
                     private var streamOut:NetStream;           
                     private var streamIn:NetStream;           
                     
                     [Bindable]
                     
                     private var myPeerID:String;           
                     private var farID:String;                      
                     public function connect():void{               
                         conn = new NetConnection();               
                         conn.addEventListener(NetStatusEvent.NET_STATUS,connStatus);               
                         conn.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErr);               
                         conn.connect(SERVER_ADDRESS+DEVELOPER_KEY);           
                     }
                                
                     private function connStatus(event:NetStatusEvent):void{
                         trace(event.info.code);
                         txtStatusStratus.text = event.info.code;
                         if(event.info.code=="NetConnection.Connect.Success"){
                             myPeerID = conn.nearID; 
                             initOutStream();
                         }
                     }
          
                     private function asyncErr(event:AsyncErrorEvent):void{
                 
                     }
                       
                     private function initOutStream():void{
                         trace("initOutStream");
                         streamOut = new NetStream(conn,NetStream.DIRECT_CONNECTIONS);
                         streamOut.addEventListener(NetStatusEvent.NET_STATUS,streamStatus);
                         streamOut.publish("media");
                         
                         // CAMERA
                         var cam:Camera = Camera.getCamera();
                         camOut.videoObject.attachCamera(cam);
                         streamOut.attachCamera(cam);
                         streamOut.attachAudio(Microphone.getMicrophone());
                        
                         var streamOutClient:Object = new Object(); 
                         streamOutClient.onPeerConnect = function(farStream:NetStream):Boolean{               
                             // initInStream(farStream.farID);             
                             return true;         
                         }       
                     }
                     
                     private function initInStream(farID:String):void{
                         trace("initInStream: ")
                         streamIn = new NetStream(conn,farID);
                         streamIn.addEventListener(NetStatusEvent.NET_STATUS,streamStatus);
                         streamIn.play("media");
                         streamIn.client = this;
                         camIn.videoObject.attachNetStream(streamIn);           
                     }
                     
                     private function streamStatus(event:NetStatusEvent):void{
                         trace("streamStatus: "+event.info.code);
                     }
                     
                     public function receiveMessage(msg:String):void{
                         trace("receiveMessage: "+msg)
                         txtHistory.text = msg+"\n"+txtHistory.text;   
                     }
          
                     public function sendMessage(msg:String):void{
                         streamOut.send("receiveMessage",msg);
                         receiveMessage(msg);
                    }
                     
                     protected function btnSend_clickHandler(event:MouseEvent):void{
                         trace("sendMessage: "+txtMessage.text)
                         sendMessage(txtMessage.text);
                     }
                  ]]>
              </fx:Script>
              <s:TextInput x="10" y="10" width="201" id="txtStatusStratus"/>
              <s:TextInput x="10" y="40" width="201" id="txtStatusStratusStream"/>
              <s:TextInput x="9" y="151" width="157" id="txtFarPeerID"/>
              <s:TextInput x="9" y="124" width="250" id="txtMyPeerID" text="{myPeerID}"/> 
              <s:Button x="10" y="75" label="Connect" click="connect()" id="btnConnectStratus"/>
              <s:Button x="174" y="152" label="initInStream" click="initInStream(txtFarPeerID.text)" id="btnConnectStratus0"/>
              <s:TextArea x="9" y="181" width="285" height="160" id="txtHistory"/>
              <s:Button x="232" y="351" label="Send" id="btnSend" click="btnSend_clickHandler(event)" width="62"/>
              <s:TextInput x="9" y="349" id="txtMessage" width="215" enter="{btnSend_clickHandler(null)}"/>
              <s:VideoElement id="camOut" width="141" height="112" x="221" y="8"/>
              <s:VideoElement id="camIn" width="141" height="112" x="365" y="8"/>
          </s:Application>