Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
(Redirected from Web)
Jump to: navigation, search


Connect JavaScript SDK to Web and Node.js applications

The latest version is 2.3.4.

Dependencies for browser

For the library to work, you need to include either jQuery or Zepto in your html before quickblox.min.js, like so:

<script src=""></script>
<script src=""></script>

Bower and RequireJS

If you use bower package manager for your project, you can install JS SDK through bower:

bower install quickblox --save

When you use RequireJS, you are able to use quickblox as AMD module. SDK supports UMD (Universal Module Definition) pattern for JavaScript modules. So it is possible to use SDK everywhere (as browser global variable, with AMD module loader like RequireJS or as CommonJS module for Node.js environment).

Node.js and NPM integration

Also you can use QuickBlox JavaScript SDK with server-side applications on NodeJS through the native node package. Just install the package in your application project like that:

npm install quickblox --save

And you're ready to go:

var QB = require('quickblox');
// OR to create many QB instances
var QuickBlox = require('quickblox').QuickBlox;
var QB1 = new QuickBlox();
var QB2 = new QuickBlox();

Download ZIP archive

QuickBlox JavaScript SDK, zip archive

Browser code samples

Learn how to include Video/Audio calls, create Group Chat room and 1 to 1 Chat, enable Push Notifications, authenticate users via Facebook/Twitter, show users' Locations and POIs, store and retrieve files from the cloud — these code samples are really simple so that even beginner developers can understand them.

Title APIs used Description
Simple JavaScript Chat (XMPP) code sample Chat, Users The Chat code sample connects and socializes your users with the chat module. Features include: Peer to Peer Chat; Group Chat; Location-based Chat.

Simple JavaScript VideoChat (WebRTC) code sample Chat, VideoChat The VideoChat code sample allows you to easily add video calling and audio calling features into your Web app. Enable a video call function similar to Skype using this code sample as a basis.


Simple Javascript content storage and update code sample Content The Content sample allows you to send, stream, store, share and save content, so that you may update your app's content without having to republish..

Simple JavaScript Users authentication code sample Users The Users code sample helps you manage and retain your user base across all platforms. It includes a simple authentication process with Single Sign-On and integration across all popular platforms, including social integration with Facebook/Twitter.

Simple JavaScript Custom Objects (key value data store) code sample Custom Objects This Custom Objects sample allows you to create any server side data structure, utilise it for any purpose, create any logic and many other custom features.

Simple Push Notifications guide Messages Push notifications to your user base — even when your app is not running! This guide enables you to send notifications and alerts to users at any time through an API or easy-to-use admin panel. You can filter who you send messages to through additional parameters.

Cordova/PhoneGap code samples

Learn how to include Video/Audio calls, create Group Chat room and 1 to 1 Chat in your Apache Cordova (PhoneGap) application — these code samples are really simple so that even beginner developers can understand them.

Title APIs used Description
Simple Cordova Chat (XMPP) code sample Chat, Users The Chat code sample connects and socializes your users with the chat module. Features include: Peer to Peer Chat; Group Chat; Location-based Chat.

Simple Cordova VideoChat (WebRTC) code sample Chat, VideoChat The VideoChat code sample allows you to easily add video calling and audio calling features into your Cordova app. Enable a video call function similar to Skype using this code sample as a basis.

Browsers support

IE Firefox Chrome Safari Opera Android Browser Blackberry Browser Opera Mobile Chrome for Android Firefox for Android
10+ 4+ 13+ 6+ 12+ 4.4+ 10+ 12+ 35+ 30+

Getting started

To use inside a browser, a window scoped variable called QB is created. Most, with the notable exception of init, take a callback parameter which gets called with an error and result parameter (ala node.js).

The common way to interact with QuickBlox can be presented with the following sequence of actions:

  1. Initialize framework
  2. Authorisation
  3. Perform actions

Initialize framework

In addition, there is helpful 5 minute guide

Initialize framework with application credentials:

  appId: 28287,
  authKey: 'XydaWcf8OO9xhGT',
  authSecret: 'JZfqTspCvELAmnW'

Initialize framework with existing QB token:

var sessionToken = '1b785b603a9ae88d9dfbd1fc0cca0335086927f1';
var appId = 3451;
QB.init(sessionToken, appId);

This means you can generate a token elsewhere (e.g. on the server side), and then use this token and application ID to initialise the SDK.


