Skip to content

Commit 9f36691

Browse files
author
Igor Khomenko
committed
Merge pull request #92 from QuickBlox/develop.webrtc.bf.16122015
bug fixing from 16122015
2 parents c90bac7 + de864c5 commit 9f36691

File tree

8 files changed

+132
-47
lines changed

8 files changed

+132
-47
lines changed

js/modules/webrtc/qbWebRTCClient.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ WebRTCClient.prototype._onCallListener = function(userID, sessionID, extension)
135135
this.signalingProvider.sendMessage(userID, extension, SignalingConstants.SignalingType.REJECT);
136136
} else {
137137
var session = this.sessions[sessionID];
138+
138139
if(!session){
139140
session = this._createAndStoreSession(sessionID, extension.callerID, extension.opponentsIDs, extension.callType);
140141

@@ -155,14 +156,18 @@ WebRTCClient.prototype._onAcceptListener = function(userID, sessionID, extension
155156
var session = this.sessions[sessionID];
156157

157158
if(session){
158-
var extensionClone = JSON.parse(JSON.stringify(extension));
159-
this._cleanupExtension(extensionClone);
159+
if(session.state === WebRTCSession.State.ACTIVE ) {
160+
var extensionClone = JSON.parse(JSON.stringify(extension));
161+
this._cleanupExtension(extensionClone);
160162

161-
if (typeof this.onAcceptCallListener === 'function'){
162-
this.onAcceptCallListener(session, userID, extensionClone);
163-
}
163+
if (typeof this.onAcceptCallListener === 'function'){
164+
this.onAcceptCallListener(session, userID, extensionClone);
165+
}
164166

165-
session.processOnAccept(userID, extension);
167+
session.processOnAccept(userID, extension);
168+
} else {
169+
Helpers.traceWarning("Ignore 'onAccept', the session( " + sessionID + " ) has invalid state.");
170+
}
166171
}else{
167172
Helpers.traceError("Ignore 'onAccept', there is no information about session " + sessionID + " by some reason.");
168173
}
@@ -212,7 +217,11 @@ WebRTCClient.prototype._onIceCandidatesListener = function(userID, sessionID, ex
212217
var session = this.sessions[sessionID];
213218

214219
if(session){
215-
session.processOnIceCandidates(userID, extension);
220+
if(session.state === WebRTCSession.State.ACTIVE) {
221+
session.processOnIceCandidates(userID, extension);
222+
} else {
223+
Helpers.traceWarning('Ignore \'OnIceCandidates\', the session ( ' + sessionID + ' ) has invalid state.');
224+
}
216225
}else{
217226
Helpers.traceError("Ignore 'OnIceCandidates', there is no information about session " + sessionID + " by some reason.");
218227
}

js/modules/webrtc/qbWebRTCHelpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ WebRTCHelpers = {
2828
}
2929
},
3030

31+
traceWarning: function(text) {
32+
if (config.debug) {
33+
console.warn('[QBWebRTC]:', text);
34+
}
35+
},
36+
3137
traceError: function(text) {
3238
if (config.debug) {
3339
console.error('[QBWebRTC]:', text);

js/modules/webrtc/qbWebRTCSession.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ WebRTCSession.prototype.connectionStateForUser = function(userID){
153153

154154
/**
155155
* Detach media stream from audio/video element
156-
* @param {string} The Id of an ellement to detach a stream
156+
* @param {string} The Id of an element to detach a stream
157157
*/
158158
WebRTCSession.prototype.detachMediaStream = function(id){
159159
var elem = document.getElementById(id);
@@ -444,17 +444,17 @@ WebRTCSession.filter = function(id, filters) {
444444
//
445445

446446
WebRTCSession.prototype.processOnCall = function(callerID, extension) {
447-
var self = this;
447+
var self = this,
448+
oppIDs = self._uniqueOpponentsIDs();
448449

449-
this._clearWaitingOfferOrAnswerTimer();
450+
self._clearWaitingOfferOrAnswerTimer();
450451

451-
var oppIDs = this._uniqueOpponentsIDs();
452-
oppIDs.forEach(function(opID, i, arr) {
453-
454-
var peerConnection = self.peerConnections[opID];
455-
if(peerConnection){
452+
oppIDs.forEach(function(opID, i, arr) {
453+
var pConn = self.peerConnections[opID];
454+
455+
if(pConn){
456456
if(opID == callerID){
457-
peerConnection.updateRemoteSDP(extension.sdp);
457+
pConn.updateRemoteSDP(extension.sdp);
458458

459459
// The group call logic starts here
460460
if(callerID != self.initiatorID && self.state === WebRTCSession.State.ACTIVE){
@@ -479,7 +479,6 @@ WebRTCSession.prototype.processOnCall = function(callerID, extension) {
479479
}
480480
}
481481
});
482-
483482
};
484483

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

js/qbStrophe.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ var Utils = require('./qbUtils');
1212
function Connection() {
1313
var protocol = config.chatProtocol.active === 1 ? config.chatProtocol.bosh : config.chatProtocol.websocket;
1414
var conn = new Strophe.Connection(protocol);
15+
1516
if (config.chatProtocol.active === 1) {
16-
conn.xmlInput = function(data) { if (data.childNodes[0]) {for (var i = 0, len = data.childNodes.length; i < len; i++) {
17-
Utils.QBLog('[QBChat]', 'RECV:', data.childNodes[i]);
18-
}} };
19-
conn.xmlOutput = function(data) { if (data.childNodes[0]) {for (var i = 0, len = data.childNodes.length; i < len; i++) {
20-
Utils.QBLog('[QBChat]', 'SENT:', data.childNodes[i]);
21-
}} };
17+
conn.xmlInput = function(data) {
18+
if (data.childNodes[0]) {
19+
for (var i = 0, len = data.childNodes.length; i < len; i++) {
20+
Utils.QBLog('[QBChat]', 'RECV:', data.childNodes[i]);
21+
}
22+
}
23+
};
24+
conn.xmlOutput = function(data) {
25+
if (data.childNodes[0]) {
26+
for (var i = 0, len = data.childNodes.length; i < len; i++) {
27+
Utils.QBLog('[QBChat]', 'SENT:', data.childNodes[i]);
28+
}
29+
}
30+
};
2231
} else {
2332
conn.xmlInput = function(data) {
2433
Utils.QBLog('[QBChat]', 'RECV:', data);

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/app.js

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@
132132
ui.createUsers(QBUsers, ui.$usersList);
133133
ui.$usersTitle.text(MESSAGES.title_login);
134134

135-
if(!params.withoutUpdMsg) {
136-
ui.updateMsg({msg: 'login'});
135+
if(!params.withoutUpdMsg || params.msg) {
136+
ui.updateMsg({msg: params.msg});
137137
}
138138
}
139139

@@ -142,15 +142,15 @@
142142
*/
143143
ui.setPositionFooter();
144144

145-
initializeUI();
145+
initializeUI({withoutUpdMsg: false, msg: 'login'});
146146

147147
QB.init(QBApp.appId, QBApp.authKey, QBApp.authSecret, CONFIG);
148148

149149
/**
150150
* EVENTS
151151
*/
152-
/** Choose caller */
153-
$(document).on('click', '.j-user', function() {
152+
/** Choose caller or callees */
153+
$(document).on('click', '.j-user', function(e) {
154154
var $el = $(this),
155155
usersWithoutCaller = [],
156156
user = {},
@@ -184,9 +184,6 @@
184184
if(err !== null) {
185185
app.caller = {};
186186

187-
ui.updateMsg( {msg: 'connect_error'} );
188-
189-
initializeUI({withoutUpdMsg: true});
190187
ui.setPositionFooter();
191188
ui.togglePreloadMain('hide');
192189
} else {
@@ -247,8 +244,9 @@
247244
app.currentSession = QB.webrtc.createNewSession(Object.keys(app.callees), QB.webrtc.CallType.VIDEO);
248245

249246
app.currentSession.getUserMedia(mediaParams, function(err, stream) {
250-
if (err) {
247+
if (err || !stream.getAudioTracks().length || !stream.getVideoTracks().length) {
251248
ui.updateMsg({msg: 'device_not_found', obj: {name: app.caller.full_name}});
249+
app.currentSession.stop({});
252250
} else {
253251
app.currentSession.call({}, function(error) {
254252
if(error) {
@@ -333,6 +331,7 @@
333331
});
334332

335333
ui.$callees.append(videoElems);
334+
ui.setPositionFooter();
336335
ui.updateMsg( {msg: 'during_call', obj: {name: app.caller.full_name}} );
337336

338337
app.currentSession.accept({});
@@ -375,7 +374,7 @@
375374
classesName = [],
376375
activeClass = [];
377376

378-
if( app.currentSession.peerConnections[userID].stream ) {
377+
if( app.currentSession.peerConnections[userID].stream && !_.isEmpty( $that.attr('src')) ) {
379378
if( $that.hasClass('active') ) {
380379
$that.removeClass('active');
381380

@@ -436,8 +435,7 @@
436435
*/
437436
QB.chat.onDisconnectedListener = function() {
438437
console.log('onDisconnectedListener.');
439-
440-
var initUIParams = authorizationing ? {withoutUpdMsg: true} : {};
438+
var initUIParams = authorizationing ? {withoutUpdMsg: false, msg: 'no_internet'} : {withoutUpdMsg: false, msg: 'login'};
441439

442440
app.caller = {};
443441
app.callees = [];
@@ -452,7 +450,6 @@
452450
$('.j-callee').remove();
453451

454452
ui.setPositionFooter();
455-
456453
authorizationing = false;
457454
};
458455

@@ -465,7 +462,9 @@
465462

466463
ui.showCallBtn();
467464

468-
ui.updateMsg({msg: 'call_stop', obj: {name: app.caller.full_name}});
465+
if(session.opponentsIDs.length > 1) {
466+
ui.updateMsg({msg: 'call_stop', obj: {name: app.caller.full_name}});
467+
}
469468

470469
/** delete blob from myself video */
471470
document.getElementById('localVideo').src = '';
@@ -487,6 +486,20 @@
487486
console.log('Session: ' + session);
488487
console.groupEnd();
489488

489+
var userInfo = _.findWhere(QBUsers, {id: +userId});
490+
491+
/** It's for p2p call */
492+
if(session.opponentsIDs.length === 1) {
493+
ui.updateMsg({
494+
msg: 'p2p_call_stop',
495+
obj: {
496+
name: userInfo.full_name,
497+
reason: 'not answered'
498+
}
499+
});
500+
}
501+
502+
/** It's for groups call */
490503
$('.j-callee_status_' + userId).text('No Answer');
491504
};
492505

@@ -553,6 +566,20 @@
553566
console.log('Extension: ' + JSON.stringify(extension));
554567
console.groupEnd();
555568

569+
var userInfo = _.findWhere(QBUsers, {id: userId});
570+
571+
/** It's for p2p call */
572+
if(session.opponentsIDs.length === 1) {
573+
ui.updateMsg({
574+
msg: 'p2p_call_stop',
575+
obj: {
576+
name: userInfo.full_name,
577+
reason: 'rejected the call'
578+
}
579+
});
580+
}
581+
582+
/** It's for groups call */
556583
$('.j-callee_status_' + userId).text('Rejected');
557584
};
558585

@@ -563,6 +590,20 @@
563590
console.log('Extension: ' + JSON.stringify(extension));
564591
console.groupEnd();
565592

593+
var userInfo = _.findWhere(QBUsers, {id: userId});
594+
595+
/** It's for p2p call */
596+
if(session.opponentsIDs.length === 1) {
597+
ui.updateMsg({
598+
msg: 'p2p_call_stop',
599+
obj: {
600+
name: userInfo.full_name,
601+
reason: 'hung up the call'
602+
}
603+
});
604+
}
605+
606+
/** It's for groups call */
566607
$('.j-callee_status_' + userId).text('Hung Up');
567608
};
568609

@@ -624,6 +665,10 @@
624665

625666
if(app.mainVideo === userID) {
626667
$('#remote_video_' + userID).removeClass('active');
668+
669+
ui.changeFilter('#main_video', 'no');
670+
app.currentSession.detachMediaStream('main_video');
671+
app.mainVideo = 0;
627672
}
628673

629674
if( !_.isEmpty(app.currentSession) ) {

samples/webrtc/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ <h4>Call from <strong class="j-ic_initiator"></strong></h4>
248248
<button class='fw-link j-logout'>Logout</button>
249249
</script>
250250

251+
<script type="text/template" id="p2p_call_stop">
252+
<%=name%> has <%=reason%>. Call is stopped.&emsp;
253+
Login&nbsp;in&nbsp;as&nbsp;<%=name%>
254+
<button class='fw-link j-logout'>Logout</button>
255+
</script>
256+
251257
<!-- SCRIPT -->
252258
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
253259
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

samples/webrtc/styles.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ body {
6666

6767
.fw-video {
6868
display: block;
69-
width: 100%;
70-
min-height: 100px;
69+
width: 135px;
70+
height: 100px;
71+
max-height: 100px;
7172

7273
background: #bfbfbf;
7374
}
7475
.fw-video-wait {
7576
min-width: 32px;
7677
background: #bfbfbf url('images/loader3.gif') no-repeat center;
7778
}
79+
.fw-video.main_video_vid {
80+
width: 100%;
81+
height: auto;
82+
max-height: none;
83+
}
7884

7985
.fw-inner {
8086
width: 90%;
@@ -479,6 +485,7 @@ body {
479485
}
480486

481487
.callees__callee_video {
488+
margin: 0 auto;
482489
border: 4px solid transparent;
483490

484491
transition: border-color .3s ease;
@@ -500,6 +507,10 @@ body {
500507
z-index: 9;
501508
}
502509

510+
.callees__callee_name {
511+
text-align: center;
512+
}
513+
503514
@media all and (min-width: 780px) {
504515
.callees__callee {
505516
width: 20%;

0 commit comments

Comments
 (0)