限制vline中会话中的用户数

时间:2014-04-18 14:08:55

标签: javascript vline

我可以限制会话中的用户数量吗? vline.session有什么选择吗?如果可以通过编写自定义javascript来完成,请指导。

编辑:

参考https://vline.com/developer/docs/vline.js/vline.MediaSession#examples,解释了双方呼叫控制器。我想问一下,有没有办法限制会话中的用户数量?会话的文档中没有这样的选项。 是否支持作为API的一部分?

如果可以使用自定义javascript完成,怎么做?

作为我努力的一部分,我试图实现vline-django示例,但在文档中找不到解决此问题的部分。

编辑2:为我工作的代码。

  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;
})();

我如何继续前进?

参考:https://vline.com/developer/docs/vline.js/

1 个答案:

答案 0 :(得分:1)

如果我理解OP正在尝试建立一个多用户聊天室 - 这也是我想用vline做的,因为我想要一个/ v聊天,参与者的数量显然应该被限制 - 它似乎“会话”一词引起了混淆,所以我将不再使用它

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

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

请注意,这是差不多一年前所以我有点模糊我正在做什么,但我的应用程序(rails)在github如果你有兴趣叉它 - 我也应该补充说,虽然这种事情并非严格当vline API支持时,至少有一些提示正在准备一些类似的功能,所以现在可能有一些API支持 - 我从那时起就注意到他们已经发布了一个"chat room demo"应用程序github,我希望他们的实现比我的更简洁,所以你可能想先看一下 - 我的应用程序确实有一个大多数完整的用户界面,并欢迎合作

相关问题