Skip to content

Commit f188476

Browse files
committed
Fix bugs for Sprint 1
* fixed grammar error * QBWEBSDK-290 * up tests (set custom interval to all async. methods) * upd dataSpec also * QBWEBSDK-276 * QBWEBSDK-270 * change to enum
1 parent 0a7008f commit f188476

File tree

11 files changed

+641
-560
lines changed

11 files changed

+641
-560
lines changed

samples/webrtc/index.html

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
<header class="header">
2121
<div class="inner">
2222
<div class="header__logo">
23-
<img class="header__logo_img" src="images/Logo_qb.svg">
24-
</img>
23+
<img class="header__logo_img" src="images/Logo_qb.svg"></img>
2524
</div>
2625

2726
<h2 class="header__title">JavaScript WebRTC Sample</h2>
@@ -34,8 +33,10 @@ <h2 class="header__title">JavaScript WebRTC Sample</h2>
3433
<form class="join j-join">
3534
<h3 class="join__title">
3635
<p>Please enter your username and chat room name.</p>
37-
<p>You can join existed chat room.</p>
38-
<p class="join__notice">Use several browsers to simulate several users.</p>
36+
<p>You can join existent chat room.</p>
37+
<p class="join__notice">
38+
Use several browsers to simulate several users.
39+
</p>
3940
</h3>
4041

4142
<div class="join__body">
@@ -316,9 +317,15 @@ <h4 class="caller__name">
316317
<script type="text/template" id="callee_video">
317318
<div class="frames_callee callees__callee j-callee">
318319
<div class="frames_callee__inner">
319-
<p class="frames_callee__status j-callee_status_<%=userID%>">Connecting</p>
320+
<p class="frames_callee__status j-callee_status_<%=userID%>">
321+
<%=state%>
322+
</p>
323+
320324
<div class="qb-video">
321-
<video class="j-callees__callee__video qb-video_source" id="remote_video_<%=userID%>" data-user="<%=userID%>"></video>
325+
<video class="j-callees__callee__video qb-video_source"
326+
id="remote_video_<%=userID%>"
327+
data-user="<%=userID%>">
328+
</video>
322329
</div>
323330
</div>
324331

samples/webrtc/js/app.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
;(function(window, QB, app, CONFIG, $, Backbone) {
22
'use strict';
33

4-
/** INIT QB */
54
$(function() {
5+
var peerConnList = QB.webrtc.PeerConnectionState;
6+
67
var sounds = {
78
'call': 'callingSignal',
89
'end': 'endCallSignal',
@@ -30,7 +31,7 @@
3031
resolve(res.users);
3132
}, function(error) {
3233
cb($occupantsCont, error.message);
33-
reject(null);
34+
reject('Not found users by tag');
3435
});
3536
});
3637
}
@@ -69,6 +70,11 @@
6970
return;
7071
}
7172

73+
if (!_.isEmpty(app.caller)) {
74+
app.router.navigate('dashboard');
75+
return false;
76+
}
77+
7278
this.container
7379
.removeClass('page-dashboard')
7480
.addClass('page-join');
@@ -82,7 +88,7 @@
8288
app.videoMain = 0;
8389
},
8490
'dashboard': function() {
85-
if (_.isEmpty(app.caller)) {
91+
if(_.isEmpty(app.caller)) {
8692
app.router.navigate('join', { 'trigger': true });
8793
return false;
8894
}
@@ -109,6 +115,8 @@
109115
$('.j-users_wrap').append( $('#users_tpl').html() );
110116
ui.insertOccupants().then(function(users) {
111117
app.users = users;
118+
}, function(err) {
119+
console.warn(err);
112120
});
113121

114122
/** render frames */
@@ -326,7 +334,11 @@
326334
document.getElementById(sounds.call).play();
327335

328336
Object.keys(app.callees).forEach(function(id, i, arr) {
329-
videoElems += compiled({userID: id, name: app.callees[id] });
337+
videoElems += compiled({
338+
'userID': id,
339+
'name': app.callees[id],
340+
'state': 'connecting'
341+
});
330342
});
331343

332344
$('.j-callees').append(videoElems);
@@ -407,10 +419,14 @@
407419
userInfo = _.findWhere(app.users, {'id': +userID});
408420

409421
if( (document.getElementById('remote_video_' + userID) === null) ) {
410-
videoElems += compiled({userID: userID, name: userInfo.full_name});
422+
videoElems += compiled({
423+
'userID': userID,
424+
'name': userInfo.full_name,
425+
'state': app.helpers.getConStateName(peerState)
426+
});
411427

412428
if(peerState === QB.webrtc.PeerConnectionState.CLOSED){
413-
app.helpers.toggleRemoteVideoView( userID, 'clear');
429+
app.helpers.toggleRemoteVideoView(userID, 'clear');
414430
}
415431
}
416432
});
@@ -650,7 +666,6 @@
650666
}
651667
});
652668
} else {
653-
654669
$('.j-callee_status_' + userId).text('Rejected');
655670
}
656671
};
@@ -697,6 +712,12 @@
697712
console.log('Session: ', session);
698713
console.groupEnd();
699714

