Skip to content

Commit 072c621

Browse files
author
Igor Khomenko
committed
merged
2 parents f458927 + 0f5940f commit 072c621

37 files changed

+552
-9466
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ npm-debug.log
1010

1111
# Use command grunt for create quickblox.js
1212
quickblox.js
13+
14+
#jasmine-npm generate
15+
.grunt

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
node_js:
3+
- "4.1"
4+
5+
before_script: "npm run-script setDependencies"
6+
7+
script: "grunt"
8+
after_success: "jasmine"

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# QuickBlox JavaScript SDK
22

3+
[![travis-ci](https://api.travis-ci.org/QuickBlox/quickblox-javascript-sdk.svg?branch=gh-pages)](https://travis-ci.org/QuickBlox/quickblox-javascript-sdk)
4+
[![npm](https://img.shields.io/npm/v/quickblox.svg)](https://www.npmjs.com/package/quickblox)
5+
[![npm](https://img.shields.io/npm/dm/quickblox.svg)](https://www.npmjs.com/package/quickblox)
6+
37
The QuickBlox JavaScript SDK provides a JavaScript library making it even
48
easier to access the QuickBlox cloud communication backend platform.
59

6-
[QuickBlox](https://quickblox.com) is a suite of communication features & data services (APIs, SDKs, code samples, admin panel, tutorials) which help digital agencies, mobile developers and publishers to add great communication functionality to smartphone applications like in Skype, WhatsApp, Viber.
10+
[QuickBlox](https://quickblox.com) is a suite of communication features & data services (APIs, SDKs, code samples, admin panel, tutorials) which help digital agencies, mobile developers and publishers to add great communication functionality to smartphone applications like in Skype, WhatsApp, Viber.
711

812

913
# Install
@@ -16,7 +20,7 @@ For correct work of JS SDK you must include the library in your html before `qu
1620

1721
```html
1822
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
19-
<script src="https://cdnjs.cloudflare.com/ajax/libs/quickblox/2.0.3/quickblox.min.js"></script>
23+
<script src="https://cdnjs.cloudflare.com/ajax/libs/quickblox/2.0.4/quickblox.min.js"></script>
2024
```
2125

2226
## Bower and RequireJS
@@ -75,6 +79,8 @@ The quickblox.js library is build from a number of **CommonJS modules** containe
7579
These modules are combined through [browserify](http://browserify.org/) into a single `quickblox.js` file in the root and so this is the only file that needs to be included in a `<script>` tag OR in a RequireJS application OR in Node.js environment (everywhere). To build the library, use the [Grunt](http://gruntjs.com/) task runner:
7680

7781
* You need to have the dependencies listed in the package.json available, use `npm install` to load them.
82+
* Install grunt-cli `npm install -g grunt-cli`
83+
* Also you need install jasmine global `npm i -g jasmine` for tests.
7884
* Change the 'version' properties in next files:
7985
* https://github.com/QuickBlox/quickblox-javascript-sdk/blob/gh-pages/js/qbConfig.js
8086
* https://github.com/QuickBlox/quickblox-javascript-sdk/blob/gh-pages/bower.json

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "quickblox",
33
"description": "QuickBlox JavaScript SDK",
4-
"version": "2.0.3",
4+
"version": "2.0.4",
55
"homepage": "http://quickblox.com/developers/Javascript",
66
"main": "quickblox.js",
77
"license": "MIT",
@@ -20,7 +20,8 @@
2020
],
2121
"authors": [
2222
"Igor Khomenko <[email protected]>",
23-
"Vlad Lukhanin <[email protected]>"
23+
"Vlad Lukhanin <[email protected]>",
24+
"Dima Lobanov <[email protected]>"
2425
],
2526
"repository": {
2627
"type": "git",

js/modules/qbChat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var isBrowser = typeof window !== "undefined";
1313
var unsupported = "This function isn't supported outside of the browser (...yet)";
1414

1515
if (isBrowser) {
16-
require('../../lib/strophe/strophe.min');
16+
require('strophe');
1717
// add extra namespaces for Strophe
1818
Strophe.addNamespace('CARBONS', 'urn:xmpp:carbons:2');
1919
Strophe.addNamespace('CHAT_MARKERS', 'urn:xmpp:chat-markers:0');

js/modules/qbPushNotifications.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@
88
var config = require('../qbConfig'),
99
Utils = require('../qbUtils');
1010

11+
var isBrowser = typeof window !== "undefined";
12+
1113
function PushNotificationsProxy(service) {
1214
this.service = service;
1315
this.subscriptions = new SubscriptionsProxy(service);
1416
this.events = new EventsProxy(service);
1517

1618
this.base64Encode = function(str) {
17-
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
18-
return String.fromCharCode('0x' + p1);
19-
}));
20-
}
21-
19+
if(isBrowser) {
20+
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
21+
return String.fromCharCode('0x' + p1);
22+
}));
23+
} else {
24+
return new Buffer(str).toString('base64');
25+
}
26+
};
2227
}
2328

2429
// Subscriptions
@@ -43,7 +48,6 @@ SubscriptionsProxy.prototype = {
4348

4449
delete: function(id, callback) {
4550
Utils.QBLog('[SubscriptionsProxy]', 'delete', id);
46-
4751
this.service.ajax({url: Utils.getUrl(config.urls.subscriptions, id), type: 'DELETE', dataType:'text'},
4852
function(err, res){
4953
if (err) { callback(err, null);}
@@ -72,7 +76,7 @@ EventsProxy.prototype = {
7276
callback = params;
7377
params = null;
7478
}
75-
79+
7680
Utils.QBLog('[EventsProxy]', 'list', params);
7781

7882
this.service.ajax({url: Utils.getUrl(config.urls.events), data: params}, callback);
@@ -92,10 +96,8 @@ EventsProxy.prototype = {
9296

9397
delete: function(id, callback) {
9498
Utils.QBLog('[EventsProxy]', 'delete', id);
95-
9699
this.service.ajax({url: Utils.getUrl(config.urls.events, id), type: 'DELETE'}, callback);
97100
}
98-
99101
};
100102

101103
module.exports = PushNotificationsProxy;

js/modules/webrtc/qbWebRTCClient.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var WebRTCSignalingProvider = require('./qbWebRTCSignalingProvider');
1818
var Helpers = require('./qbWebRTCHelpers');
1919
var RTCPeerConnection = require('./qbRTCPeerConnection');
2020
var SignalingConstants = require('./qbWebRTCSignalingConstants');
21+
var Utils = require('../../qbUtils');
2122

2223
function WebRTCClient(service, connection) {
2324
if (WebRTCClient.__instance) {
@@ -127,7 +128,7 @@ WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension)
127128

128129
delete extension.sdp;
129130
delete extension.platform;
130-
extension["sessionID"] = sessionID;
131+
extension.sessionID = sessionID;
131132

132133
this.signalingProvider.sendMessage(userID, extension, SignalingConstants.SignalingType.REJECT);
133134
} else {
@@ -140,7 +141,7 @@ WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension)
140141
this._cleanupExtension(extensionClone);
141142

142143
if (typeof this.onCallListener === 'function'){
143-
this.onCallListener(session, extensionClone);
144+
Utils.safeCallbackCall(this.onCallListener, session, extensionClone);
144145
}
145146
}
146147

@@ -159,7 +160,7 @@ WebRTCClient.prototype._onAcceptListener = function(userID, sessionID, extension
159160
this._cleanupExtension(extensionClone);
160161

161162
if (typeof this.onAcceptCallListener === 'function'){
162-
this.onAcceptCallListener(session, userID, extensionClone);
163+
Utils.safeCallbackCall(this.onAcceptCallListener,session, userID, extensionClone);
163164
}
164165

165166
session.processOnAccept(userID, extension);
@@ -172,16 +173,17 @@ WebRTCClient.prototype._onAcceptListener = function(userID, sessionID, extension
172173
};
173174

174175
WebRTCClient.prototype._onRejectListener = function(userID, sessionID, extension) {
175-
var session = this.sessions[sessionID];
176+
var that = this,
177+
session = that.sessions[sessionID];
176178

177179
Helpers.trace("onReject. UserID:" + userID + ". SessionID: " + sessionID);
178180

179181
if(session){
180182
var extensionClone = JSON.parse(JSON.stringify(extension));
181-
this._cleanupExtension(extensionClone);
183+
that._cleanupExtension(extensionClone);
182184

183185
if (typeof this.onRejectCallListener === 'function'){
184-
this.onRejectCallListener(session, userID, extensionClone);
186+
Utils.safeCallbackCall(that.onRejectCallListener, session, userID, extensionClone);
185187
}
186188

187189
session.processOnReject(userID, extension);
@@ -195,12 +197,12 @@ WebRTCClient.prototype._onStopListener = function(userID, sessionID, extension)
195197

196198
var session = this.sessions[sessionID],
197199
extensionClone = JSON.parse(JSON.stringify(extension));
198-
200+
199201
if( session && (session.state === WebRTCSession.State.ACTIVE || session.state === WebRTCSession.State.NEW)){
200202
this._cleanupExtension(extensionClone);
201203

202204
if (typeof this.onStopCallListener === 'function'){
203-
this.onStopCallListener(session, userID, extensionClone);
205+
Utils.safeCallbackCall(this.onStopCallListener, session, userID, extensionClone);
204206
}
205207

206208
session.processOnStop(userID, extension);
@@ -231,7 +233,7 @@ WebRTCClient.prototype._onUpdateListener = function(userID, sessionID, extension
231233
Helpers.trace("onUpdate. UserID:" + userID + ". SessionID: " + sessionID + ". Extension: " + JSON.stringify(extension));
232234

233235
if (typeof this.onUpdateCallListener === 'function'){
234-
this.onUpdateCallListener(session, userID, extension);
236+
Utils.safeCallbackCall(this.onUpdateCallListener, session, userID, extension);
235237
}
236238
};
237239

@@ -278,4 +280,4 @@ function getOpponentsIdNASessions(sessions) {
278280
}
279281

280282
return opponents;
281-
}
283+
}

js/modules/webrtc/qbWebRTCHelpers.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
var config = require('../../qbConfig');
7-
var download = require('../../../lib/download/download.min');
87

98
var WebRTCHelpers = {};
109

@@ -77,9 +76,4 @@ WebRTCHelpers.CallType = {
7776
AUDIO: 2
7877
};
7978

80-
/** Download Blob to local file system */
81-
Blob.prototype.download = function() {
82-
download(this, this.name, this.type);
83-
};
84-
8579
module.exports = WebRTCHelpers;

js/modules/webrtc/qbWebRTCSession.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ WebRTCSession.prototype.getUserMedia = function(params, callback) {
8181
/**
8282
* Additional parameters for Media Constraints
8383
* http://tools.ietf.org/html/draft-alvestrand-constraints-resolution-00
84-
*
84+
*
8585
* googEchoCancellation: true
8686
* googAutoGainControl: true
8787
* googNoiseSuppression: true
@@ -125,14 +125,14 @@ WebRTCSession.prototype.attachMediaStream = function(id, stream, options) {
125125
if (elem) {
126126
var URL = window.URL || window.webkitURL;
127127
elem.src = URL.createObjectURL(stream);
128-
128+
129129
if (options && options.muted) elem.muted = true;
130-
130+
131131
if (options && options.mirror) {
132132
elem.style.webkitTransform = 'scaleX(-1)';
133133
elem.style.transform = 'scaleX(-1)';
134134
}
135-
135+
136136
elem.play();
137137
} else {
138138
throw new Error('Unable to attach media stream, element ' + id + ' is undefined');
@@ -169,7 +169,7 @@ WebRTCSession.prototype.detachMediaStream = function(id){
169169
/**
170170
* [Initiate a call]
171171
* @param {object} extension [custom parametrs]
172-
* @param {Function} callback
172+
* @param {Function} callback
173173
*/
174174
WebRTCSession.prototype.call = function(extension, callback) {
175175
var self = this,
@@ -251,7 +251,7 @@ WebRTCSession.prototype.accept = function(extension) {
251251
var offerTime = (self.acceptCallTime - self.startCallTime) / 1000;
252252
self._startWaitingOfferOrAnswerTimer(offerTime);
253253

254-
/**
254+
/**
255255
* here we have to decide to which users the user should call.
256256
* We have a rule: If a userID1 > userID2 then a userID1 should call to userID2.
257257
*/
@@ -452,7 +452,7 @@ WebRTCSession.prototype.processOnCall = function(callerID, extension) {
452452

453453
oppIDs.forEach(function(opID, i, arr) {
454454
var pConn = self.peerConnections[opID];
455-
455+
456456
if(pConn){
457457
if(opID == callerID){
458458
pConn.updateRemoteSDP(extension.sdp);
@@ -509,7 +509,7 @@ WebRTCSession.prototype.processOnReject = function(userID, extension) {
509509
}else{
510510
Helpers.traceError("Ignore 'OnReject', there is no information about peer connection by some reason.");
511511
}
512-
512+
513513
this._closeSessionIfAllConnectionsClosed();
514514
};
515515

@@ -579,7 +579,7 @@ WebRTCSession.prototype.processOnNotAnswer = function(peerConnection) {
579579
peerConnection.release();
580580

581581
if(typeof this.onUserNotAnswerListener === 'function'){
582-
this.onUserNotAnswerListener(this, peerConnection.userID);
582+
Utils.safeCallbackCall(this.onUserNotAnswerListener, this, peerConnection.userID);
583583
}
584584

585585
this._closeSessionIfAllConnectionsClosed();
@@ -590,15 +590,15 @@ WebRTCSession.prototype.processOnNotAnswer = function(peerConnection) {
590590
*/
591591
WebRTCSession.prototype._onRemoteStreamListener = function(userID, stream) {
592592
if (typeof this.onRemoteStreamListener === 'function'){
593-
this.onRemoteStreamListener(this, userID, stream);
593+
Utils.safeCallbackCall(this.onRemoteStreamListener, this, userID, stream);
594594
}
595595
};
596596

597597
WebRTCSession.prototype._onSessionConnectionStateChangedListener = function(userID, connectionState) {
598598
var self = this;
599599

600600
if (typeof self.onSessionConnectionStateChangedListener === 'function'){
601-
self.onSessionConnectionStateChangedListener(self, userID, connectionState);
601+
Utils.safeCallbackCall(self.onSessionConnectionStateChangedListener, self, userID, connectionState);
602602
}
603603
};
604604

@@ -613,7 +613,7 @@ WebRTCSession.prototype._createPeer = function(userID, peerConnectionType) {
613613
/**
614614
* Additional parameters for RTCPeerConnection options
615615
* new RTCPeerConnection(pcConfig, options)
616-
*
616+
*
617617
* DtlsSrtpKeyAgreement: true
618618
* RtpDataChannels: true
619619
*/
@@ -643,7 +643,7 @@ WebRTCSession.prototype._close = function() {
643643
this.state = WebRTCSession.State.CLOSED;
644644

645645
if(typeof this.onSessionCloseListener === 'function'){
646-
this.onSessionCloseListener(this);
646+
Utils.safeCallbackCall(this.onSessionCloseListener, this);
647647
}
648648
};
649649

@@ -775,7 +775,7 @@ WebRTCSession.prototype._uniqueOpponentsIDs = function(){
775775
opponents.push(parseInt(userID));
776776
}
777777
});
778-
778+
779779
return opponents;
780780
};
781781

@@ -788,7 +788,7 @@ WebRTCSession.prototype._uniqueOpponentsIDsWithoutInitiator = function(){
788788
opponents.push(parseInt(userID));
789789
}
790790
});
791-
791+
792792
return opponents;
793793
};
794794

@@ -832,4 +832,4 @@ function _prepareIceServers(iceServers) {
832832
return iceServersCopy;
833833
}
834834

835-
module.exports = WebRTCSession;
835+
module.exports = WebRTCSession;

js/modules/webrtc/qbWebRTCSignalingProcessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* WebRTC Module (WebRTC signaling provider)
44
*/
55

6-
require('../../../lib/strophe/strophe.min');
6+
require('strophe');
77

88
var Helpers = require('./qbWebRTCHelpers');
99
var SignalingConstants = require('./qbWebRTCSignalingConstants');

js/modules/webrtc/qbWebRTCSignalingProvider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* WebRTC Module (WebRTC signaling processor)
44
*/
55

6-
require('../../../lib/strophe/strophe.min');
6+
require('strophe');
77

88
var Helpers = require('./qbWebRTCHelpers');
99
var SignalingConstants = require('./qbWebRTCSignalingConstants');

0 commit comments

Comments
 (0)