1

Can I restrict the number of users in a session? Is there any option in vline.session? Please guide if this can be done by writing custom javascript.

EDIT:

Referring to https://vline.com/developer/docs/vline.js/vline.MediaSession#examples, a two party call controller is explained. I want to ask is there any way to restrict number of users in a session? There is no such option present in session's docs. Is it supported as a part of the API?

If this can be done using custom javascript, how?

As a part of my effort, I have tried to implement vline-django examples, but could not find a section in documentation that addresses this issue.

EDIT 2: The code that is working for me.

  var vlineClient = (function(){

  var client, session,
    authToken = {{ user|vline_auth_token|safe }},
    serviceId = {% vline_service_id %},
    profile = {{ user|vline_user_profile|safe }};

  // Create vLine client  
  window.vlineClient = client = vline.Client.create({"serviceId": serviceId, "ui": true});
  // Add login event handler
  client.on('login', onLogin);
  // Do login
  client.login(serviceId, profile, authToken);

  function onLogin(event) {
    session = event.target;

    // Find and init call buttons
    var callButtons = document.getElementsByClassName('callbutton');
    for (var i=0; i < callButtons.length; ++i) {
      initCallButton(callButtons[i]);
    }
  }

  // add event handlers for call button
  function initCallButton(button) {
    var userId = button.getAttribute('data-userid');

    // fetch person object associated with username
    session.getPerson(userId).done(function(person) {
      // update button state with presence
      function onPresenceChange() {
        button.setAttribute('data-presence', person.getPresenceState());
      }

      // set current presence
      onPresenceChange();

      // handle presence changes
      person.on('change:presenceState', onPresenceChange);

      // start a call when button is clicked
      button.addEventListener('click', function() {
        person.startMedia();
      });
    });
  }

  return client;
})();

How do I move ahead?

Reference: https://vline.com/developer/docs/vline.js/

4

1 回答 1

1

如果我理解正确,OP 正在尝试建立一个多用户聊天室——这也是我想用 vline 做的事情,因为我也想要 a/v 聊天,所以显然应该限制参与者的数量——看来术语“会话”在这里引起了混乱,所以我将避免使用它

我通过在数据库中创建固定数量的用户并在实际将访问者与其中一个准备好的用户相关联之前自己处理身份验证来解决这个问题 - 所以一些 javascript 将每个访问者作为现有的“匿名”用户之一登录并只设置一个登录?在数据库中标记,以便下一个访问者将作为下一个空用户槽登录,并且当所有槽都被占用时,访问者会收到“聊天室已满 - 稍后再试”响应

可能不是最优雅的解决方案 - 例如,访问者选择的用户名存储在客户端,并且必须重新分配给用户可定义的 vline 会话变量之一,以便它可以与每条消息和logged_in 一起传递?用户退出时需要重置 db 标志

请注意,这几乎是一年前的事了,所以我对我所做的事情有点模糊,但如果你有兴趣分叉它,我的应用程序(rails)在 github 上 - 我还应该补充一点,虽然这种事情并没有得到严格的支持vline API 当时至少有一些暗示正在准备一些类似的功能,所以现在可能有一些 API 支持 - 从那时起我确实注意到他们已经在 github 上发布了一个“聊天室演示”应用程序,我希望他们的实现比我的更简洁,所以你可能想先看看 - 我的应用程序确实有一个带有 gravatars 的大部分完整的 UI,欢迎合作

于 2014-04-20T22:57:04.170 回答