715+
var state = app.currentSession.connectionStateForUser(userId);
716+
717+
if(state === peerConnList.DISCONNECTED || state === peerConnList.FAILED || state === peerConnList.CLOSED) {
718+
return false;
719+
}
720+
700721
app.currentSession.peerConnections[userId].stream = stream;
701722
app.currentSession.attachMediaStream('remote_video_' + userId, stream);
702723

samples/webrtc/js/helpers.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@
7272
.addClass( filterName );
7373
};
7474

75+
app.helpers.getConStateName = function(num) {
76+
var answ;
77+
78+
switch (num) {
79+
case QB.webrtc.PeerConnectionState.DISCONNECTED:
80+
case QB.webrtc.PeerConnectionState.FAILED:
81+
case QB.webrtc.PeerConnectionState.CLOSED:
82+
answ = 'DISCONNECTED';
83+
break;
84+
default:
85+
answ = 'CONNECTING';
86+
}
87+
88+
return answ;
89+
};
90+
7591
app.helpers.toggleRemoteVideoView = function(userId, action) {
7692
var $video = $('#remote_video_' + userId);
7793

samples/webrtc/styles.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ b {
5656
top: 0; bottom: 0;
5757
left: 0; right: 0;
5858
max-width: 100%;
59+
max-height: 100%;
60+
margin: auto;
5961
}
6062

6163
.qb-error {

spec/QB-ChatSpec.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ describe('Chat API', function() {
22
'use strict';
33

44
var LOGIN_TIMEOUT = 10000;
5-
var MESSAGING_TIMEOUT = 1500;
5+
var MESSAGING_TIMEOUT = 3000;
66
var IQ_TIMEOUT = 1000;
77
var REST_REQUESTS_TIMEOUT = 3000;
88

@@ -26,7 +26,7 @@ describe('Chat API', function() {
2626
'userId': QBUser1.id,
2727
'password': QBUser1.password
2828
}, function(err, roster) {
29-
if(err){ done.fail("Chat login error: ", err); }
29+
if(err){ done.fail('Chat login error: ' + JSON.stringify(err)); }
3030

3131
expect(roster).not.toBeNull();
3232
done();
@@ -40,11 +40,11 @@ describe('Chat API', function() {
4040

4141
QB.chat.onMessageListener = function(userId, receivedMessage){
4242
expect(receivedMessage).not.toBeNull();
43-
expect(receivedMessage.type).toEqual("chat");
43+
expect(receivedMessage.type).toEqual('chat');
4444
expect(userId).toEqual(QBUser1.id);
4545
expect(receivedMessage.extension).toEqual({
46-
param1: "value1",
47-
param2: "value2"
46+
param1: 'value1',
47+
param2: 'value2'
4848
});
4949
expect(receivedMessage.id).toEqual(self.messageId);
5050
expect(receivedMessage.markable).toEqual(1);
@@ -54,10 +54,10 @@ describe('Chat API', function() {
5454
};
5555

5656
var message = {
57-
type: "chat",
57+
type: 'chat',
5858
extension: {
59-
param1: "value1",
60-
param2: "value2"
59+
param1: 'value1',
60+
param2: 'value2'
6161
},
6262
markable: 1
6363
};

spec/QB-CoreSpec.js

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,51 @@
11
describe('Session API', function() {
2-
'use strict';
2+
'use strict';
33

4-
var REST_REQUESTS_TIMEOUT = 3000;
4+
var REST_REQUESTS_TIMEOUT = 10000;
55

6-
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
7-
var request = isNodeEnv ? require('request') : {};
6+
var isNodeEnv = typeof window === 'undefined' && typeof exports === 'object';
87

9-
var QB = isNodeEnv ? require('../src/qbMain') : window.QB;
10-
var CREDENTIALS = isNodeEnv ? require('./config').CREDS : window.CREDS;
11-
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
12-
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
8+
var QB = isNodeEnv ? require('../src/qbMain') : window.QB;
139

14-
/**
15-
* TEST CASES
16-
*/
17-
it('can init SDK with session token and appId', function(){
18-
QB.init('56655ac9a0eb476d92002b66', CREDENTIALS.appId);
10+
var CREDS = isNodeEnv ? require('./config').CREDS : window.CREDS;
11+
var CONFIG = isNodeEnv ? require('./config').CONFIG : window.CONFIG;
12+
var QBUser1 = isNodeEnv ? require('./config').QBUser1 : window.QBUser1;
1913

20-
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDENTIALS.appId);
21-
});
22-
23-
it('can init SDK with appId, authKey, authSecret, config', function(){
24-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CONFIG);
14+
it('can init SDK with session token and appId', function(){
15+
QB.init('56655ac9a0eb476d92002b66', CREDS.appId);
2516

26-
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDENTIALS.appId);
27-
expect(QB.service.qbInst.config.creds.authKey).toEqual(CREDENTIALS.authKey);
28-
expect(QB.service.qbInst.config.creds.authSecret).toEqual(CREDENTIALS.authSecret);
29-
expect(QB.service.qbInst.config.debug).toEqual(CONFIG.debug);
30-
});
17+
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDS.appId);
18+
});
3119

32-
it('can create a session', function(done){
33-
QB.createSession(function (err, session){
34-
if(err){
35-
done.fail("Create a session error: " + JSON.stringify(err));
36-
}else{
37-
expect(session).not.toBeNull();
38-
expect(session.application_id).toEqual(CREDENTIALS.appId);
20+
it('can init SDK with appId, authKey, authSecret, config', function(){
21+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CONFIG);
3922

40-
done();
41-
}
23+
expect(QB.service.qbInst.config.creds.appId).toEqual(CREDS.appId);
24+
expect(QB.service.qbInst.config.creds.authKey).toEqual(CREDS.authKey);
25+
expect(QB.service.qbInst.config.creds.authSecret).toEqual(CREDS.authSecret);
26+
expect(QB.service.qbInst.config.debug).toEqual(CONFIG.debug);
4227
});
43-
}, REST_REQUESTS_TIMEOUT);
28+
29+
it('can create a session', function(done){
30+
QB.createSession(function (err, session){
31+
if(err){
32+
done.fail('Create a session error: ' + JSON.stringify(err));
33+
}else{
34+
expect(session).not.toBeNull();
35+
expect(session.application_id).toEqual(CREDS.appId);
36+
37+
done();
38+
}
39+
});
40+
}, REST_REQUESTS_TIMEOUT);
4441

4542
it('can create a User session', function(done){
4643
QB.createSession(QBUser1, function (err, session){
4744
if(err){
4845
done.fail("Create a User session error: " + JSON.stringify(err));
4946
}else{
5047
expect(session).not.toBeNull();
51-
expect(session.application_id).toEqual(CREDENTIALS.appId);
48+
expect(session.application_id).toEqual(CREDS.appId);
5249
expect(session.user_id).toEqual(QBUser1.id);
5350

5451
done();
@@ -108,7 +105,7 @@ describe('Session API', function() {
108105
}
109106
};
110107

111-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CUSTOMCONFIG);
108+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CUSTOMCONFIG);
112109

113110
expect(QB.service.qbInst.config.endpoints.api).toEqual('apicustomdomain.quickblox.com');
114111
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chatcustomdomain.quickblox.com');
@@ -124,7 +121,7 @@ describe('Session API', function() {
124121
}
125122
};
126123

127-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, CUSTOMCONFIG2);
124+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, CUSTOMCONFIG2);
128125

129126
expect(QB.service.qbInst.config.endpoints.api).toEqual('apicustomdomain2.quickblox.com');
130127
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chatcustomdomain2.quickblox.com');
@@ -140,7 +137,7 @@ describe('Session API', function() {
140137
}
141138
};
142139

143-
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret, DEFAULTCONFIG);
140+
QB.init(CREDS.appId, CREDS.authKey, CREDS.authSecret, DEFAULTCONFIG);
144141

145142
expect(QB.service.qbInst.config.endpoints.api).toEqual('api.quickblox.com');
146143
expect(QB.service.qbInst.config.endpoints.chat).toEqual('chat.quickblox.com');

0 commit comments

Comments
 (0)