|
12 | 12 | var ui = {
|
13 | 13 | 'income_call': '#income_call',
|
14 | 14 | 'filterSelect': '.j-filter',
|
15 |
| - 'sourceFilter': '.j-source' |
| 15 | + 'sourceFilter': '.j-source', |
| 16 | + 'insertOccupants': function() { |
| 17 | + var $occupantsCont = $('.j-users'); |
| 18 | + |
| 19 | + function cb($cont, res) { |
| 20 | + $cont.empty() |
| 21 | + .append(res) |
| 22 | + .removeClass('wait'); |
| 23 | + } |
| 24 | + |
| 25 | + return new Promise(function(resolve, reject) { |
| 26 | + $occupantsCont.addClass('wait'); |
| 27 | + |
| 28 | + app.helpers.renderUsers().then(function(res) { |
| 29 | + cb($occupantsCont, res.usersHTML); |
| 30 | + resolve(res.users); |
| 31 | + }, function(error) { |
| 32 | + cb($occupantsCont, error.message); |
| 33 | + reject(null); |
| 34 | + }); |
| 35 | + }); |
| 36 | + } |
16 | 37 | };
|
17 | 38 |
|
18 | 39 | var call = {
|
|
86 | 107 |
|
87 | 108 | /** render users wrapper */
|
88 | 109 | $('.j-users_wrap').append( $('#users_tpl').html() );
|
89 |
| - |
90 |
| - /** render users */ |
91 |
| - app.helpers.renderUsers().then(function(res) { |
92 |
| - $('.j-users').empty() |
93 |
| - .append(res.usersHTML) |
94 |
| - .removeClass('wait'); |
95 |
| - |
96 |
| - app.users = res.users; |
97 |
| - }, function(error) { |
98 |
| - if(error.title === 'not found') { |
99 |
| - $('.j-users').empty() |
100 |
| - .append(error.message) |
101 |
| - .removeClass('wait'); |
102 |
| - } |
| 110 | + ui.insertOccupants(function(users) { |
| 111 | + app.users = users; |
103 | 112 | });
|
104 | 113 |
|
105 | 114 | /** render frames */
|
|
154 | 163 | return [item.name, item.value.trim()];
|
155 | 164 | }));
|
156 | 165 |
|
| 166 | + if(localStorage.getItem('isAuth')) { |
| 167 | + $('#already_auth').modal(); |
| 168 | + return false; |
| 169 | + } |
| 170 | + |
157 | 171 | $form.addClass('join-wait');
|
158 | 172 |
|
159 | 173 | app.helpers.join(data).then(function (user) {
|
|
186 | 200 | } else {
|
187 | 201 | $form.removeClass('join-wait');
|
188 | 202 | $form.trigger('reset');
|
| 203 | + localStorage.setItem('isAuth', true); |
189 | 204 | app.router.navigate('dashboard', { trigger: true });
|
190 | 205 | }
|
191 | 206 | });
|
|
201 | 216 | */
|
202 | 217 | /** REFRESH USERS */
|
203 | 218 | $(document).on('click', '.j-users__refresh', function() {
|
204 |
| - var $btn = $(this), |
205 |
| - $usersCont = $('.j-users'); |
| 219 | + var $btn = $(this); |
206 | 220 |
|
| 221 | + app.callees = {}; |
207 | 222 | $btn.prop('disabled', true);
|
208 |
| - $usersCont.addClass('wait'); |
209 |
| - |
210 |
| - app.helpers.renderUsers().then(function(res) { |
211 |
| - $usersCont.empty() |
212 |
| - .append(res.usersHTML) |
213 |
| - .removeClass('wait'); |
214 | 223 |
|
215 |
| - app.users = res.users; |
| 224 | + ui.insertOccupants().then(function(users) { |
| 225 | + app.users = users; |
216 | 226 |
|
217 | 227 | $btn.prop('disabled', false);
|
218 |
| - }, function(error) { |
219 |
| - if(error.title === 'not found') { |
220 |
| - $('.j-users').empty() |
221 |
| - .append(error.message) |
222 |
| - .removeClass('wait'); |
223 |
| - } |
224 |
| - |
| 228 | + app.helpers.setFooterPosition(); |
| 229 | + }, function() { |
225 | 230 | $btn.prop('disabled', false);
|
| 231 | + app.helpers.setFooterPosition(); |
226 | 232 | });
|
227 |
| - |
228 |
| - app.callees = {}; |
229 |
| - |
230 |
| - app.helpers.setFooterPosition(); |
231 | 233 | });
|
232 | 234 |
|
233 | 235 | /** Check / uncheck user (callee) */
|
|
494 | 496 | app.users = [];
|
495 | 497 |
|
496 | 498 | QB.chat.disconnect();
|
| 499 | + localStorage.removeItem('isAuth'); |
497 | 500 | app.router.navigate('join', {'trigger': true});
|
498 | 501 | app.helpers.setFooterPosition();
|
499 | 502 | } else {
|
|
502 | 505 | });
|
503 | 506 | });
|
504 | 507 |
|
| 508 | + /** Close tab or browser */ |
| 509 | + $( window ).unload(function() { |
| 510 | + localStorage.removeItem('isAuth'); |
| 511 | + }); |
| 512 | + |
505 | 513 | /**
|
506 | 514 | * QB Event listener.
|
507 | 515 | *
|
|
606 | 614 | console.log('Extension: ', extension);
|
607 | 615 | console.groupEnd();
|
608 | 616 |
|
609 |
| - var initiator = _.findWhere(app.users, {id: session.initiatorID}); |
610 |
| - app.currentSession = session; |
| 617 | + ui.insertOccupants().then(function(users) { |
| 618 | + app.users = users; |
611 | 619 |
|
612 |
| - /** close previous modal */ |
613 |
| - $(ui.income_call).modal('hide'); |
614 |
| - /** |
615 |
| - * set name of caller |
616 |
| - * TODO: what if user doesn't sync all users |
617 |
| - */ |
618 |
| - $('.j-ic_initiator').text( initiator.full_name ? initiator.full_name : 'Unknown' ); |
619 |
| - $(ui.income_call).modal('show'); |
620 |
| - document.getElementById(sounds.rington).play(); |
| 620 | + var initiator = _.findWhere(app.users, {id: session.initiatorID}); |
| 621 | + app.currentSession = session; |
| 622 | + |
| 623 | + /** close previous modal */ |
| 624 | + $(ui.income_call).modal('hide'); |
| 625 | + |
| 626 | + $('.j-ic_initiator').text(initiator.full_name); |
| 627 | + $(ui.income_call).modal('show'); |
| 628 | + document.getElementById(sounds.rington).play(); |
| 629 | + }); |
621 | 630 | };
|
622 | 631 |
|
623 | 632 | QB.webrtc.onRejectCallListener = function onRejectCallListener(session, userId, extension) {
|
|
776 | 785 | app.calleesAnwered = [];
|
777 | 786 | }
|
778 | 787 |
|
779 |
| - if (app.currentSession.currentUserID === app.currentSession.initiatorID && !isCallEnded) { |
| 788 | + if (app.currentSession.currentUserID === app.currentSession.initiatorID && !isCallEnded) { |
780 | 789 | /** get array if users without user who ends call */
|
781 |
| - app.calleesAnwered = _.reject(app.calleesAnwered, function(num){ return num.id === +userId; }); |
| 790 | + app.calleesAnwered = _.reject(app.calleesAnwered, function(num){ return num.id === +userId; }); |
782 | 791 |
|
783 |
| - app.helpers.stateBoard.update({ |
| 792 | + app.helpers.stateBoard.update({ |
784 | 793 | 'title': 'tpl_accept_call',
|
785 | 794 | 'property': {
|
786 | 795 | 'users': app.calleesAnwered
|
787 | 796 | }
|
788 |
| - }); |
789 |
| - } |
| 797 | + }); |
| 798 | + } |
790 | 799 |
|
791 | 800 | if( _.isEmpty(app.currentSession) || isCallEnded ) {
|
792 | 801 | if(call.callTimer) {
|
|
0 commit comments