简体   繁体   English

OpenTok SDK - 空引用错误 - Xamarin iOS

[英]OpenTok SDK - Null reference error - Xamarin iOS

I have built a simple Xamarin iOS app to subscribe (no publishing) to a single stream and display it in my primary view.我构建了一个简单的 Xamarin iOS 应用程序来订阅(不发布)单个流并将其显示在我的主视图中。 The app will connect to a screen capturing stream from a desktop application that will be publishing the stream.该应用程序将从将发布流的桌面应用程序连接到屏幕捕获流。

My Setup我的设置

Windows VS paired to a remote Mac, running a simulator on my local windows environment. Windows VS 与远程 Mac 配对,在我的本地 Windows 环境中运行模拟器。

Using Xamarin.OpenTok.iOS (SDK v2.17.1) Nuget package in project.在项目中使用 Xamarin.OpenTok.iOS (SDK v2.17.1) Nuget 包。

My project is not a Xamarin Forms cross-platform application, but solely an iOS application.我的项目不是 Xamarin Forms 跨平台应用程序,而只是一个 iOS 应用程序。

OpenTok session and tokens generated in project management portal.在项目管理门户中生成的 OpenTok 会话和令牌。 I have attempted both "Relay" and "Routed" with the same results.我尝试了“中继”和“路由”,结果相同。 I have been creating tokens with a 7 day expiration.我一直在创建有效期为 7 天的令牌。

In developing the implementation of the OpenTok SDK into my app, I have followed the project found here在将 OpenTok SDK 的实现开发到我的应用程序中时,我遵循了此处找到的项目

The Issue问题

I am creating a new session passing in my newly generated API Key and Session Id and then Connecting with my subscriber token.我正在创建一个新会话,传入我新生成的 API 密钥和会话 ID,然后连接我的订阅者令牌。

_session = new OTSession(_apiKey, _sessionId, null);
...
_session.ConnectWithToken(_userToken, out error);

I am also subscribing to relevant Session events (ConnectionDestroyed, DidConnect, StreamCreated, StreamDestroyed, DidFailWithError).我还订阅了相关的会话事件(ConnectionDestroyed、DidConnect、StreamCreated、StreamDestroyed、DidFailWithError)。

After starting this connection I am given the following output and none of the events I am subscribed to are invoked.启动此连接后,我得到以下输出,并且没有调用我订阅的任何事件。


Output Log - StackOverflow would not let me paste the log here输出日志 - StackOverflow 不允许我在这里粘贴日志


I am also seeing an attempted connection to the Session in the OpenTok Inspector.我还在 OpenTok Inspector 中看到了与会话的尝试连接。


Session Log会话日志


I am aware of this ticket and have confirmed it is not an expired token.我知道这张票并确认它不是过期的令牌。 I am pretty confident that this null reference is coming from the OpenTok SDK source code and not my code but cannot tell what it is.我非常有信心这个空引用来自 OpenTok SDK 源代码而不是我的代码,但无法说明它是什么。 The error will completely freeze my app as the looping does not stop.该错误将完全冻结我的应用程序,因为循环不会停止。 Any help and guidance would be appreciated.任何帮助和指导将不胜感激。 So the questions are:所以问题是:

What is causing this error and how can I fix it?是什么导致了这个错误,我该如何解决? Am I missing an initialization step?我错过了初始化步骤吗?

Is the iOS Simulator the real issue? iOS模拟器是真正的问题吗?

Thanks谢谢

a simple Xamarin iOS app to subscribe (no publishing) to a single stream and display it in my primary view.一个简单的 Xamarin iOS 应用程序,用于订阅(不发布)单个流并将其显示在我的主视图中。 The app will connect to a screen capturing stream from a desktop application that will be publishing the stream该应用程序将从将发布流的桌面应用程序连接到屏幕捕获流

This is possible to implement with Xamarin Vonage Video API SDK.这可以通过 Xamarin Vonage Video API SDK 实现。 I will try to explain that as detailed as possible, feel free to skip ahead.我将尝试尽可能详细地解释,请随意跳过。

