Skip to content

Commit 1eb464c

Browse files
author
Igor Khomenko
committed
fixed an issue with double call of _acceptInternal
1 parent d89180e commit 1eb464c

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

js/modules/webrtc/qbRTCPeerConnection.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ RTCPeerConnection.prototype.init = function(delegate, userID, sessionID, type) {
3939
this.sessionID = sessionID;
4040
this.userID = userID;
4141
this.type = type;
42-
this.sdp = null;
42+
this.remoteSDP = null;
4343

4444
this.state = RTCPeerConnection.State.NEW;
4545

@@ -64,7 +64,18 @@ RTCPeerConnection.prototype.release = function(){
6464
if(this.signalingState !== 'closed'){
6565
this.close();
6666
}
67-
}
67+
};
68+
69+
RTCPeerConnection.prototype.updateRemoteSDP = function(newSDP){
70+
if(!newSDP){
71+
throw new Error("sdp string can't be empty.");
72+
}
73+
this.remoteSDP = newSDP;
74+
};
75+
76+
RTCPeerConnection.prototype.getRemoteSDP = function(){
77+
return this.remoteSDP;
78+
};
6879

6980
RTCPeerConnection.prototype.setRemoteSessionDescription = function(type, remoteSessionDescription, callback){
7081
var desc = new RTCSessionDescription({sdp: remoteSessionDescription, type: type});
@@ -110,10 +121,6 @@ RTCPeerConnection.prototype.getAndSetLocalSessionDescription = function(callback
110121
}
111122
};
112123

113-
RTCPeerConnection.prototype.updateSDP = function(newSDP){
114-
this.sdp = newSDP;
115-
}
116-
117124
RTCPeerConnection.prototype.addCandidates = function(iceCandidates) {
118125
var candidate;
119126
for (var i = 0, len = iceCandidates.length; i < len; i++) {

js/modules/webrtc/qbWebRTCSession.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function WebRTCSession(sessionID, initiatorID, opIDs, callType, signalingProvide
7474
*/
7575
WebRTCSession.prototype.getUserMedia = function(params, callback) {
7676
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
77-
77+
7878
if(!getUserMedia) {
7979
throw new Error('getUserMedia() is not supported in your browser');
8080
}
@@ -267,7 +267,7 @@ WebRTCSession.prototype._acceptInternal = function(userID, extension) {
267267
if(peerConnection){
268268
peerConnection.addLocalStream(this.localStream);
269269

270-
peerConnection.setRemoteSessionDescription('offer', peerConnection.sdp, function(error){
270+
peerConnection.setRemoteSessionDescription('offer', peerConnection.getRemoteSDP(), function(error){
271271
if(error){
272272
Helpers.traceError("'setRemoteSessionDescription' error: " + error);
273273
}else{
@@ -314,7 +314,7 @@ WebRTCSession.prototype.reject = function(extension) {
314314
ext["opponentsIDs"] = self.opponentsIDs;
315315

316316
var peersLen = Object.keys(self.peerConnections).length;
317-
317+
318318
if(peersLen > 0){
319319
for (var key in self.peerConnections) {
320320
var peerConnection = self.peerConnections[key];
@@ -449,17 +449,19 @@ WebRTCSession.prototype.processOnCall = function(callerID, extension) {
449449
this._clearWaitingOfferOrAnswerTimer();
450450

451451
var oppIDs = this._uniqueOpponentsIDs();
452-
oppIDs.forEach(function(opID, i, arr) {
452+
oppIDs.forEach(function(opID, i, arr) {
453453

454454
var peerConnection = self.peerConnections[opID];
455455
if(peerConnection){
456-
peerConnection.updateSDP(extension.sdp);
456+
if(opID == callerID){
457+
peerConnection.updateRemoteSDP(extension.sdp);
457458

458-
// The group call logic starts here
459-
if(callerID != self.initiatorID && self.state === WebRTCSession.State.ACTIVE){
460-
self._acceptInternal(callerID, {});
461-
}
459+
// The group call logic starts here
460+
if(callerID != self.initiatorID && self.state === WebRTCSession.State.ACTIVE){
461+
self._acceptInternal(callerID, {});
462+
}
462463

464+
}
463465
} else {
464466
// create peer connections for each opponent
465467
var peerConnection;
@@ -468,14 +470,16 @@ WebRTCSession.prototype.processOnCall = function(callerID, extension) {
468470
}else{
469471
peerConnection = self._createPeer(opID, 'answer');
470472
}
473+
471474
self.peerConnections[opID] = peerConnection;
472475

473476
if(opID == callerID){
474-
peerConnection.updateSDP(extension.sdp);
477+
peerConnection.updateRemoteSDP(extension.sdp);
475478
self._startAnswerTimer();
476479
}
477480
}
478481
});
482+
479483
};
480484

481485
WebRTCSession.prototype.processOnAccept = function(userID, extension) {

quickblox.min.js

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

samples/webrtc/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ <h4>Call from <strong class="j-ic_initiator"></strong></h4>
201201
</li>
202202
</script>
203203

204-
204+
205205
<script type="text/template" id="accept_call">
206206
<% _.each(users, function(el, i, list) { %>
207207
<% if(list.length === 1){ %>
@@ -213,7 +213,7 @@ <h4>Call from <strong class="j-ic_initiator"></strong></h4>
213213
<b><%= el.full_name %></b>,
214214
<% } %>
215215
<% } %>
216-
<% }); %>
216+
<% }); %>
217217
</script>
218218

219219
<script type="text/template" id="login_tpl">
@@ -253,7 +253,7 @@ <h4>Call from <strong class="j-ic_initiator"></strong></h4>
253253
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
254254
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
255255

256-
<script src="../../quickblox.min.js"></script>
256+
<script src="../../quickblox.js"></script>
257257

258258
<script src="config.js"></script>
259259
<script src="app.js"></script>

0 commit comments

Comments
 (0)