流的发布和订阅

 // caller publishes media stream
    outgoingStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
    outgoingStream.addEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
    outgoingStream.publish("media-caller");

 

// caller subscribes to callee's media stream
    incomingStream = new NetStream(netConnection, identity);
    incomingStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
    incomingStream.play("media-caller");

 

//音频和视频的启动

private function startAudio():void
   {
    if (sendAudioCheckbox.selected)
    {
     var mic:Microphone = getMicrophone();
     if (mic && outgoingStream)
     {
      outgoingStream.attachAudio(mic);
     }
    }
    else
    {
     if (outgoingStream)
     {
      outgoingStream.attachAudio(null);
     }
    }
   }
   
   private function startVideo():void
   {
    if (sendVideoCheckbox.selected)
    {
     var camera:Camera = Camera.getCamera(cameraIndex.toString());
     if (camera)
     {
      localVideoDisplay.attachCamera(camera);
      if (outgoingStream)
      {
       outgoingStream.attachCamera(camera);
      }
     }
    }
    else
    {
     localVideoDisplay.attachCamera(null);
     if (outgoingStream)
     {
      outgoingStream.attachCamera(null);
     }
    }
   }

 

// user clicked accept button
   private function acceptCall():void
   {
    stopRing();
    
    incomingStream.receiveAudio(true);
    incomingStream.receiveVideo(true);
    
    remoteVideo = new Video();
    remoteVideo.width = 320;
    remoteVideo.height = 240;
    remoteVideo.attachNetStream(incomingStream);
    remoteVideoDisplay.addChild(remoteVideo);
        
    // callee publishes media
    outgoingStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
    outgoingStream.addEventListener(NetStatusEvent.NET_STATUS, outgoingStreamHandler);
    outgoingStream.publish("media-callee");
    
    var o:Object = new Object
    o.onPeerConnect = function(caller:NetStream):Boolean
    {
     status("Caller connecting to media stream: " + caller.farID + "\n");
                      
     return true;
    }
    outgoingStream.client = o;
    
    netConnection.call(Relay, null, remoteId, Accept, userNameInput.text);
    
    startVideo();
    startAudio();
         
    currentState = CallEstablished;
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值