You started correctly with the Xamarin samples.您正确地开始使用 Xamarin 示例。

In fact, there are only 2 changes you need to do to achieve your goal with Xamarin.iOS app (not Xamarin.Forms, will get to that later):实际上,只需进行 2 处更改即可使用 Xamarin.iOS 应用程序实现目标(不是 Xamarin.Forms,稍后会介绍):

  1. Update ApiKey, SessionId and Token in OpentokTestConstants.cs ( here ) file更新ApiKey,会话ID和令牌在OpentokTestConstants.cs这里)文件
  2. Comment out Publish() in the OpentokStreamingService so that the app only subscribes to video streams in the session and does not publish camera stream OpentokStreamingService中的Publish() ,让app只订阅session中的视频流,不发布camera流

Here is a screenshot running the sample app with these changes in iOS simulator and viewing a stream published from the web (I used the "The OpenTok Playground" tool for that)这是在 iOS 模拟器中运行带有这些更改的示例应用程序并查看从网络发布的流的屏幕截图(为此我使用了“OpenTok Playground”工具)

在 Xamarin.iOS 中运行的示例订阅实时流

Now, regarding Xamarin.Forms.现在,关于 Xamarin.Forms。

There is no sample for Xamarin.Forms, unfortunately.不幸的是,没有 Xamarin.Forms 的示例。 If you can share a sample app (without ApiKey/SessionId please) I'd be glad to look at it.如果您可以共享示例应用程序(请不要使用 ApiKey/SessionId),我很乐意查看它。

Generally, a logic for video calls on Xamarin.Forms is:通常,在 Xamarin.Forms 上进行视频通话的逻辑是:

  • have DependencyInjection wiring to expose key methods from OpentokStreamingService that is implemented in iOS/Android samples ( docs on how you do that in Xamarin.Forms )具有 DependencyInjection 接线以公开来自在 iOS/Android 示例中实现的OpentokStreamingService关键方法( 有关如何在 Xamarin.Forms 中执行此操作的文档
  • implement a custom Xamarin.Forms view + renderers for it.为其实现自定义 Xamarin.Forms 视图 + 渲染器。 The view does not need to do anything.视图不需要做任何事情。 The renderer should be doing at least one thing - passing down a reference to a native view to the OpentokStreamingService using a code like this:渲染器应该至少做一件事 - 使用如下代码将本机视图的引用传递给 OpentokStreamingService:
            _opentokService.SetStreamContainer(NativeView, false);

where NativeView is a native (Xamarin.iOS/Xamarin.Android) view (not Xamarin.Forms view).其中 NativeView 是本机 (Xamarin.iOS/Xamarin.Android) 视图(不是 Xamarin.Forms 视图)。 You can get that reference in the renderer's ElementChanged method.您可以在渲染器的ElementChanged方法中获取该引用。

This doc from Xamarin covers that well . Xamarin 的这个文档很好地涵盖了这一点

自定义渲染器 - 获取对本机视图的引用

After the selected line, Control will have a native view reference that you just need to pass to OpentokStreamingService.在选定的行之后, Control将有一个本机视图引用,您只需将其传递给 OpentokStreamingService。

That will get you a scenario working in Xamarin.Forms.这将为您提供在 Xamarin.Forms 中工作的场景。 I hope that this answer helps!我希望这个答案有帮助!

PS: Logging with Vonage Video API Xamarin SDK on iOS PS:在 iOS 上使用 Vonage Video API Xamarin SDK 进行日志记录

There is a better way to get logs for diagnostics purposes with iOS SDK.有一种更好的方法可以使用 iOS SDK 获取日志以进行诊断。 A call like that before any OpenTok SDK calls would give you a very detailed log of what's going on:在任何 OpenTok SDK 调用之前进行这样的调用将为您提供有关正在发生的事情的非常详细的日志:

OpenTok.OpenTokExtraLogging.EnableOpenTokLoggingToConsole();

It will look like this:它看起来像这样:

Vonage Video API Xamarin SDK 详细日志记录选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM