草庐IT

ios - Capturer(iPhone 摄像头)未提供给 TVIVideoCapturer for TwilioVideo iOS SDK

coder 2024-01-29 原文

我收到一个错误,我的 TwilioVideo 模块需要一个捕获器(相机或麦克风),但没有接收到该输入。在我们切换到 Cocoapods 安装 SDK 和 PureLayout UI 库后,这个错误开始发生。之前我们手动将所有这些依赖项安装到 XCode 中。

我正在开发 React Native iOS 0.40.0 版本,react-native-cli 版本为 1.0.0。我正在使用 XCode 版本 8.2.1 (8C1002),iPhone 6 模拟器在 iOS 10.2 上运行。我正在使用 Cocoapods 1.2.0 版。我使用的是 TwilioVideo SDK 版本 1.0.0-beta5。还有一个 1.0.0-beta6 版本,我也试过了(结果相同)。恢复到版本 1.0.0-beta4 确实消除了错误,这对我来说表明我实现注册音频和视频轨道的方式存在问题。

这是我的 Pod 文件:

source 'https://github.com/CocoaPods/Specs'
source 'https://github.com/twilio/cocoapod-specs'

target 'MyApp' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for MyApp
    pod 'TwilioVideo', '1.0.0-beta5'
    pod 'PureLayout', '~> 3.0'
  target 'MapleNativeProviderTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

我已经基于这个存储库在 XCode 中实现了一个 TwilioVideo 模块:react-native-twilio-video-webrtc .他最近更新了存储库以适用于 React Native 0.40.0,它更改了 XCode 的导入语法。我已经尝试使用旧的导入语法和新的导入语法,但当我尝试装载我的视频组件时,我继续收到以下错误:

这是 TwilioVideo SDK 的文档.这是 TVIVideoCapturer .

我对 react-native-twilio-video-webrtc 进行了修改,它本质上只是 TwilioVideo SDK 的一个薄包装器,使用 RCT_EXPORT_METHOD 来公开关键的 API 方法。该库在 init 方法中初始化音频和视频轨道,这会导致一些令人讨厌的行为,这些行为与应用程序启动时事件监听器不接收回调有关。因此,我将这些轨道移至名为 initialize 的自定义、公开的 RCT_EXPORT_METHOD。这是我从应用程序中的特定 View 调用的,它安装视频并初始化相机/麦克风输入。

我对 TWVideoModule.m 的实现是:

#import "TWVideoModule.h"

static NSString* roomDidConnect               = @"roomDidConnect";
static NSString* roomDidDisconnect            = @"roomDidDisconnect";
static NSString* roomDidFailToConnect         = @"roomDidFailToConnect";
static NSString* roomParticipantDidConnect    = @"roomParticipantDidConnect";
static NSString* roomParticipantDidDisconnect = @"roomParticipantDidDisconnect";

static NSString* participantAddedVideoTrack   = @"participantAddedVideoTrack";
static NSString* participantRemovedVideoTrack = @"participantRemovedVideoTrack";
static NSString* participantAddedAudioTrack   = @"participantAddedAudioTrack";
static NSString* participantRemovedAudioTrack = @"participantRemovedAudioTrack";
static NSString* participantEnabledTrack      = @"participantEnabledTrack";
static NSString* participantDisabledTrack     = @"participantDisabledTrack";

static NSString* cameraDidStart               = @"cameraDidStart";
static NSString* cameraWasInterrupted         = @"cameraWasInterrupted";
static NSString* cameraDidStopRunning         = @"cameraDidStopRunning";

@interface TWVideoModule () <TVIParticipantDelegate, TVIRoomDelegate, TVIVideoTrackDelegate, TVICameraCapturerDelegate>

@end

@implementation TWVideoModule

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue
{
  return dispatch_get_main_queue();
}

- (NSArray<NSString *> *)supportedEvents
{
  return @[roomDidConnect,
           roomDidDisconnect,
           roomDidFailToConnect,
           roomParticipantDidConnect,
           roomParticipantDidDisconnect,
           participantAddedVideoTrack,
           participantRemovedVideoTrack,
           participantAddedAudioTrack,
           participantRemovedAudioTrack,
           participantEnabledTrack,
           participantDisabledTrack,
           cameraDidStopRunning,
           cameraDidStart,
           cameraWasInterrupted];
}


- (instancetype)init
{
  self = [super init];
  if (self) {

    UIView* remoteMediaView = [[UIView alloc] init];
    //remoteMediaView.backgroundColor = [UIColor blueColor];

    //remoteMediaView.translatesAutoresizingMaskIntoConstraints = NO;
    self.remoteMediaView = remoteMediaView;


    UIView* previewView = [[UIView alloc] init];
    //previewView.backgroundColor = [UIColor yellowColor];

    //previewView.translatesAutoresizingMaskIntoConstraints = NO;
    self.previewView = previewView;

  }
  return self;
}

