HMWebRTC 0.2.0

HMWebRTC 0.2.0

Tran Diep Hue Man 维护。



HMWebRTC 0.2.0

  • TRAN DIEP Hue Man

HMWebRTC

CI Status Version License Platform

示例

要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install

示例应用程序使用当前的 Google AppRTC Web 服务器

安装

HMWebRTC 通过 CocoaPods 提供。要安装它,只需将以下行添加到 Podfile

pod 'HMWebRTC'

依赖项

现在 GoogleWebRPC 已可在 CocoaPods 上使用,但无法直接在客户端应用程序中使用,需要一些必须的步骤/配置,如 iOS SDK 示例 中所示。

为了方便使用,本项目将 iOS 工作示例的必要模块封装起来,以便直接在其他使用 CocoaPod 的项目中重用。

功能

该项目附带预置可用的WebRTC客户端模块。请参考示例应用程序进行手动使用。

另一方面,此 Cocoapod 还包含视频聊天的 UI + 视图控制器,预配置完成,可直接嵌入其他项目中。

在您的应用中使用 HMWebRTC

安装框架后,需要做一些预配置才能使其正常运行。

配置服务器主机参数

默认应用客户端参数使用当前 Google WebRTC 服务器参数

如以下示例所示,使用静态配置类 ARDAppClientConfig 替换默认配置参数以适应您的 WebRTC 后端

#import "HMWebRPC/ARDAppClientConfig.h"

[ARDAppClientConfig setServerHostParams:@"https://..."]
...

WebRTC 客户端的默认参数

static NSString * kARDRoomServerHostUrl = @"https://appr.tc";
static NSString * kARDIceServerRequestUrl = @"https://appr.tc/params";
static NSString * kARDRoomServerJoinFormat = @"https://appr.tc/join/%@";
static NSString * kARDRoomServerJoinFormatLoopback = @"https://appr.tc/join/%@?debug=loopback";
static NSString * kARDRoomServerMessageFormat = @"https://appr.tc/message/%@/%@";
static NSString * kARDRoomServerLeaveFormat = @"https://appr.tc/leave/%@/%@";
static NSString * kTURNRefererURLString = @"https://appr.tc";

初始化/反初始化应用中的SSL连接

例如,在单视频通话应用程序中

# AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // When needed, initialize the peer SSL connection
    NSDictionary *fieldTrials = @{};
    RTCInitFieldTrialDictionary(fieldTrials);
    RTCInitializeSSL();
    RTCSetupInternalTracer();
    
    ...
    return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Before exiting, end the current peer session
    RTCShutdownInternalTracer();
    RTCCleanupSSL();
}

添加视频聊天

此 Pod 包含用于点对点视频聊天的 UI xib 以及其视图控制器。简单地将 xib 视图添加到您的 storyboard 视图控制器的 main 视图。

screenshot01.png

然后,在将调用视频聊天的应用程序视图中(例如 HMRoomViewController),实现视频聊天视图控制器的代理

@interface HMRoomViewController ()<HMVideoCallViewControllerDelegate>
...
@end

接下来,要调用视频聊天视图,只需在您的代码中初始化并显示视图控制器即可

// Init the video view controller & set the room identifier
HMVideoCallViewController *videoCallViewController = [[HMVideoCallViewController alloc] initForRoom:trimmedRoom isLoopback:NO delegate:self];

// Present the view controller as modal
videoCallViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:videoCallViewController animated:YES completion:nil];

此外,在通话结束后实现视频视图控制器的委托

#pragma mark - HMVideoCallViewControllerDelegate

- (void)viewControllerDidFinish:(HMVideoCallViewController *)viewController {
    if (![viewController isBeingDismissed]) {
        NSLog(@"Dismissing VC");
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}

许可证

HMWebRTC 在 MIT 许可下可用。更多信息请参阅 LICENSE 文件。