简体   繁体   English

OpenTok / Tokbox显示另一页,直到有一个订阅

[英]OpenTok/Tokbox Display another page until a suscribe is on

I'm trying to make a "waiting page" until one subscriber get in the call, I tried this: 我试图建立一个“等待页面”,直到一个订户加入呼叫为止,我尝试这样做:

    <div id="cont">

          <div class="row">

         <p>Waiting</p>

        </div>
</div>

And on the session.suscribe() method I have this: 在session.suscribe()方法上,我有:

            session.subscribe(event.stream, 'subscriber', subscriberOptions, function (error) {

                if (error) {
                    console.log('There was an error publishing: ', error.name, error.message);
                } else {
                    delWaiting();
                }
            });

    function delWaiting() {
        $("#cont").empty();
        $('#cont').html('<div id="videos"> <div id= "subscriber"> </div > <div id="publisher"> </div> </div>');

    }

In this example I tried to remove the waiting content and add the html that I need for the video call, the problem is that this doesn't work because of all the other html that opentok creates, is there a simple way to do this using opemtok methods? 在此示例中,我尝试删除等待的内容并添加视频通话所需的html,问题是由于opentok创建的所有其他html导致此方法不起作用,是否有一种简单的方法可以使用opemtok方法?

The main reason it's not working is because you are calling session.subscribe() before you create the element with id subscriber . 它不工作的主要原因是因为你调用session.subscribe()将创建一个ID的元素之前subscriber You need to make sure the element with id subscriber exists before calling session.subscribe() . 您需要调用session.subscribe() 之前确保具有id subscriber的元素存在。

The following is an extension of your snippet but instead of an id string it passes a DOM element into session.subscribe() , then appends this element to the DOM after success: 以下是您代码段的扩展,但它代替了ID字符串,而是将DOM元素传递给session.subscribe() ,然后在成功后将该元素附加到DOM:

var subscriberContainer = document.createElement('div');

session.subscribe(event.stream, subscriberContainer, subscriberOptions, function (error) {
  if (error) {
    console.log('There was an error subscribing: ', error.name, error.message);
  } else {
    delWaiting(subscriberContainer);
  }
});

function delWaiting(subscriberContainer) {
  $("#cont").empty().html('<div id="videos"> <div id="subscriber"> </div > <div id="publisher"> </div> </div>');
  $('#subscriber').append(subscriberContainer);
}

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

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