Skip to content

Commit 2fefcc4

Browse files
author
Igor Khomenko
committed
Merge pull request #105 from QuickBlox/develop.sf.260116
Added more TURN servers; Wrap WebRTC callbacks into 'safeCallbackCall'; added Travic integration
2 parents 6048dc7 + 4301dc6 commit 2fefcc4

File tree

10 files changed

+94
-52
lines changed

10 files changed

+94
-52
lines changed

.travis.yml

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

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# QuickBlox JavaScript SDK
22

3+
[![npm](https://img.shields.io/npm/v/quickblox.svg)]()
4+
[![npm](https://img.shields.io/npm/dm/quickblox.svg)]()
5+
36
The QuickBlox JavaScript SDK provides a JavaScript library making it even
47
easier to access the QuickBlox cloud communication backend platform.
58

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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/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/qbConfig.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ var config = {
4444
'url': 'turn:turn.quickblox.com:3478?transport=tcp',
4545
'username': 'quickblox',
4646
'credential': 'baccb97ba2d92d71e26eb9886da5f1e0'
47+
},
48+
{
49+
'url': 'turn:turnsingapor.quickblox.com:3478?transport=udp',
50+
'username': 'quickblox',
51+
'credential': 'baccb97ba2d92d71e26eb9886da5f1e0'
52+
},
53+
{
54+
'url': 'turn:turnsingapore.quickblox.com:3478?transport=tcp',
55+
'username': 'quickblox',
56+
'credential': 'baccb97ba2d92d71e26eb9886da5f1e0'
57+
},
58+
{
59+
'url': 'turn:turnireland.quickblox.com:3478?transport=udp',
60+
'username': 'quickblox',
61+
'credential': 'baccb97ba2d92d71e26eb9886da5f1e0'
62+
},
63+
{
64+
'url': 'turn:turnireland.quickblox.com:3478?transport=tcp',
65+
'username': 'quickblox',
66+
'credential': 'baccb97ba2d92d71e26eb9886da5f1e0'
4767
}
4868
]
4969
},

js/qbMain.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ QuickBlox.prototype = {
3030
Content = require('./modules/qbContent'),
3131
Location = require('./modules/qbLocation'),
3232
PushNotifications = require('./modules/qbPushNotifications'),
33-
Data = require('./modules/qbData');
33+
Data = require('./modules/qbData'),
34+
conn;
3435

3536
if (isBrowser) {
3637
/** create Strophe Connection object */
3738
var Connection = require('./qbStrophe');
38-
var conn = new Connection();
39+
conn = new Connection();
3940

4041
/** add WebRTC API if API is avaible */
4142
if( Utils.isWebRTCAvailble() ) {

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@
7070
},
7171
"config": {
7272
"ghooks": {
73-
"pre-commit": "jasmine"
73+
"pre-push": "jasmine"
7474
}
75+
},
76+
"scripts": {
77+
"build": "npm install -g jasmine && npm install -g grunt && grunt",
78+
"test": "jasmine"
7579
}
7680
}

quickblox.min.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)