测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | BSD |
发布最后发布 | 2017年6月 |
由 Kelly Chu维护。
依赖 | |
libjingle_peerconnection | >= 0 |
SocketRocket | >= 0 |
此 Xcode 项目是 Google 的 WebRTC 示例的本机封装。它将 WebRTC 组件组织到一个 cocoa pod 中,可以轻松部署到任何 Xcode 项目中。与之前版本的 WebRTC 项目不同,该 pod 随附的预编译 libWebRTC 静态库与 64 位应用程序一起工作。目前,该项目旨在在 iOS 设备上运行(不支持 iOS 模拟器)。
此 Xcode 项目包含一个基于本机 Storyboard 的 Room 定位器和视频聊天视图控制器。
以下资源对帮助本项目达到今天的地位很有帮助:
要在 iPhone 或 iPad 上运行应用程序,您可以分叉此存储库,并在 Xcode 中打开 AppRTC.xcworkspace
,以便将其编译到您的 iOS 设备上以进行检查。默认情况下,服务器地址设置为 https://apprtc.appspot.com。
如果您想在应用程序中集成 WebRTC 视频聊天,您可以安装 AppRTC pod
pod install AppRTC
从这里您可以查看本项目中的ARTCVideoChatViewController
类。以下步骤将详细说明您需要在应用程序中进行的具体更改以添加视频通话。
WebRTC可以通过SSL安全通信。如果您想通过https://apprtc.appspot.com进行测试,则需要这样做。您需要修改AppDelegate.m
类,如下所示
#import "RTCPeerConnectionFactory.h"
application:didFinishLaunchingWithOptions:
方法中 [RTCPeerConnectionFactory initializeSSL];
applicationWillTerminate:
方法中 [RTCPeerConnectionFactory deinitializeSSL];
要将视频通话添加到应用程序中,您需要2个视图
为此,请执行以下操作
#import <libjingle_peerconnection/RTCEAGLVideoView.h>
#import <AppRTC/ARDAppClient.h>
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.
@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 view
/* 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];
[self.client setServerHostUrl:@"https://apprtc.appspot.com"];
[self.client connectToRoomWithId:@"room123" options:nil];
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 */
}
RTCEAGLVideoViewDelegate
的委托回调- (void)videoView:(RTCEAGLVideoView *)videoView didChangeVideoSize:(CGSize)size {
/* resize self.localView or self.remoteView based on the size returned */
}
如果您想做出贡献,请fork仓库并发出pull请求。如果您有特殊请求并希望合作,请直接与我联系。谢谢!
以下是需要解决并在短期内发布的已知问题