ios中使用webrtc流程


//创建RTCPeerConnectionFactory

_factory = [[RTCPeerConnectionFactory alloc] init];

 

//创建peerconnection,其中config定义turnserver constraints定义//音视频配置信息

_peerConnection = [[RTCPeerConnection alloc]

                          initWithFactory:_factory

                          configuration:config                                  

                          constraints:constraints

                            delegate:self];

 

//创建本地音视频stream,并加入到peerconnection

//本地视频track创建完成后,预览本地视频

RTCMediaStream *localStream = [self createLocalMediaStream];

[_peerConnection addStream:localStream];

 

//如果为发起方,获取本地offer,并通过命令通道发给对方

[_peerConnection offerForConstraints:[

                      self defaultOfferConstraints]

completionHandler:^(

        RTCSessionDescription    *sdp,

NSError *error) {

//回调函数中将offer发给对方 

 

 

//从命令通道收到对方的answer消息,设置到peerconnection

[_peerConnection setRemoteDescription:sdpPreferringH264

                          completionHandler:^(NSError *error) {

                          //回调函数中判断设置结果,如有错提示用户 

 

//从命令通道收到对方的candidate消息,设置到peerconnection

[_peerConnection addIceCandidate:candidateMessage.candidate];

 

//peerconnection回调函数收到candidate,通过命令通道发送给对方

(void)peerConnection:(RTCPeerConnection *)peerConnection

didGenerateIceCandidate:(RTCIceCandidate *)candidate {

//candidate发送给对方 }

 

//peerconnection回调函数收到对方视频

(void)peerConnection:(RTCPeerConnection *)peerConnection

         didAddStream:(RTCMediaStream *)stream {

        //显示远程视频  



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值