- (void)dealloc
{
  [self.remoteMediaView removeFromSuperview];
  self.remoteMediaView = nil;

  [self.previewView removeFromSuperview];
  self.previewView = nil;

  self.participant = nil;
  self.localMedia = nil;
  self.camera = nil;
  self.localVideoTrack = nil;
  self.videoClient = nil;
  self.room = nil;
}

RCT_EXPORT_METHOD(initialize) {
  self.localMedia = [[TVILocalMedia alloc] init];
  self.camera = [[TVICameraCapturer alloc] init];

  NSLog(@"Camera %@", self.camera);

  self.camera.delegate = self;

  self.localVideoTrack = [self.localMedia addVideoTrack:YES
                                               capturer:self.camera
                                            constraints:[self videoConstraints]
                                                  error:nil];

  self.localAudioTrack = [self.localMedia addAudioTrack:YES];

  if (!self.localVideoTrack) {
    NSLog(@"Failed to add video track");
  } else {
    // Attach view to video track for local preview
    [self.localVideoTrack attach:self.previewView];
  }

}

此文件的其余部分与添加和删除轨道以及加入/断开 Twilio channel 有关,因此我没有包含它。我还有 TWVideoPreviewManagerTWRemotePreviewManager,它们只是为本地和远程视频流的媒体对象提供 UIView。

我的 TwilioVideoComponent.js 组件是:

import React, { Component, PropTypes } from 'react'
import {
    NativeModules,
    NativeEventEmitter
} from 'react-native';

import {
    View,
} from 'native-base';

const {TWVideoModule} = NativeModules;

class TwilioVideoComponent extends Component {

    state = {};

    static propTypes = {
        onRoomDidConnect: PropTypes.func,
        onRoomDidDisconnect: PropTypes.func,
        onRoomDidFailToConnect: PropTypes.func,
        onRoomParticipantDidConnect: PropTypes.func,
        onRoomParticipantDidDisconnect: PropTypes.func,
        onParticipantAddedVideoTrack: PropTypes.func,
        onParticipantRemovedVideoTrack: PropTypes.func,
        onParticipantAddedAudioTrack: PropTypes.func,
        onParticipantRemovedAudioTrack: PropTypes.func,
        onParticipantEnabledTrack: PropTypes.func,
        onParticipantDisabledTrack: PropTypes.func,
        onCameraDidStart: PropTypes.func,
        onCameraWasInterrupted: PropTypes.func,
        onCameraDidStopRunning: PropTypes.func,
        ...View.propTypes,
    };

    _subscriptions = [];

    constructor(props) {
        super(props);

        this.flipCamera = this.flipCamera.bind(this);
        this.startCall = this.startCall.bind(this);
        this.endCall = this.endCall.bind(this);

        this._eventEmitter = new NativeEventEmitter(TWVideoModule)
    }

    //
    // Methods

    /**
     * Initializes camera and microphone tracks
     */
    initializeVideo() {
        TWVideoModule.initialize();
    }

    flipCamera() {
        TWVideoModule.flipCamera();
    }

    startCall({roomName, accessToken}) {
        TWVideoModule.startCallWithAccessToken(accessToken, roomName);
    }

    endCall() {
        TWVideoModule.disconnect();
    }

    toggleVideo() {
        TWVideoModule.toggleVideo();
    }

    toggleAudio() {
        TWVideoModule.toggleAudio();
    }

    _unregisterEvents() {
        this._subscriptions.forEach(e => e.remove());
        this._subscriptions = []
    }

    _registerEvents() {

        this._subscriptions = [

            this._eventEmitter.addListener('roomDidConnect', (data) => {
                if (this.props.onRoomDidConnect) {
                    this.props.onRoomDidConnect(data)
                }
            }),

            this._eventEmitter.addListener('roomDidDisconnect', (data) => {
                if (this.props.onRoomDidDisconnect) {
                    this.props.onRoomDidDisconnect(data)
                }
            }),

            this._eventEmitter.addListener('roomDidFailToConnect', (data) => {
                if (this.props.onRoomDidFailToConnect) {
                    this.props.onRoomDidFailToConnect(data)
                }
            }),

            this._eventEmitter.addListener('roomParticipantDidConnect', (data) => {
                if (this.props.onRoomParticipantDidConnect) {
                    this.props.onRoomParticipantDidConnect(data)
                }
            }),

            this._eventEmitter.addListener('roomParticipantDidDisconnect', (data) => {
                if (this.props.onRoomParticipantDidDisconnect) {
                    this.props.onRoomParticipantDidDisconnect(data)
                }
            }),

            this._eventEmitter.addListener('participantAddedVideoTrack', (data) => {
                if (this.props.onParticipantAddedVideoTrack) {
                    this.props.onParticipantAddedVideoTrack(data)
                }
            }),

            this._eventEmitter.addListener('participantRemovedVideoTrack', (data) => {
                if (this.props.onParticipantRemovedVideoTrack) {
                    this.props.onParticipantRemovedVideoTrack(data)
                }
            }),

            this._eventEmitter.addListener('participantAddedAudioTrack', (data) => {
                if (this.props.onParticipantAddedAudioTrack) {
                    this.props.onParticipantAddedAudioTrack(data)
                }
            }),

            this._eventEmitter.addListener('participantRemovedAudioTrack', (data) => {
                if (this.props.onParticipantRemovedAudioTrack) {
                    this.props.onParticipantRemovedAudioTrack(data)
                }
            }),

            this._eventEmitter.addListener('participantEnabledTrack', (data) => {
                if (this.props.onParticipantEnabledTrack) {
                    this.props.onParticipantEnabledTrack(data)
                }
            }),

            this._eventEmitter.addListener('participantDisabledTrack', (data) => {
                if (this.props.onParticipantDisabledTrack) {
                    this.props.onParticipantDisabledTrack(data)
                }
            }),

            this._eventEmitter.addListener('cameraDidStart', (data) => {
                if (this.props.onCameraDidStart) {
                    this.props.onCameraDidStart(data)
                }
            }),

            this._eventEmitter.addListener('cameraWasInterrupted', (data) => {
                if (this.props.onCameraWasInterrupted) {
                    this.props.onCameraWasInterrupted(data)
                }
            }),

            this._eventEmitter.addListener('cameraDidStopRunning', (data) => {
                if (this.props.onCameraDidStopRunning) {
                    this.props.onCameraDidStopRunning(data)
                }
            })

        ]

    }

