isbx_apprtc_在ios的使用

ISBX apprtc 在iOS的使用

1. 把WebRTC视频聊天集成到你的app中

项目目录 - 终端中输入 pod install AppRTC

2. 从这里你可以找到ARTCVideoChatViewController类 ,接下来集成的详细步骤:

1. 初始化SSL peer 连接

WebRTC可以通过SSL安全通信. 如果你要测试https,这是必须的. 你要修改你的appDelegate.m如下:

  1. #import "RTCPeerConnectionFactory.h"
  2. 在 didFinishLaunchingWithOption:方法中加入 : [RTCPeerConnectionFactory initializeSSL];
  3. 在applicationWillTerminate: 方法中: [RTCPeerConnectionFactory deinitializeSSL];
2. 添加视频聊天

需要两个控件:

  • Local Video View : 显示设备相机
  • Remote Video View : 显示远程相机.

步骤:

  • 1.在你的ViewController或无论什么要放这两个视图的类中 ,引入:
#import <libjingle_peerconnection/RTCEAGLVideoView.h>
#import <AppRTC/ARDAppClient.h>
  • 2.这个类要实现ARDAppClientDelegate 和 RTCEAGLVideoViewDelegate 协议.
@interface ARTCVideoChatViewController : UIViewController <ARDAppClientDelegate, RTCEAGLVideoViewDelegate>

//ARDAppClientDelegate: 管理当远程客户端连接和断开实践. 同时处理收到本地和远程视频提要.
//RTCEAGLVideoViewDelegate : 负责确定视频帧大小.
  • 3.定义这些属性:
//执行AppRTC服务器连接并加入聊天室
@property (strong, nonatomic) ARDAppClient *client;
//视图中显示的远程视频
@property (strong, nonatomic) IBOutlet RTCEAGLVideoView *remoteView;
//显示的本地视频
@property (strong, nonatomic) IBOutlet RTCEAGLVideoView *localView;
@property (strong, nonatomic) RTCVideoTrack *localVideoTrack;
@property (strong, nonatomic) RTCVideoTrack *remoteVideoTrack;
  • 4.初始化这些属性,并设置代理
/* Initializes the ARDAppClient with the delegate assignment */
  self.client = [[ARDAppClient alloc] initWithDelegate:self];

  /* RTCEAGLVideoViewDelegate provides notifications on video frame dimensions */
  [self.remoteView setDelegate:self];
  [self.localView setDelegate:self];
  • 5.接入一个视频聊天室
// 设置Url
[self.client setServerHostUrl:@"https://apprtc.appspot.com"];
[self.client connectToRoomWithId:@"room123" options:nil];

主要内容在connectRoomWithId: option:里面:

  1. 首先把state 更改为kARDAppClientStateConnecting.
  2. 发送TURN Request.
  3. 注册room服务器

      1. 处理ARDAPPClientDelegate方法事件
//连接状态.
- (void)appClient:(ARDAppClient *)client didChangeState:(ARDAppClientState)state {
switch (state) {
    case kARDAppClientStateConnected:
        NSLog(@"Client connected.");
        break;
    case kARDAppClientStateConnecting:
        NSLog(@"Client connecting.");
        break;
    case kARDAppClientStateDisconnected:
        NSLog(@"Client disconnected.");
        [self remoteDisconnected];
        break;
}
}
//接收本地视频轨迹
- (void)appClient:(ARDAppClient *)client didReceiveLocalVideoTrack:(RTCVideoTrack *)localVideoTrack {
self.localVideoTrack = localVideoTrack;
[self.localVideoTrack addRenderer:self.localView];
}
//接收远程视频轨迹
- (void)appClient:(ARDAppClient *)client didReceiveRemoteVideoTrack:(RTCVideoTrack *)remoteVideoTrack {
self.remoteVideoTrack = remoteVideoTrack;
[self.remoteVideoTrack addRenderer:self.remoteView];
}

- (void)appClient:(ARDAppClient *)client didError:(NSError *)error {
/* Handle the error */
}
  • 7.处理RTCEAGLVideoViewDelegate回调
- (void)videoView:(RTCEAGLVideoView *)videoView didChangeVideoSize:(CGSize)size {
//根据返回的大小调整localView或remoteView
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值