Skip to content

Commit 5a7a784

Browse files
committed
QBWEBSDK-181
1 parent e8d12ce commit 5a7a784

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

samples/webrtc/app.js

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -158,58 +158,62 @@
158158
classNameCheckedUser = 'users__user-active';
159159

160160
/** if app.caller is not exist create caller, if no - add callees */
161-
if( _.isEmpty(app.caller) ) {
162-
authorizationing = true;
163-
ui.togglePreloadMain('show');
164-
/**
165-
* id: + for convert to number type
166-
*/
167-
app.caller = {
168-
id: +$.trim( $el.data('id') ),
169-
login: $.trim( $el.data('login') ),
170-
password: $.trim( $el.data('password') ),
171-
full_name: $.trim( $el.data('name') )
172-
};
173-
174-
usersWithoutCaller = _.filter(QBUsers, function(i) { return i.id !== app.caller.id; });
161+
if(!window.navigator.onLine) {
162+
ui.updateMsg({msg: 'no_internet'});
163+
} else {
164+
if(_.isEmpty(app.caller)) {
165+
authorizationing = true;
166+
ui.togglePreloadMain('show');
167+
/**
168+
* id: + for convert to number type
169+
*/
170+
app.caller = {
171+
id: +$.trim( $el.data('id') ),
172+
login: $.trim( $el.data('login') ),
173+
password: $.trim( $el.data('password') ),
174+
full_name: $.trim( $el.data('name') )
175+
};
176+
177+
usersWithoutCaller = _.filter(QBUsers, function(i) { return i.id !== app.caller.id; });
178+
179+
ui.$usersList.empty();
180+
181+
ui.updateMsg( {msg: 'connect'} );
182+
183+
QB.chat.connect({
184+
jid: QB.chat.helpers.getUserJid( app.caller.id, QBApp.appId ),
185+
password: app.caller.password
186+
}, function(err, res) {
187+
if(err !== null) {
188+
app.caller = {};
189+
190+
ui.setPositionFooter();
191+
ui.togglePreloadMain('hide');
192+
QB.chat.disconnect();
193+
} else {
194+
ui.createUsers(usersWithoutCaller, ui.$usersList);
175195

176-
ui.$usersList.empty();
196+
ui.$usersTitle.text(MESSAGES.title_callee);
197+
ui.updateMsg( {msg: 'login_tpl', obj: {name: app.caller.full_name}} );
177198

178-
ui.updateMsg( {msg: 'create_session'} );
179-
ui.updateMsg( {msg: 'connect'} );
199+
ui.$panel.removeClass('hidden');
200+
ui.setPositionFooter();
201+
ui.togglePreloadMain('hide');
202+
}
180203

181-
QB.chat.connect({
182-
jid: QB.chat.helpers.getUserJid( app.caller.id, QBApp.appId ),
183-
password: app.caller.password
184-
}, function(err, res) {
185-
if(err !== null) {
186-
app.caller = {};
204+
authorizationing = false;
205+
});
206+
} else {
207+
user.id = +$.trim( $el.data('id') );
208+
user.name = $.trim( $el.data('name') );
187209

188-
ui.setPositionFooter();
189-
ui.togglePreloadMain('hide');
210+
if ($el.hasClass(classNameCheckedUser)) {
211+
delete app.callees[user.id];
212+
$el.removeClass(classNameCheckedUser);
190213
} else {
191-
ui.createUsers(usersWithoutCaller, ui.$usersList);
192-
193-
ui.$usersTitle.text(MESSAGES.title_callee);
194-
ui.updateMsg( {msg: 'login_tpl', obj: {name: app.caller.full_name}} );
195-
196-
ui.$panel.removeClass('hidden');
197-
ui.setPositionFooter();
198-
ui.togglePreloadMain('hide');
214+
app.callees[user.id] = user.name;
215+
$el.addClass(classNameCheckedUser);
199216
}
200-
201-
authorizationing = false;
202-
});
203-
} else {
204-
user.id = +$.trim( $el.data('id') );
205-
user.name = $.trim( $el.data('name') );
206-
207-
if ($el.hasClass(classNameCheckedUser)) {
208-
delete app.callees[user.id];
209-
$el.removeClass(classNameCheckedUser);
210-
} else {
211-
app.callees[user.id] = user.name;
212-
$el.addClass(classNameCheckedUser);
213217
}
214218
}
215219

@@ -241,8 +245,8 @@
241245
if ( _.isEmpty(app.callees) ) {
242246
$('#error_no_calles').modal();
243247
} else {
248+
ui.updateMsg( {msg: 'create_session'} );
244249
app.currentSession = QB.webrtc.createNewSession(Object.keys(app.callees), QB.webrtc.CallType.VIDEO);
245-
246250
app.currentSession.getUserMedia(mediaParams, function(err, stream) {
247251
if (err || !stream.getAudioTracks().length || !stream.getVideoTracks().length) {
248252
ui.updateMsg({msg: 'device_not_found', obj: {name: app.caller.full_name}});

0 commit comments

Comments
 (0)