CTIVideoCall 1.0.1

CTIVideoCall 1.0.1

Samuel K 维护。



 
依赖关系
OTKAnalytics= 2.1.0
OpenTok= 2.16.3
SVProgressHUD= 2.2.1
 

logo

Build Status Version Status license MIT Platform PRs Welcome

Accelerator Core iOS

"加速器核心" 以简单的方式将音频/视频通信集成到任何 iOS 应用程序中,通过 OpenTok 平台进行。您可以轻松完成以下任务:

  • 一对一音频/视频通话
  • 多方音频/视频通话
  • 一对一屏幕共享
  • 多方屏幕共享
  • 用于处理音频/视频启用/禁用的 UI 组件

配置,构建并运行示例应用

  1. 获取 API 密钥Session IDToken 的值。有关重要信息,请参阅获取 OpenTok 凭据

  2. 按照 CocoaPods 入门指南中的说明安装 CocoaPods。

  3. 在终端中,使用 cd 命令进入您的项目目录,并输入 pod install

  4. 使用新的 *.xcworkspace 文件在 Xcode 中重新打开您的项目。

  5. 将以下空字符串替换为相应的 API 密钥、Session ID 和 Token 值。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        sharedSession = [[OTAcceleratorSession alloc] initWithOpenTokApiKey:@"apikey" sessionId:@"sessionid" token:@"token"];
        return YES;
    }
  6. 使用 Xcode 在 iOS 模拟器或设备上构建和运行应用程序。

  7. 为了测试音频/视频通信,我们包含了一个简单的网页应用程序以简化流程:浏览器演示。只需打开它,并将相应的 API 密钥、Session ID 和 Token 值替换进去。然后保存并加载到浏览器中。对于多方通话,您可以打开多个标签页来实现。

  8. 您可能想要在其他平台上运行

Accelerator Core Javascript
Accelerator Core Android

示例代码

每个通信实例将从 OTOneToOneCommunicatorDataSource 中获取 OpenTok 会话,因此这适用于每个通信实例。

  • 传递会话

    - (OTAcceleratorSession *)sessionOfOTOneToOneCommunicator:(OTOneToOneCommunicator *)oneToOneCommunicator {
        return <#OTAcceleratorSession#>;
    }
  • 一对一

    self.communicator = [[OTOneToOneCommunicator alloc] init];
    self.communicator.dataSource = self;
    [self.communicator connectWithHandler:^(OTCommunicationSignal signal, NSError *error) {
        if (signal == OTPublisherCreated && !error) {
            weakSelf.communicator.publisherView.frame = CGRectMake(0, 0, 100, 100);
            [self.publisherView addSubview:weakSelf.communicator.publisherView];
        }
        else if (signal == OTSubscriberReady && !error) {
            weakSelf.communicator.subscriberView.frame = CGRectMake(0, 0, 100, 100);
            [self.subscriberView addSubview:weakSelf.communicator.subscriberView];
        }
    }];
  • 多方

    self.communicator = [[OTMultiPartyCommunicator alloc] init];
    self.communicator.dataSource = self;
    [self.communicator connectWithHandler:^(OTCommunicationSignal signal, OTMultiPartyRemote *subscriber, NSError *error) {
        if (signal == OTPublisherCreated && !error) {
            weakSelf.communicator.publisherView.frame = CGRectMake(0, 0, 100, 100);
            [self.publisherView addSubview:weakSelf.communicator.publisherView];
        }
        else if (signal == OTSubscriberReady && !error) {
            subscriber.subscriberView.frame = <#your desired frame for this remote subscriberview#>;
            // your logic to handle multiple remote subscriberview(s)
        }
    }];
  • 屏幕共享

    使用如下所示的 - (instancetype)initWithView:- (instancetype)initWithView:name:

    self.screenSharer = [[OTOneToOneCommunicator alloc] initWithView:[UIApplication sharedApplication].keyWindow.rootViewController.view];

    或者

    self.screenSharer = [[OTMultiPartyCommunicator alloc] initWithView:[UIApplication sharedApplication].keyWindow.rootViewController.view];
  • 预定义的 UI

    启用音视频控制

    self.communicator.publisherView.controlView.isVerticalAlignment = YES;
    self.communicator.publisherView.controlView.frame = CGRectMake(10, 10, CGRectGetWidth(self.publisherView.frame) * 0.1, CGRectGetHeight(self.publisherView.frame) * 0.3);

    处理视频的启用/禁用控制

    // default
    // enable handleAudioVideo property, the publisherView will be covered by a silhouette automatically.
    self.communicator.publisherView.handleAudioVideo = YES; 
    
    // disable handleAudioVideo property, the publisherView will do nothing for enabling/disabling publishVideo.
    self.communicator.publisherView.handleAudioVideo = NO; 

已准备好使用的组件

  • 一对一通讯

ready-in-use-2 ready-in-use-3

OTOneToOneCommunicationController *vc = [OTOneToOneCommunicationController oneToOneCommunicationControllerWithSession:<#OTAcceleratorSession#>];
[self.navigationController pushViewController:vc animated:YES];

使用核心的示例应用程序

以下示例应用程序使用 加速器核心

获取 OpenTok 凭证

要使用 OpenTok 的框架,您需要一个 Session ID,Token 和 API Key。您可以在 OpenTok 开发者仪表板 获取这些值。对于生产部署,您必须使用其中一个 OpenTok 服务器 SDK 生成 Session ID 和 Token 值。

加速器核心作为依赖关系

在您使用任何 OpenTok 加速器时,都要求使用加速器核心。加速器核心是一个公共层,其中包括所有 OpenTok 一对一通讯示例应用程序中所包含的音频视频通讯逻辑,并允许所有加速器和示例应用程序共享同一个 OpenTok 会话。加速器包和示例应用程序通过公共加速器会话包层访问 OpenTok 会话,这使它们能够共享单个 OpenTok 会话。

architecture

在 Android 和 iOS 移动平台上,当你尝试设置监听器(Android)或代理(iOS)时,通常无法为同一事件设置多个监听器或代理。例如,在这些移动平台上,你只能设置一个 OpenTok 信号监听器。但是,公共加速器会话包允许你为同一事件设置多个监听器。