To be able to use QuickBlox API you have to create a session.

There are 2 types of session:

  • Application session. It provides only READ access to data.
  • User session. It provides CRUD (Create, Read, Update, Delete) access to data.

To create an application session use this code:

QB.createSession(function(err, result) {
  // callback function

With an Application session you can READ any data you need and only have to do one Create operation — User Sign Up).

To update an Application session to a User session you have to login to QuickBlox:

var params = {login: 'garry', password: 'garry5santos'};
// or through email
// var params = {email: '', password: 'garry5santos'};
// or through social networks (Facebook / Twitter)
// var params = {provider: 'facebook', keys: {token: 'AM46dxjhisdffgry26282352fdusdfusdfgsdf'}};
QB.login(params, function(err, result) {
  // callback function

Or, if the user is already exist, you can create a User session in single query as well:

var params = {login: 'garry', password: 'garry5santos'};
// or through email
// var params = {email: '', password: 'garry5santos'};
// or through social networks (Facebook / Twitter)
// var params = {provider: 'facebook', keys: {token: 'AM46dxjhisdffgry26282352fdusdfusdfgsdf'}};
QB.createSession(params, function(err, result) {
  // callback function

A session will remain valid for 2 hours after the last request to QuickBlox was performed.

Session expiration

You may now specify a session expiration listener in this configuration. It looks like this:

config = {
  on: {
    sessionExpired: [Function]
QB.init(3477, 'ChRnwEJ3WzxH9O4', 'AS546kpUQ2tfbvv', config);

It has been placed inside the "on" field so that we can add more listeners in the future. This function fires when the SDK makes a request and recognises an expired session error. It will execute this function before it executes the original callback for the request. You could use it to create a new session, request a new token from your backend, or simply tell the user to refresh the page.

This function accepts 2 parameters, "next" and "retry". Calling next() will cause the original callback of the request to be fired - you would use this if your session creation/regeneration fails. Retry will make the original request again with your newly regenerated token, meaning minimal interruption to the operation of your code.


We recommend you to create config.js configuration file in your js-application and insert your QB application credentials and other ancillary data into it.

A custom configuration can look like this:

var CONFIG = {
  endpoints: {
    api: "", // set custom API endpoint
    chat: "" // set custom Chat endpoint
  chatProtocol: {
    active: 2 // set 1 to use BOSH, set 2 to use WebSockets (default)
  debug: {mode: 1} // set DEBUG mode
QB.init(3477, 'ChRnwEJ3WzxH9O4', 'AS546kpUQ2tfbvv', CONFIG);

The above would enable debugging, disable ssl and change the endpoints so that requests would go to another server.

There are 3 debug mods:

  • debug: {mode: 0} - logs are off
  • debug: {mode: 1} - the SDK will be printing logs to console.log()
  • debug: {mode: 2, file: "appname_debug.log"} - the SDK will be printing logs into file with name "appname_debug.log". Works only on Node.js.

Test API: Spec Runner

You can check QuickBlox API tests with JavaScript SDK.

  • To use the Spec Runner, head over to the Spec Runner page on GitHub.
  • Or if you download the Javascript SDK, you will find the Spec Runner in the /spec folder.

Framework changelog

v2.3.4 — Oct. 18, 2016


  • Method for send message and method for send system message return message id.

v2.3.3 — Oct. 07, 2016


  • SDK can send and receive the body in the system message.

v2.3.2 — Oct. 05, 2016


  • Removed parseInt() method for the 'id' attribute in attachment.

v2.3.1 — Sept. 29, 2016


  • Updated method 'get' in Roster.

v2.3.0 — Sept. 28, 2016


  • Full Node.js environment support.


  • Can't install QB via bower.

v2.2.3 — Sept. 27, 2016


  • Updated Strophe lib to v.1.2.8;
  • Send initial presence if one of client (instance) goes offline.

v2.2.2 — Sept. 16, 2016


  • Updated logic of privacy list user blocking (two ways).

v2.2.1 — Sept. 07, 2016


  • Updated regexp for room name in WebRTC sample;

v2.2.0 — Sept. 07, 2016


  • QB.webrtc.getMediaDevices return all devices (video/audio inputs);
  • Added a parameter to listener onCallStatsReport (session, userId, stats, error);
  • Set statsReportTimeInterval is false by default;
  • Added a new type of login to WebRTC sample.


  • Changed the source folder name from 'js' to 'src';
  • Changed bootstrap version (4.0.0);

v2.1.5 — Aug 30, 2016


  • QB.webrtc.onReconnectFailedListener to handle chat reconnection errors.
  • QB.webrtc.onInvalidEventsListener handles 'onAccept', 'onReject', 'onStop' (audio/video call) events when session has unsuitable state.


  • Added a property recipient_id to message object in

v2.1.4 — Jul 19, 2016


  • QB.content.upload now returns an empty {} as a result in its callback.
  • QB.content.createAndUpload callback now doesn't contain a path parameter in the result.


  • Adopt QB.content.createAndUpload method to work with different files storages.

v2.1.3 — Jul 14, 2016


  • Added method.


  • wasn't working on node.js.

v2.1.2 — May 16, 2016


  • doesn't fire success callback.

v2.1.1 — Mar 16, 2016


  • issue when id (blobId) try to parse into Int(*, 10).

v2.1.0 — Mar 04, 2016


  • Video chat(WebRTC) Stats API (added onCallStatsReport callback and statsReportTimeInterval config property) - allows access to the statistical information about a peer connection.


  • issue with video chat where the Firefox browser doesn't produce a connection closed event (workaround via WebRTC Stats API using stats.bytesReceived). Also, a video call isn't recovered if a user on Firefox loses the Internet connection for a while during the call.
  • undefined 'getError' method issue in listeners;


  • XMPP library Strophe.js to 1.2.4 version

v2.0.4 — Feb 01, 2016

  • Now we connect all library dependencies via npm (this should fix all issues with the 3rd party build tools).
  • Wrap all Video Chat module callbacks into safeCallbackCall function.
  • Added more TURN servers (Ireland, Singapore) for Video Chat.
  • Ability to run tests from command line via jasmine command.
  • travis-ci integration

v2.0.3 — Jan 21, 2016

  • Fixed an issue with chat login in Safari browser.

v2.0.2 — Jan 11, 2016

  • Fixed an issue when it wasn't possible to use the library on node.js
  • Added method.
  • Added errors handler in VideoChat sample

v2.0.1 — Jan 6, 2016

v1.17.2 — Dec 7, 2015

  • Fixed an issue with WebRTC Video calling module when QB.init(sessionToken, appId) is used.

v1.17.1 — Dec 7, 2015

  • Added, error) to track errors in chat.
  • Added an ability to init SDK via QB.init(sessionToken, appId).

v1.17.0 — Dec 4, 2015

  • Privacy Lists API
  • Now works on node.js. The method was deleted.
  • Added tests via Jasmine for all modules

v1.16.1 — Nov 24, 2015

  • Fixed an issue with chat 'delivered' status where a user received the delivery receipts for messages sent to himself.

v1.16.0 — Nov 17, 2015

  • Chat:
    • added onReconnectListener and onDisconnectedListener listeners to manage connection states
    • wrapped up all chat callbacks into try/catch
    • added the read/delivered message statuses to chat sample
    • moved chat sample notifications to System Notifications API
    • added API to get unread messages count:, callback)
    • force message deletion API
    • delete multiple dialogs in a single query API
    • fixed an issue with method. Now in a case of error it returns object instead of string.
  • WebRTC Video calling:
    • Got rid of MediaStream.stop() warning
  • Users:
    • Twitter Digits integration
  • Other:
    • Simplified custom endpoints setup via config
    • Removed ssl config. From now there is no way to use unsecure connection.
    • Renamed 'Messages' to 'Push Notifications' module.
    • Reviewed Users, Content tests
    • Removed s3Bucket and turn settings from config

v1.15.2 — Nov 13, 2015
  • Updated methods QB.content.privateUrl and QB.content.publicUrl - now you have to pass the file's uid instead of id.
  • Fixed an issue with QB.content.privateUrl and QB.content.publicUrl on custom API domains.
v1.15.1 — Oct 16, 2015
  • API to mark chat messages as 'markable'
v1.15.0 — Oct 16, 2015
  • System Notifications API
  • Chat Read/Delivered statuses API
  • Added a method QB.webrtc.close(); to close the connection.
  • Updates for now you can pass occupants_ids as an array as well.
v1.14.0 — Oct 2, 2015
  • Advanced logs management, with ability to save logs to file.
  • Removed an ability to enable debug mode in QB.init. Now you have to use config map for this.
  • Now QB.content.createAndUpload works on node.js
  • Removed Places API
  • Added QB.content.privateUrl and QB.content.publicUrl helpers
v1.13.1 — Sep 18, 2015
  • Ability to use user_id (not only user's jid) in Roster methods
v1.13.0 — Sep 2, 2015
  • Added
v1.12.0 — Aug 20, 2015
  • WebRTC:
    • New callback listener: QB.webrtc.onUserNotAnswerListener
    • Cross-platform calling (Web/iOS/Android) bug fixes
  • Chat
    • Renamed to
    • Ability to pass user's resource when login to chat:{userId: 35, password: 'bestpass', resource: 'MacBookPro OS X'}, ...});
v1.11.0 — Aug 11, 2015
  • WebRTC updates:
    • Updated the arguments list of QB.webrtc.stop from QB.webrtc.stop(userId, reason, extension) to QB.webrtc.stop(userId, extension). Don't need to use a 'reason' argument anymore. You can use extension parameter to pass any data.
    • Added a callback to track the session state: QB.webrtc.onSessionStateChangedListener = function(newState, userId).
    • Added new config: webrtc.answerTimeInterval.
    • Cross-platform calling (Web/iOS/Android) bug fixes
    • Bug fixes.
v1.10.0 — Aug 10, 2015
  • support of 'now typing' Chat API
  • added 'getRecipientId' chat helper method
  • ability to get 'messageId' on a sender's side
  • fixed an issue with chat connect on IE
  • force dialog deletion API
v1.9.3 — Jul 14, 2015
  • added an ability to use user_id as a first parameter in
  • added an ability to use user_id in
  • added an ability to provide the page & per_page parameters in QB.content.list
v1.9.2 — May 22, 2015
v1.9.0 — Mar 04, 2015
  • better WebRTC support
v1.8.0 — Feb 07, 2015
  • QB.webrtc
    • updated Signaling messages and API
    • added a support of the cross-platform video / audio calls (web-ios-android)
    • small bugfix
v1.7.0 — Jan 13, 2015
  • Allowed use of Zepto.js with QB JS SDK
  • Added sessionExpired listener function which checks the expiration time for session
  • Added ISO time injection to server responses
  • new API:
    • QB.getSession() for retrieving info about current session
v1.6.0 — Dec 17, 2014
  • Added WebRTC module to SDK core
  • Removed the deprecated webrtc plugin
v1.5.0 — Nov 28, 2014
  • Return back to CommonJS modules
  • Support of UMD (Universal Module Definition) for SDK
  • bugfix with QB variable for browser
v1.4.3 — Nov 25, 2014
  • Rewrited SDK with RequireJS modules
  • Published SDK to Bower
    • added method
v1.3.8 — Nov 10, 2014
  • added configuration options to QB.init()
v1.3.7 — Oct 27, 2014
    • auto reconnect to chat after session closing (added callback)
    • enabled Carbons extension
    • improved roster logic
    • small bugfix
v1.3.5 — Sep 26, 2014
    • added API: Create a message
    • added API: Remove chat dialog
    • Using MongoDB.Bson.ObjectID as the XMPP ID
    • Added the callback functions to roster methods
    • Fixed receiving messages for Safari and IE
    • Fixed removing of roster item
v1.3.0 — Sep 1, 2014
  • Added Chat 2.0 module (Note! doesn't available in npm package yet)
v1.2.0 — Jun 15, 2014
  • Updated the SDK core
    • removed jQuery library
    • completion of support IE9
    • QB.session and QB.config are deprecated (please use QB.service.qbInst object instead)
    • optimization SDK
  • Updated Auth module
    • added Twitter authorization
  • Updated Users module
    • added all users filters
    • renamed perPage and pageNo to per_page and page respectively
    • get user by external ID
    • delete user by external ID
    • added .resetPassword() function
  • Bug fixes Content and CO modules
v1.1.13 — Jun 7, 2014
  • Node.js compatibility
  • Created a node npm package
v1.1.0 — Apr 24, 2014
  • Added chat and webrtc plugins
v1.0.1 — Feb 25, 2014
  • Added initialization with existing QB token
v1.0.0 — Jan 22, 2014
  • SDK stable version
  • (Users, Content, Location, Messages, Custom Objects) API calls are covered