Skip to content

Fix bugs for sprint 1 #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions quickblox.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/webrtc/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'login': 'Login as any user on this computer and another user on another computer.',
'create_session': 'Creating a session...',
'connect': 'Connecting...',
'connect_error': 'Something wrong with connect to chat. Check internet connection or user info and trying again.',
'connect_error': 'Something went wrong with the connection. Check internet connection or user info and try again.',
'login_as': 'Logged in as ',
'title_login': 'Choose a user to login with:',
'title_callee': 'Choose users to call:',
Expand Down
21 changes: 20 additions & 1 deletion samples/webrtc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ <h4>
</div>

<!-- MODALS -->
<div class="modal fade" id="connect_err" tabindex="-1" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>

<h4>Connect to chat is failed</h4>
</div>

<div class="modal-body">
<p class="text-danger">
Something wrong with connect to chat. Check internet connection or user info and trying again.
</p>
</div>
<p></p>
</div>
</div>
</div>

<div class="modal fade" id="error_no_calles" tabindex="-1">
<div class="modal-dialog modal-sm">
<div class="modal-content">
Expand Down Expand Up @@ -128,7 +147,7 @@ <h4>Call from <strong class="j-ic_initiator"></strong></h4>

<script type="text/template" id="tpl_device_not_found">
Error: devices (camera or microphone) are not found.
<span class="qb-text">&emsp;Login in <b>as <%=name%></b></span>
<span class="qb-text">Login in <b>as <%=name%></b></span>
<button class='fw-link j-logout'>Logout</button>
</script>

Expand Down
59 changes: 39 additions & 20 deletions samples/webrtc/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,25 @@
password: 'webAppPass'
}, function(err, res) {
if(err) {
QB.chat.disconnect();
app.router.navigate('join', { trigger: true });
if(!_.isEmpty(app.currentSession)) {
app.currentSession.stop({});
app.currentSession = {};
}

app.helpers.changeFilter('#localVideo', 'no');
app.helpers.changeFilter('#main_video', 'no');
app.mainVideo = 0;

$(ui.filterSelect).val('no');
app.calleesAnwered = [];

if(call.callTimer) {
$('#timer').addClass('hidden');
clearInterval(call.callTimer);
call.callTimer = null;
call.callTime = 0;
app.helpers.network = {};
}
} else {
$form.removeClass('join-wait');
$form.trigger('reset');
Expand Down Expand Up @@ -250,6 +267,7 @@
/** Hangup */
if ($btn.hasClass('hangup')) {
if(!_.isEmpty(app.currentSession)) {

app.currentSession.stop({});
app.currentSession = {};

Expand Down Expand Up @@ -278,7 +296,7 @@
return false;
}

app.helpers.stateBoard.update('create_session');
app.helpers.stateBoard.update({'title': 'create_session'});
app.currentSession = QB.webrtc.createNewSession(Object.keys(app.callees), QB.webrtc.CallType.VIDEO);

app.currentSession.getUserMedia(mediaParams, function(err, stream) {
Expand Down Expand Up @@ -323,7 +341,6 @@

/** DECLINE */
$(document).on('click', '.j-decline', function() {
console.info('FUUUC');
if (!_.isEmpty(app.currentSession)) {
app.currentSession.reject({});

Expand Down Expand Up @@ -374,6 +391,7 @@
compiled = _.template( $('#callee_video').html() );

$('.j-actions').addClass('hangup');
$(ui.sourceFilter).attr('disabled', true);

/** get all opponents */
app.currentSession.opponentsIDs.forEach(function(userID, i, arr) {
Expand All @@ -390,7 +408,7 @@
videoElems += compiled({userID: userID, name: userInfo.full_name});

if(peerState === QB.webrtc.PeerConnectionState.CLOSED){
app.helpers.toggleRemoteVideoView(app.currentSession, userID, 'clear');
app.helpers.toggleRemoteVideoView( userID, 'clear');
}
}
});
Expand All @@ -403,7 +421,6 @@
}
});
app.helpers.setFooterPosition();

app.currentSession.accept({});
}
});
Expand Down Expand Up @@ -514,7 +531,7 @@
QB.webrtc.onCallStatsReport = function onCallStatsReport(session, userId, stats) {
console.group('onCallStatsReport');
console.log('userId: ', userId);
// console.log('Stats: ', stats);
console.log('session: ', session);
console.groupEnd();

/**
Expand All @@ -525,7 +542,7 @@
var inboundrtp = _.findWhere(stats, {type: 'inboundrtp'});

if(!inboundrtp || !app.helpers.isBytesReceivedChanges(userId, inboundrtp)) {
console.warn("This is Firefox and user " + userId + " has lost his connection.");
console.warn('This is Firefox and user ' + userId + ' has lost his connection.');

if(!_.isEmpty(app.currentSession)) {
app.currentSession.closeConnection(userId);
Expand All @@ -552,7 +569,7 @@

if(session.opponentsIDs.length > 1) {
app.helpers.stateBoard.update({
'title': 'call_stop',
'title': 'tpl_call_stop',
'property': {
'name': app.caller.full_name
}
Expand Down Expand Up @@ -585,17 +602,20 @@

QB.webrtc.onCallListener = function onCallListener(session, extension) {
console.group('onCallListener.');
console.log('Session: ' + session);
console.log('Extension: ' + JSON.stringify(extension));
console.log('Session: ', session);
console.log('Extension: ', extension);
console.groupEnd();

var initiator = _.findWhere(app.users, {id: session.initiatorID});
app.currentSession = session;

/** close previous modal */
$(ui.income_call).modal('hide');
/** set name of caller */
$('.j-ic_initiator').text( initiator.full_name );
/**
* set name of caller
* TODO: what if user doesn't sync all users
*/
$('.j-ic_initiator').text( initiator.full_name ? initiator.full_name : 'Unknown' );
$(ui.income_call).modal('show');
document.getElementById(sounds.rington).play();
};
Expand Down Expand Up @@ -697,11 +717,11 @@
};

