菜鸟教程小白 发表于 2022-12-12 11:17:59

ios - OpenTok iOS API :Stream in iPad more then two


                                            <p><p>我想在不同设备上为两个以上的用户进行直播并从 opentok 获取 api 我已经从 (<a href="https://github.com/opentok/OpenTok-iOS-Hello-World" rel="noreferrer noopener nofollow">https://github.com/opentok/OpenTok-iOS-Hello-World</a>) 下载了演示应用程序,这不是 webrtc,我使用 key 、 session 和 token 运行应用程序梨对梨的残疾,
它适用于两个直播流,但是当我托盘连接第三个流时,我无法得到那个,
我发现盯着演示应用程序(在 iPad 2/3/4 上,限制是四个流。一个应用程序最多可以同时拥有四个订阅者,或者一个发布者和最多三个订阅者。)</p>

<p>我正在用三台 iPad 进行测试,屏幕上只有两台</p>

<p>那么如何在三个 iPad 上同时制作两个以上的流</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您链接的项目 (OpenTok-iOS-Hello-World) 仅用于订阅一个流。作为概念验证,您只需修改一些方法并在 <code>ViewController.m</code></p> 中添加一个实例变量,就可以非常简单地在屏幕上显示两个订阅者

<p>创建一个跟踪订阅者数量的变量:</p>

<pre><code>@implementation ViewController {
    OTSession* _session;
    OTPublisher* _publisher;
    OTSubscriber* _subscriber;
    int _numSubscribers;// **NEW**
}
</code></pre>

<p>在初始化方法中初始化变量:</p>

<pre><code>- (void)viewDidLoad
{
    ;
    _session = [ initWithSessionId:kSessionId
                                           delegate:self];
    _numSubscribers = 0;// **NEW**
    ;
}
</code></pre>

<p>确保我们没有订阅我们自己的流:</p>

<pre><code>static bool subscribeToSelf = NO;
</code></pre>

<p>修改此 session 委托(delegate)方法中不再关心是否已有订阅者:</p>

<pre><code>- (void)session:(OTSession*)mySession didReceiveStream:(OTStream*)stream
{
    NSLog(@&#34;session didReceiveStream (%@)&#34;, stream.streamId);

    // See the declaration of subscribeToSelf above.
    if ( (subscribeToSelf &amp;&amp; )
         ||
         (!subscribeToSelf &amp;&amp; !)
       ) {
      // ** Changing if statement **
      if (_numSubscribers &lt; 2) {
            _subscriber = [ initWithStream:stream delegate:self];
            _numSubscribers++;
      }
    }
}
</code></pre>

<p>将订阅者并排放置,占用更少的宽度:</p>

<pre><code>- (void)subscriberDidConnectToStream:(OTSubscriber*)subscriber
{
    NSLog(@&#34;subscriberDidConnectToStream (%@)&#34;, subscriber.stream.connection.connectionId);
    // ** Calculate the frame **
    CGRect subFrame = CGRectMake(0, widgetHeight, widgetWidth / 2, widgetHeight)
    if (_numSubscribers == 2) subFrame = CGRectOffset(subFrame, widgetWidth / 2, 0);
    ;
    ;
}
</code></pre>

<p>注意:此解决方案不会产生稳定的应用程序。只要您不断开中间的任何 iPad,它应该可以让您看到两个订阅者。要完成此操作,您需要将在 <code>session:didRecieveStream:</code> 中创建的 OTSubscribers 存储在像 NSArray 这样的集合中,处理删除正确的订阅者并减少 <code>_numSubscribers</code>在 <code>session:didDropStream:</code> 中,并考虑您希望 <code>updateSubscriber</code> 方法如何工作。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - OpenTok iOS API :Stream in iPad more then two,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/16769518/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/16769518/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - OpenTok iOS API :Stream in iPad more then two