Skip to content

Commit 508e4bf

Browse files
author
dimaspirit
committed
issues/29 & QBWEBSDK-168
FOR NOTE: We recomend use Function Declaration that SDK could identify what function(listener) has error
1 parent e8a69c6 commit 508e4bf

File tree

4 files changed

+54
-48
lines changed

4 files changed

+54
-48
lines changed

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;

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.

samples/webrtc/js/app.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,15 @@
441441
});
442442

443443
/**
444-
* QB Event listener:
445-
* chat:
444+
* QB Event listener.
445+
*
446+
* [Recommendation]
447+
* We recomend use Function Declaration
448+
* that SDK could identify what function(listener) has error
449+
*
450+
* Chat:
446451
* - onDisconnectedListener
447-
* webrtc:
452+
* WebRTC:
448453
* - onSessionCloseListener
449454
* - onUserNotAnswerListener
450455
* - onUpdateCallListener
@@ -475,7 +480,7 @@
475480
authorizationing = false;
476481
};
477482

478-
QB.webrtc.onSessionCloseListener = function(session){
483+
QB.webrtc.onSessionCloseListener = function onSessionCloseListener(session){
479484
console.log('onSessionCloseListener: ' + session);
480485

481486
/** pause play call sound */
@@ -507,7 +512,7 @@
507512
remoteStreamCounter = 0;
508513
};
509514

510-
QB.webrtc.onUserNotAnswerListener = function(session, userId) {
515+
QB.webrtc.onUserNotAnswerListener = function onUserNotAnswerListener(session, userId) {
511516
console.group('onUserNotAnswerListener.');
512517
console.log('UserId: ' + userId);
513518
console.log('Session: ' + session);
@@ -528,11 +533,10 @@
528533
);
529534
}
530535

531-
/** It's for groups call */
532536
$('.j-callee_status_' + userId).text('No Answer');
533537
};
534538

535-
QB.webrtc.onUpdateCallListener = function(session, userId, extension) {
539+
QB.webrtc.onUpdateCallListener = function onUpdateCallListener(session, userId, extension) {
536540
console.group('onUpdateCallListener.');
537541
console.log('UserId: ' + userId);
538542
console.log('Session: ' + session);
@@ -545,7 +549,7 @@
545549
}
546550
};
547551

548-
QB.webrtc.onCallListener = function(session, extension) {
552+
QB.webrtc.onCallListener = function onCallListener(session, extension) {
549553
console.group('onCallListener.');
550554
console.log('Session: ' + session);
551555
console.log('Extension: ' + JSON.stringify(extension));
@@ -566,7 +570,7 @@
566570
document.getElementById(ui.sounds.rington).play();
567571
};
568572

569-
QB.webrtc.onAcceptCallListener = function(session, userId, extension) {
573+
QB.webrtc.onAcceptCallListener = function onAcceptCallListener(session, userId, extension) {
570574
console.group('onAcceptCallListener.');
571575
console.log('UserId: ' + userId);
572576
console.log('Session: ' + session);
@@ -588,7 +592,7 @@
588592
}
589593
};
590594

591-
QB.webrtc.onRejectCallListener = function(session, userId, extension) {
595+
QB.webrtc.onRejectCallListener = function onRejectCallListener(session, userId, extension) {
592596
console.group('onRejectCallListener.');
593597
console.log('UserId: ' + userId);
594598
console.log('Session: ' + session);
@@ -614,7 +618,7 @@
614618
$('.j-callee_status_' + userId).text('Rejected');
615619
};
616620

617-
QB.webrtc.onStopCallListener = function(session, userId, extension) {
621+
QB.webrtc.onStopCallListener = function onStopCallListener(session, userId, extension) {
618622
console.group('onStopCallListener.');
619623
console.log('UserId: ' + userId);
620624
console.log('Session: ' + session);
@@ -641,7 +645,7 @@
641645
$('.j-callee_status_' + userId).text('Hung Up');
642646
};
643647

644-
QB.webrtc.onRemoteStreamListener = function(session, userID, stream) {
648+
QB.webrtc.onRemoteStreamListener = function onRemoteStreamListener(session, userID, stream) {
645649
console.group('onRemoteStreamListener.');
646650
console.log('userID: ' + userID);
647651
console.log('Session: ' + session);
@@ -662,7 +666,7 @@
662666
}
663667
};
664668

665-
QB.webrtc.onSessionConnectionStateChangedListener = function(session, userID, connectionState) {
669+
QB.webrtc.onSessionConnectionStateChangedListener = function onSessionConnectionStateChangedListener(session, userID, connectionState) {
666670
console.group('onSessionConnectionStateChangedListener.');
667671
console.log('UserID: ' + userID);
668672
console.log('Session: ' + session);

0 commit comments

Comments
 (0)