Search code examples
javascriptangularjsquickblox

Quickblox: Cannot get users by tag_list. Error: Token is required


I need to get the users that have been put into a specific room. The room name is entered at log in into the tag_list parameter. I adjusted the example's code to get the users by the tag_list parameter but it says I need a token to get access. Can anyone explain what is happening in the example code that I have not replicated? Here is my code:

$scope.callees = [$scope.user.id];
$scope.sessionType = QB.webrtc.CallType.VIDEO; // AUDIO is also possible
$scope.session = QB.webrtc.createNewSession($scope.callees, $scope.sessionType);
var mediaParams = {
    audio: true,
    video: true,
    options: {
        muted: true,
        mirror: true
    },
    elemId: 'localVideoEl',
    optional: {
        minWidth: 240,
        maxWidth: 320,
        minHeight: 160,
        maxHeight: 240
    }
};

QB.users.get(
    {
        'tags': [$scope.user.tag_list], 
        'per_page': 100
    }, 
function(err, result){
    if (err) {
        console.log(err);
    } else {
        console.log(result);
    }
});

Solution

  • Well Angular users... Turns out the answer is SO EXCITING!!! (sarcasm) It turns out You have to wrap the request in yet another QB.login and yet another QB.createSession...

    QB.createSession(function(err,result){
        if (result) {
            QB.login($scope.user, function(loginErr, loginUser){
                if (loginErr) {
                    console.log('log in error');
                    console.log(loginErr);
                }else {
    
    // HANDLE USERS                     
    
                    var params = {tags: [$scope.user.tag_list]};
                    QB.users.get(params, function(err, result){
                        if (err){
                            console.log(err);
                        }else{
                            console.log(result);
                        }
                    });
    
    // HANDLE CHAT  
    
                    QB.chat.connect(patient, function(err, res) {
                        if (err) { console.log(err); } else { console.log(res); }
                    });
    
    // HANDLE VIDEO 
    
                    $scope.callees = [$scope.user.id];
                    $scope.sessionType = QB.webrtc.CallType.VIDEO; // AUDIO is also possible
                    $scope.session = QB.webrtc.createNewSession($scope.callees, $scope.sessionType);
    
                    var mediaParams = {
                        audio: true,
                        video: true,
                        options: {
                            muted: true,
                            mirror: true
                        },
                        elemId: 'localVideoEl',
                        optional: {
                            minWidth: 240,
                            maxWidth: 320,
                            minHeight: 160,
                            maxHeight: 240
                        }
                    };
                    $scope.session.getUserMedia(mediaParams, function(err, stream) {
                        if (err){
                            //console.log(err);
                        }else{
                            //console.log(stream);
                        }
                    });
    
    
    
    
                }
            });
        }else if (err) {
            console.log(err);
        }
    });
    

    So it appears despite all the efforts to have a single page app you still have to log in on every page... If anyone in the Angular community has a better answer to continuously logging in after every route change I would be not sarcastically delighted! Feel free to list your solution and I will mark it correct instead of mine... as mine, I feel, is not the real answer...