Search code examples
javascriptchatquickblox

Quickblox Group chat Join Not working (Javascript SDK)


I have troubles using quickblox JS SDK for group chat

QB.chat.muc.join(dlg.xmpp_room_jid, function(){
 console.log("Joined dialog " + dlg._id + " xmpp " + dlg.xmpp_room_jid);
})

This is from Quickblox's sample code. I have checked the source code, and compared with two, but I've found no differences. Finally, I have replaced app id, api key and some credentials to working quickblox's sample code. And realized that sample app is not working with my credentials. Does it really matter with QB account?


Solution

  • I have figured out. In my case, the reason was from your session creation API. API Documentation says to use [POST] /session.json, but the users with this API is not working for group chat. I used /auth.json for session creation and used signup RESTful api, and it is working now. This is not account problem. I think they should check that API or update documentation.

    This is the usage of /auth.json api.

    function qbGenerateSession() {
        // Generate signature
        $nonce = rand();
        $timestamp = time(); // time() method must return current timestamp in UTC but seems like hi is return timestamp in current time zone
        $signature_string = "application_id=" . QB_APP_ID . "&auth_key=" . QB_AUTH_KEY . "&nonce=" . $nonce . "&timestamp=" . $timestamp;
    
        $signature = hash_hmac('sha1', $signature_string , QB_AUTH_SECRET);
    
        //echo $signature;
        //echo $timestamp;
    
        // Build post body
        $post_body = http_build_query( array(
            'application_id' => QB_APP_ID,
            'auth_key' => QB_AUTH_KEY,
            'timestamp' => $timestamp,
            'nonce' => $nonce,
            'signature' => $signature,
            ));
    
        // Configure cURL
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://api.quickblox.com/auth.json'); // Full path is - https://api.quickblox.com/auth.json
        curl_setopt($curl, CURLOPT_POST, true); // Use POST
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    
        // Execute request and read response
        $response = curl_exec($curl);
    
        $token = null;
    
        try {
            $authInfo = json_decode($response);
            $token = $authInfo->session->token;
        }
        catch (Exception $e) {
            curl_close($curl);
            return null;
        }
    
        // Close connection
        curl_close($curl);
    
        return $token;
    }