    componentWillMount() {
        this._eventEmitter.addListener('cameraDidStart', (data) => {
            if (this.props.onCameraDidStart) {
                this.props.onCameraDidStart(data)
            }
        });
        this._registerEvents()
    }

    componentWillUnmount() {
        this._unregisterEvents()
    }

    render() {
        return this.props.children || null
    }
}

export default TwilioVideoComponent;

我不确定如何修改 XCode 以兼容 TwilioVideo beta5 API。任何帮助将不胜感激。

最佳答案

在您的 podfile 中,查找 # use_frameworks! 并删除 #。

关于ios - Capturer(iPhone 摄像头)未提供给 TVIVideoCapturer for TwilioVideo iOS SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42075289/

有关ios - Capturer(iPhone 摄像头)未提供给 TVIVideoCapturer for TwilioVideo iOS SDK的更多相关文章

  1. ruby - 我可以使用 aws-sdk-ruby 在 AWS S3 上使用事务性文件删除/上传吗? - 2

    我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的

  2. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  3. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  4. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  5. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  6. 三分钟集成 TapTap 防沉迷 SDK(Unity 版) - 2

    三分钟集成Tap防沉迷SDK(Unity版)一、SDK介绍基于国家对上线所有游戏必须增加防沉迷功能的政策下,TapTap推出防沉迷SDK,供游戏开发者进行接入;允许未成年用户在周五、六、日以及法定节假日晚上8:00-9:00进行游戏,防沉谜时间段进入游戏会弹窗进行提示!开发环境要求:Unity2019.4或更高版本iOS10或更高版本Android5.0(APIlevel21)或更高版本🔗Unity集成Demo参考链接🔗UnityTapSDK功能体验APK下载链接二、集成前准备1.创建应用进入开发者后台,按照提示开始创建应用;2.开通服务在使用TDS实名认证和防沉迷服务之前,需要在上面创建的应

  7. ruby - 如何使用适用于 ruby​​ 的 aws sdk 创建 route53 记录集? - 2

    EC2会在实例停止然后重新启动时为其提供新的IP地址,因此我需要能够自动管理route53记录集,以便我可以一致地访问内容。遗憾的是,sdk的route53部分的文档远不如ec2的文档那么健壮(可以理解),所以我有点卡住了。到目前为止,从我所看到的情况来看,似乎change_resource_record_sets(link)是可行的方法,但我对:chages需要什么感到困惑>因为它提到了一个Change对象,但没有提供指向所述对象描述的链接。这是我的代码目前的样子:r53.client.change_resource_record_sets(:hosted_zone_id=>'MY_

  8. ruby - 为 IO::popen 拯救 "command not found" - 2

    当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

  9. ruby - IO::EAGAINWaitReadable:资源暂时不可用 - 读取会阻塞 - 2

    当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab

  10. ruby - 如何使用 ruby​​ fibers 避免阻塞 IO - 2

    我需要将目录中的一堆文件上传到S3。由于上传所需的90%以上的时间都花在了等待http请求完成上,所以我想以某种方式同时执行其中的几个。Fibers能帮我解决这个问题吗?它们被描述为解决此类问题的一种方法,但我想不出在http调用阻塞时我可以做任何工作的任何方法。有什么方法可以在没有线程的情况下解决这个问题? 最佳答案 我没有使用1.9中的纤程,但是1.8.6中的常规线程可以解决这个问题。尝试使用队列http://ruby-doc.org/stdlib/libdoc/thread/rdoc/classes/Queue.html查看文

随机推荐