OTAcceleratorCore 4.0.0

OTAcceleratorCore 4.0.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期上次发布2022年11月

Alberto CintadomarinasJason TietAbdul AjetunmobiDevRel Vonage 维护。



 
依赖关系
OTKAnalytics= 2.1.2
OpenTok= 2.18.1
SVProgressHUD= 2.2.5
 

Accelerator Core iOS

Build Status Version Status license MIT Platform PRs Welcome

Tokbox is now known as Vonage

加速器核心是一个通过 OpenTok 平台将音频/视频通信集成到任何 iOS 应用程序中的解决方案。已弃用的 加速器 TextChat加速器 注释 现在是加速器核心的一部分。

加速器核心可以帮助您

核心

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

文本聊天

  • 一对一文本聊天

注释

  • 带有注释的一对一音频/视频通话

配置、构建和运行示例应用程序

加速器核心工作区包含 3 个示例应用程序,分别用于核心、文本聊天和注释组件。

  1. 获取 API 密钥会话 ID令牌 的值。有关重要信息,请参阅 获取 OpenTok 凭据

  2. CocoaPods 入门 中所述安装 CocoaPods。

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

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

  5. 将以下空字符串替换为相应的 API 密钥、会话 ID 和令牌值

    - (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. 为了测试音视频通信,我们提供了一个简单的Web应用,以使其更易于操作:浏览器演示。只需打开它,并替换相应的API密钥、会话ID和令牌值。然后保存并加载到浏览器中。对于多方通信,可以通过打开多个标签页来实现。

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

加速器核心JavaScript

加速器核心安卓

核心示例代码

每个通信实例将从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];

文本书聊示例代码

  • 传递会话

    - (OTAcceleratorSession *)sessionOfOTOneToOneCommunicator:(OTOneToOneCommunicator *)oneToOneCommunicator {
        return <#OTAcceleratorSession#>;
    }
  • 启动信号文本书聊数据

    // we assume self owns a table tableView
    [self.textChat connectWithHandler:^(OTTextChatConnectionEventSignal signal, OTConnection *connection, NSError *error) {
        if (signal == OTTextChatConnectionEventSignalDidConnect) {
            NSLog(@"Text Chat starts");
        }
        else if (signal == OTTextChatConnectionEventSignalDidDisconnect) {
            NSLog(@"Text Chat stops");
        }
    } messageHandler:^(OTTextChatMessageEventSignal signal, OTTextMessage *message, NSError *error) {
        if (signal == OTTextChatMessageEventSignalDidSendMessage || signal == OTTextChatMessageEventSignalDidReceiveMessage) {
            if (!error) {
                [weakSelf.textMessages addObject:message];
                [weakSelf.tableView reloadData];
            }
        }
    }];
  • 停止信号文本书聊数据

    [self.textchat disconnect];

文本书聊信号JSON要求

当使用OpenTok信号API和OpenTok文本书聊组件时使用的JSON,描述了提交聊天消息时使用的相关信息。这些信息包括日期、聊天消息文本、发送者别名和发送者ID。此JSON格式如图例所示

// var type = "text-chat"
{
    "sentOn" : 1462396461923.305,
    "text" : "Hi",
    "sender" : {
        "alias" : "Tokboxer",
        "id" : "16FEB40D-C09B-4491-A983-44677B7EBB3E"
    }
}

此格式化的JSON被转换为字符串,然后提交给OpenTok信号API。有关更多信息,请参阅

为了测试文本书聊,我们提供了一个简单的Web应用,以使其更易于操作:浏览器演示-文本书聊。只需打开它,并替换相应的API密钥、会话ID和令牌值。然后保存并加载到浏览器中。

注释示例代码

OTAnnotationScrollView类是该示例中注释特性的核心。

self.annotationView = [[OTAnnotationScrollView alloc] init];
self.annotationView.frame = <# desired frame #>;
[self.annotationView initializeToolbarView];
self.annotationView.toolbarView.frame = <# desired frame #>;

类设计

以下类表示OpenTok注释加速器的软件设计。

描述
OTAnnotator 确保跨设备和平台进行远程注释的核心组件。
OTAnnotationScrollView 提供在全屏或指定屏幕区域进行注释的基本组件。
OTAnnotationToolbarView 一个方便的注释工具栏,您根据需要可选择使用。作为替代,您可以使用OTAnnotationScrollView创建自己的工具栏。
OTFullScreenAnnotationViewController 一个方便的视图控制器,使您能够立即注释整个屏幕。

第三方库

使用核心的示例应用

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

加速器和示例应用通过加速器会话包层访问OpenTok会话,这允许它们共享单个OpenTok会话

architecture

在Android和iOS移动平台上,当您尝试设置监听器(Android)或委托(iOS)时,通常无法为同一事件设置多个监听器或委托。例如,在这些移动平台上,您只能设置一个OpenTok信号监听器。然而,通用加速器会话包允许您为同一事件设置多个监听器。

获取 OpenTok 凭据

要使用 OpenTok 框架,您需要一个会议 ID、一个令牌和一个 API 密钥。您可以在 OpenTok 开发者仪表板 获取这些值。对于生产部署,您必须使用 OpenTok 服务器 SDK 之一生成会议 ID 和令牌值。

开发和贡献

有兴趣贡献?我们❤️拉取请求!请参阅 贡献指南

获取帮助

我们很愿意听取您的反馈,所以如果您有任何问题、评论或在项目中发现错误,请告诉我们!您可以

进一步阅读