QB.webrtc.onSessionConnectionStateChangedListener = function onSessionConnectionStateChangedListener(session, userId, connectionState) {
console.group('onSessionConnectionStateChangedListener.');
console.log('UserID: ', userId);
console.log('Session: ', session);
console.log('Сonnection state: ', connectionState);
console.groupEnd();
console.group('onSessionConnectionStateChangedListener.');
console.log('UserID: ', userId);
console.log('Session: ', session);
console.log('Сonnection state: ', connectionState);
console.groupEnd();

var connectionStateName = _.invert(QB.webrtc.SessionConnectionState)[connectionState],
$calleeStatus = $('.j-callee_status_' + userId),
Expand Down Expand Up @@ -734,7 +754,6 @@
$('#remote_video_' + userId).removeClass('active');

app.helpers.changeFilter('#main_video', 'no');
// app.currentSession.detachMediaStream('main_video');
app.mainVideo = 0;
}

Expand Down Expand Up @@ -765,7 +784,7 @@
'title': 'tpl_accept_call',
'property': {
'users': app.calleesAnwered
}
}
});
}

Expand Down
90 changes: 46 additions & 44 deletions samples/webrtc/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
* [getUui - generate a unique id]
* @return {[string]} [a unique id]
*/
function getUui() {
function _getUui() {
var navigator_info = window.navigator;
var screen_info = window.screen;
var uid = navigator_info.mimeTypes.length;
Expand All @@ -107,56 +107,58 @@
}

app.helpers.join = function(data) {
var userRequiredParams = {
'login': _getUui(),
'password': 'webAppPass'
};

return new Promise(function(resolve, reject) {
QB.createSession(function(csError, csResult){
if(csError) {
reject(csError);
QB.createSession(function(csErr, csRes){
if(csErr) {
reject(csErr);
} else {
/** Login */
QB.login({
'login': getUui(),
'password': 'webAppPass'
},
function(egError, egUser){
/** User not found */
if(egError) {
QB.users.create({
'login': getUui(),
'password': 'webAppPass',
'full_name': data.username,
'tag_list': data.room
},
function(ucError, ucUser){
if(ucError) {
console.log('[create user] Error:', ucError);
reject(ucError);
} else {
console.log('[create user] User:', ucUser);
resolve(ucUser);
}
}
);
} else {
/** Update info */
if(egUser.user_tags !== data.room || egUser.full_name !== data.username ) {
QB.users.update(egUser.id, {
'full_name': data.username,
'tag_list': data.room
}, function(uuError, uuUser) {
if(uuError) {
console.log('APP [update user] Error:', uuError);
reject(uuError);
/** In first trying to login */
QB.login(userRequiredParams, function(loginErr, loginUser){
if(loginErr) {
/** Login failed, trying to create account */
QB.users.create({
'login': _getUui(),
'password': 'webAppPass',
'full_name': data.username,
'tag_list': data.room
}, function(createErr, createUser){
if(createErr) {
console.log('[create user] Error:', createErr);
reject(createErr);
} else {
QB.login(userRequiredParams, function(reloginErr, reloginUser) {
if(reloginErr) {
console.log('[relogin user] Error:', reloginErr);
} else {
console.log('APP [update user] User:', uuUser);
resolve(uuUser);
resolve(reloginUser);
}
});
} else {
resolve(egUser);
}
});
} else {
/** Update info */
if(loginUser.user_tags !== data.room || loginUser.full_name !== data.username ) {
QB.users.update(loginUser.id, {
'full_name': data.username,
'tag_list': data.room
}, function(updateError, updateUser) {
if(updateError) {
console.log('APP [update user] Error:', updateError);
reject(updateError);
} else {
resolve(updateUser);
}
});
} else {
resolve(loginUser);
}
}
);
});
}
});
});
Expand All @@ -180,7 +182,7 @@
}
});

if(!result.items.length) {
if(result.items.length < 2) {
reject({
'title': 'not found',
'message': 'Not found users by tag'
Expand Down
55 changes: 26 additions & 29 deletions src/modules/webrtc/qbRTCPeerConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,35 +239,32 @@ RTCPeerConnection.prototype.onIceConnectionStateCallback = function() {
};

RTCPeerConnection.prototype._getStatsWrap = function() {
var self = this,
selector = self.delegate.callType == 1 ? self.getLocalStreams()[0].getVideoTracks()[0] : self.getLocalStreams()[0].getAudioTracks()[0],
statsReportInterval;

if (!config.webrtc && !config.webrtc.statsReportTimeInterval) {
return;
}

if (isNaN(+config.webrtc.statsReportTimeInterval)) {
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
return;
}

statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;

var _statsReportCallback = function() {
_getStats(self, selector,
function (results) {
self.delegate._onCallStatsReport(self.userID, results);
},
function errorLog(err) {
Helpers.traceError("_getStats error. " + err.name + ": " + err.message);
}
);
};

Helpers.trace('Stats tracker has been started.');

self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval);
var self = this,
selector = self.delegate.callType == 1 ? self.getLocalStreams()[0].getVideoTracks()[0] : self.getLocalStreams()[0].getAudioTracks()[0],
statsReportInterval;

if (config.webrtc && config.webrtc.statsReportTimeInterval) {
if (isNaN(+config.webrtc.statsReportTimeInterval)) {
Helpers.traceError('statsReportTimeInterval (' + config.webrtc.statsReportTimeInterval + ') must be integer.');
return;
}

statsReportInterval = config.webrtc.statsReportTimeInterval * 1000;

var _statsReportCallback = function() {
_getStats(self, selector,
function (results) {
self.delegate._onCallStatsReport(self.userID, results);
},
function errorLog(err) {
Helpers.traceError('_getStats error. ' + err.name + ': ' + err.message);
}
);
};

Helpers.trace('Stats tracker has been started.');
self.statsReportTimer = setInterval(_statsReportCallback, statsReportInterval);
}
};

RTCPeerConnection.prototype._clearWaitingReconnectTimer = function() {
Expand Down
Loading