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/

sinhayash
  • 2,693
  • 4
  • 19
  • 51
  • your question does not explain very well what you really want to solve and what you have done so far to resolve it on your own. You should start with explaining a bit of context of your question/task first. Then, you should do first some research on your own. If yo do not succeed, come to SO, describe what you have found and ask for further advice. – Jan Vlcinsky Apr 18 '14 at 14:41
  • @JanVlcinsky What else may I explain? Please help. – sinhayash Apr 20 '14 at 17:35
  • good rewrite. Now I understand what you are talking about and it is more likely, that someone who is familiar with vline will help you. I was commenting as general reviewer, not as JavaScript and vline expert. – Jan Vlcinsky Apr 20 '14 at 18:53
  • my quick reaction (without deep knowledge). Generally, a session represents "single login" and describes the fact, one user is connected/logged somewhere. By that definition one session allows only one user. Reading `vline.Session` definition "A Session represents an end-user login to the vLine Cloud. It is responsible for maintaining user presence and performing requests on behalf of the end-user (e.g., subscribing to the presence of other users)." looks, like vline uses the same concept. Do you really want to limit number of users in a session or number of sessions? – Jan Vlcinsky Apr 20 '14 at 18:57

1 Answers1

1

if i understand correctly the OP is trying to make a multi-user chat room - this is also what i wanted to do with vline and because i wanted a/v chat as well the number of participants should obviously be capped - it appears that the term 'session' is causing the confusion here so i will refrain from using it

i worked around this by creating a fixed number of users in a db and handling authentication myself before actually associating a visitor with one of the prepared users - so some javascript logs in each visitor as one of those existing 'anonymous' users and sets only a logged_in? flag in the db so that the next visitor will log in as the next vacant user slot and when all slots are occupied the visitor gets a "chat room full - try again later" response

probably not the most elegant solution - for example the visitor chosen usernames are stored client-side and must be re-assigned to one of the user-definable vline session vars so it can be passed along with each message and the logged_in? db flag needs to be reset when the user exits

note that this was almost a year ago so im a bit foggy on exactly what i did but my app (rails) in up on github if youre interested to fork it - also i should add that although this sort of thing wasnt strictly supported by the vline API at the time there were at least some hints that some analogous feature was being prepared for so there may be some API support for this now - i did notice since then that they have released a "chat room demo" app on github and i would expect that their implementation is more concise than mine so you may want to look at that first - my app tho does have a mostly complete UI with gravatars and collaboration is welcomed

Mr-Jonze
  • 111
  • 2
  • great that you provided some answer and valuable hints. However, it is not easy to read your answer as you are using too many abbreviations (OP, a/v). Please, keep in mind reader of your text - use the language, reader will understand without googling for unknown expressions. You also made great proposal to see an application on Github - if you would provide a link to it, it would make using your generous proposal much simpler. – Jan Vlcinsky Apr 21 '14 at 19:27
  • ok thanks for the tips jan - i was intentionally trying not to be so verbose especially as i cant know that the Original Poster will actually return to read this - if he does return and show some interest i will be happy to elaborate further - my main advice tho is to first check out the demo app that vline has provided to see if that meets his needs - i will edit my answer to include the link – Mr-Jonze Apr 22 '14 at 01:29
  • thanks for the edit, the link to your app adds extra value to your answer (and it was very easy to do so). Still, you have left "OP" and "a/v" unexplained. Advice: If you are going to provide quick or incomplete reaction, save your time and skip it completely, or use comment, which allows quick and easy clarification and discussion. But posting half-baked answer is not worth your effort and spoils Stack Overflow space with difficult to use content. You can also get negative points for such answers. – Jan Vlcinsky Apr 22 '14 at 06:56
  • @Mr-Jonze the chat room demo you mentioned is not working for me, [or may be I am doing something wrong] Also, I know it can be done somehow using db flags, I wanted an elegant solution. Thanks. – sinhayash Apr 24 '14 at 06:57