iOSWebRTC语音视频通话实现与demo

    xiaoxiao2021-04-13  75

    前言

    最近公司要出一个视频通话的项目。在网上看了好多项目但是感觉要么太复杂要么满足不了我们的需求。个人认为环信的做的应该还是很不错的,但是我们领导要求WebRtc来做,没办法。 首先说一下:WebRtc本身是谷歌搞出来的,所以实在不行可以谷歌一发吧!不过源码还是比较gay的,哈哈哈,看运气不知道你能不能下下来。 官方教程 :https://webrtc.org/native-code/ios/  WebRtc只适合小范围(8人以内)音视频会议,不适合做直播: 让粉丝们来看直播,如果同时粉丝数>10人,那么不关 WebRtc 鸟事,服务器请使用 nginx rtmp-module架设,架设好了用 ffmpeg 命令行来测试播摄像头。主播客户端请使用rtmp进行推流给rtmp-module,粉丝请使用 rtmp / flv + http stream 进行观看,PC-web端的粉丝请使用 Flash NetStream来观看,移动 web端的粉丝请使用 hls / m3u8 来观看。 这是知乎上的,一些这方面的讲解!如果你已经入门了,可以去看看:https://www.zhihu.com/question/25497090/answer/72397450 网上有很多开源的代码,我也建议你可以去看看!有时候看看他的代码看得多了其实就能懂很多了,无非就是调接口这些! 对了,这个最主要的是需要搭建服务器哦!有人纠结究竟自己搭还是去买,我个人感觉搭它的服务器还是很简单的、=-= 恩,可以自己去百度按照教程来,不过需要注意的是从公网到外网这个会有点麻烦!不过我想着不是你的MARK!哈哈哈,交给那些后台吧!

    About

         项目是一个基于本土故事板空间定位器和视频聊天视图控制器,UI这块的话 我觉得你可以自己想得到的!毕竟画几个播放器不算太难吧!

    Features

    完全原生objective - c 64位支持libWebRTC预先编译。。(节省你小时编译) 从v1.0.2我们现在引用pod libjingle_peerconnection由原始的维护。 一个自动libWebRTC io。 构建流程利用可可豆荚依赖关系管理视图控制器很容易落入自己的项目暴露api来轻松地定制,适应你的需要(更多细节见下文)支持最近https://apprtc.appspot.com(2015年10月)也有一个叉的谷歌AppRTC Web服务器维护这个项目完全兼容

    Notes

    以下资源帮助得到这个项目到今天的地方: How to get started with WebRTC and iOS without wasting 10 hours of your lifehiroeorz's AppRTCDemo ProjectPristine.io Automated WebRTC Building

    Running the AppRTC App on your iOS Device

    你的iPhone或者iPad上运行这个应用程序可以存储库和打开AppRTC叉。在Xcode中xcworkspace和编译你的iOS设备上检查出来。默认情况下,服务器地址设置为https://apprtc.appspot.com。

    Using the AppRTC Pod in your App

    如果你想把WebRTC视频聊天到你自己的应用程序中,您可以安装AppRTC舱: pod install AppRTC 从那里你可以看到在这个回购ARTCVideoChatViewController类。以下步骤详细具体更改您将需要在您的应用程序添加视频聊天。

    Initialize SSL Peer Connection

    WebRTC可以通过SSL安全通信。这是必需的,如果你想测试在https://apprtc.appspot.com。您需要修改您的AppDelegate。m类如下: Import the RTCPeerConnectionFactory.h#import "RTCPeerConnectionFactory.h" Add the following to your application:didFinishLaunchingWithOptions: method: [RTCPeerConnectionFactory initializeSSL]; Add the following to your applicationWillTerminate: method: [RTCPeerConnectionFactory deinitializeSSL];

    Add Video Chat

    向应用程序添加视频聊天你需要2视图: 1.本地视频视图——从你的设备摄像头视频呈现 2.远程视频呈现视图——视频远程相机 为此,执行以下: 1.ViewController或使用的任何类,其中包含上面定义的两个视图添加以下标题:进口 #import <libjingle_peerconnection/RTCEAGLVideoView.h> #import <AppRTC/ARDAppClient.h>2.类应该实现ARDAppClientDelegate和RTCEAGLVideoViewDelegate协议: @interface ARTCVideoChatViewController : UIViewController <ARDAppClientDelegate, RTCEAGLVideoViewDelegate>* `ARDAppClientDelegate` - Handles events when remote client connects and disconnect states. Also, handles events when local and remote video feeds are received. * `RTCEAGLVideoViewDelegate` - Handles event for determining the video frame size.3.在您的类定义以下属性: @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;* *ARDAppClient* - Performs the connection to the AppRTC Server and joins the chat room * *remoteView* - Renders the Remote Video in the view * *localView* - Renders the Local Video in the view4.初始化属性变量时一定要设置代表: /* 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.连接到一个视频聊天室 [self.client setServerHostUrl:@"https://apprtc.appspot.com"]; [self.client connectToRoomWithId:@"room123" options:nil];6.处理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 { /* resize self.localView or self.remoteView based on the size returned */ }

    Known Issues

    以下是已知问题正在处理,应该不久公布: None at this time 有需要代码的可以联系加群。群号:622492955 哈哈哈!!!
    转载请注明原文地址: https://ju.6miu.com/read-668671.html

    最新回复(0)