Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ The QuickBlox JavaScript SDK provides a JavaScript library making it even easier

For the library to work, you need to include either [jQuery](http://jquery.com/) or [Zepto](http://zeptojs.com/) in your html before `quickblox.min.js`, like so:

For correct work of JS SDK you must include the library in your html before `quickblox.min.js`, like so:

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/quickblox/2.5.4/quickblox.min.js"></script>
```

Begin with version 2.5.0 no dependencies for work correctly is not needed.
Beginning with version 2.5.0, no dependencies are need for the QuickBlox SDK to work correctly.

## Bower and RequireJS

If you use bower package manager for your project, you can install JS SDK through bower:
If you use the bower package manager for your project, you can install the 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)](https://github.com/umdjs/umd) 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).
When you use **RequireJS**, you are able to use QuickBlox as an AMD compliant module. The SDK supports the [UMD (Universal Module Definition)](https://github.com/umdjs/umd) pattern for JavaScript modules, so it is possible to use the SDK everywhere (as a global variable in the browser via an AMD module loader like RequireJS or as a CommonJS module in a 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:
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 this:

```
npm install quickblox --save
Expand Down
80 changes: 40 additions & 40 deletions quickblox.min.js

Large diffs are not rendered by default.

70 changes: 43 additions & 27 deletions src/modules/qbChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,34 @@ function ChatProxy(service) {
* Uses by Strophe
*/
if (Utils.getEnv().browser) {
// strophe js
self.connection = new Connection();
}else{
// node-xmpp-client
self.nClient = new NodeClient({
'autostart': false,
'reconnect': true
});

// override 'send' function to add some logs
var originSendFunction = self.nClient.send;
self.nClient.send = function(stanza) {
Utils.QBLog('[Chat]', 'SENT:', stanza.toString());
originSendFunction.call(self.nClient, stanza);
};

self.nodeStanzasCallbacks = {};
// strophe js
self.connection = new Connection();

/** Add extension methods to track handlers for removal on reconnect */
self.connection.XHandlerReferences = [];
self.connection.XAddTrackedHandler = function (handler, ns, name, type, id, from, options) {
self.connection.XHandlerReferences.push(self.connection.addHandler(handler, ns, name, type, id, from, options));
};
self.connection.XDeleteHandlers = function () {
while (self.connection.XHandlerReferences.length) {
self.connection.deleteHandler(self.connection.XHandlerReferences.pop());
}
};
} else {
// node-xmpp-client
self.nClient = new NodeClient({
'autostart': false,
'reconnect': true
});

// override 'send' function to add some logs
var originSendFunction = self.nClient.send;
self.nClient.send = function(stanza) {
Utils.QBLog('[Chat]', 'SENT:', stanza.toString());
originSendFunction.call(self.nClient, stanza);
};

self.nodeStanzasCallbacks = {};
}

this.service = service;
Expand Down Expand Up @@ -649,6 +660,11 @@ ChatProxy.prototype = {
case Strophe.Status.CONNECTED:
Utils.QBLog('[Chat]', 'Status.CONNECTED at ' + chatUtils.getLocalTime());

// Remove any handlers that might exist from a previous connection via
// extension method added to the connection on initialization in qbMain.
// NOTE: streamManagement also adds handlers, so do this first.
self.connection.XDeleteHandlers();

if(config.streamManagement.enable && config.chatProtocol.active === 2){
self.streamManagement.enable(self.connection, null);
self.streamManagement.sentMessageCallback = self._sentMessageCallback;
Expand All @@ -657,17 +673,17 @@ ChatProxy.prototype = {
self._isLogout = false;
self._isDisconnected = false;

self.connection.addHandler(self._onMessage, null, 'message', 'chat');
self.connection.addHandler(self._onMessage, null, 'message', 'groupchat');
self.connection.addHandler(self._onPresence, null, 'presence');
self.connection.addHandler(self._onIQ, null, 'iq');
self.connection.addHandler(self._onSystemMessageListener, null, 'message', 'headline');
self.connection.addHandler(self._onMessageErrorListener, null, 'message', 'error');
self.connection.XAddTrackedHandler(self._onMessage, null, 'message', 'chat');
self.connection.XAddTrackedHandler(self._onMessage, null, 'message', 'groupchat');
self.connection.XAddTrackedHandler(self._onPresence, null, 'presence');
self.connection.XAddTrackedHandler(self._onIQ, null, 'iq');
self.connection.XAddTrackedHandler(self._onSystemMessageListener, null, 'message', 'headline');
self.connection.XAddTrackedHandler(self._onMessageErrorListener, null, 'message', 'error');

// enable carbons
self._enableCarbons();

// chat server will close your self.connection if you are not active in chat during one minute
// chat server will close your connection if you are not active in chat during one minute
// initial presence and an automatic reminder of it each 55 seconds
self.connection.send($pres());

Expand Down Expand Up @@ -1088,7 +1104,7 @@ ChatProxy.prototype = {
throw new Error(unsupportedError);
}

return this.connection.addHandler(handler, null, params.name || null, params.type || null, params.id || null, params.from || null);
return this.connection.XAddTrackedHandler(handler, null, params.name || null, params.type || null, params.id || null, params.from || null);

function handler() {
callback();
Expand Down Expand Up @@ -1435,7 +1451,7 @@ MucProxy.prototype = {

if (Utils.getEnv().browser) {
if (typeof callback === 'function') {
self.connection.addHandler(callback, null, 'presence', null, id);
self.connection.XAddTrackedHandler(callback, null, 'presence', null, id);
}

self.connection.send(pres);
Expand Down Expand Up @@ -1478,7 +1494,7 @@ MucProxy.prototype = {
var roomJid = self.helpers.getRoomJid(jid, userCurrentJid);

if (typeof callback === 'function') {
self.connection.addHandler(callback, null, 'presence', presParams.type, null, roomJid);
self.connection.XAddTrackedHandler(callback, null, 'presence', presParams.type, null, roomJid);
}

self.connection.send(pres);
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/streamManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* Chat Stream Management plugin
* doc: http://xmpp.org/extensions/xep-0198.html
*
* To enable this features add to config
* To enable this features add to config
* ```javascript
* streamManagement: {
- enable: true
- }
* ```
*
*
* Uses listener by QB.chat.onSentMessageCallback
*
* ```javascript
Expand Down Expand Up @@ -112,7 +112,7 @@ StreamManagement.prototype._addEnableHandlers = function () {
var self = this;

if (Utils.getEnv().browser) {
self._c.addHandler(_incomingStanzaHandler.bind(self));
self._c.XAddTrackedHandler(_incomingStanzaHandler.bind(self));
} else if (Utils.getEnv().node){
self._c.on('stanza', _incomingStanzaHandler.bind(self));
}
Expand Down