5
5
var ui = {
6
6
$usersTitle : $ ( '.j-users__title' ) ,
7
7
$usersList : $ ( '.j-users__list' ) ,
8
- $cl : $ ( '.j-console' ) ,
9
8
10
9
$panel : $ ( '.j-pl' ) ,
11
10
$callees : $ ( '.j-callees' ) ,
68
67
this . $btnHangup . removeClass ( 'hidden' ) ;
69
68
this . $btnCall . addClass ( 'hidden' ) ;
70
69
} ,
71
- /**
72
- * [updateMsg update massage for user]
73
- * @param {[string] } msg_name [key for MESSAGES object / name(id) of template]
74
- * @param {[object] } obj [additional paramets for compiled template]
75
- */
76
- updateMsg : function ( params ) {
77
- var msg = '' ;
78
-
79
- if ( MESSAGES [ params . msg ] ) {
80
- msg = MESSAGES [ params . msg ] ;
81
- } else {
82
- msg = _ . template ( $ ( '#' + params . msg ) . html ( ) ) ( params . obj ) ;
83
- }
84
-
85
- this . $cl
86
- . empty ( )
87
- . append ( msg ) ;
88
- } ,
89
70
toggleRemoteVideoView : function ( userID , action ) {
90
71
var $video = $ ( '#remote_video_' + userID ) ;
91
72
132
113
133
114
ui . createUsers ( QBUsers , ui . $usersList ) ;
134
115
ui . $usersTitle . text ( MESSAGES . title_login ) ;
135
-
116
+
136
117
if ( ! params . withoutUpdMsg || params . msg ) {
137
- ui . updateMsg ( { msg : params . msg } ) ;
118
+ qbApp . MsgBoard . update ( params . msg ) ;
138
119
}
139
120
}
140
121
159
140
160
141
/** if app.caller is not exist create caller, if no - add callees */
161
142
if ( ! window . navigator . onLine ) {
162
- ui . updateMsg ( { msg : 'no_internet' } ) ;
143
+ qbApp . MsgBoard . update ( 'no_internet' ) ;
163
144
} else {
164
145
if ( _ . isEmpty ( app . caller ) ) {
165
146
authorizationing = true ;
178
159
179
160
ui . $usersList . empty ( ) ;
180
161
181
- ui . updateMsg ( { msg : 'connect' } ) ;
162
+ qbApp . MsgBoard . update ( 'connect' ) ;
182
163
183
164
QB . chat . connect ( {
184
165
jid : QB . chat . helpers . getUserJid ( app . caller . id , QBApp . appId ) ,
194
175
ui . createUsers ( usersWithoutCaller , ui . $usersList ) ;
195
176
196
177
ui . $usersTitle . text ( MESSAGES . title_callee ) ;
197
- ui . updateMsg ( { msg : 'login_tpl' , obj : { name : app . caller . full_name } } ) ;
178
+ qbApp . MsgBoard . update ( 'login_tpl' , { name : app . caller . full_name } ) ;
198
179
199
180
ui . $panel . removeClass ( 'hidden' ) ;
200
181
ui . setPositionFooter ( ) ;
240
221
} ;
241
222
242
223
if ( ! window . navigator . onLine ) {
243
- ui . updateMsg ( { msg : 'no_internet' } ) ;
224
+ qbApp . MsgBoard . update ( 'no_internet' ) ;
244
225
} else {
245
226
if ( _ . isEmpty ( app . callees ) ) {
246
227
$ ( '#error_no_calles' ) . modal ( ) ;
247
228
} else {
248
- ui . updateMsg ( { msg : 'create_session' } ) ;
229
+ qbApp . MsgBoard . update ( 'create_session' ) ;
249
230
app . currentSession = QB . webrtc . createNewSession ( Object . keys ( app . callees ) , QB . webrtc . CallType . VIDEO ) ;
250
231
app . currentSession . getUserMedia ( mediaParams , function ( err , stream ) {
251
232
if ( err || ! stream . getAudioTracks ( ) . length || ! stream . getVideoTracks ( ) . length ) {
252
- ui . updateMsg ( { msg : 'device_not_found' , obj : { name : app . caller . full_name } } ) ;
233
+ qbApp . MsgBoard . update ( 'device_not_found' , { name : app . caller . full_name } ) ;
253
234
app . currentSession . stop ( { } ) ;
254
235
} else {
255
236
app . currentSession . call ( { } , function ( error ) {
258
239
} else {
259
240
var compiled = _ . template ( $ ( '#callee_video' ) . html ( ) ) ;
260
241
261
- ui . updateMsg ( { msg : 'calling' } ) ;
242
+ qbApp . MsgBoard . update ( 'calling' ) ;
262
243
document . getElementById ( ui . sounds . call ) . play ( ) ;
263
244
264
245
/** create video elements for callees */
284
265
app . currentSession . stop ( { } ) ;
285
266
app . currentSession = { } ;
286
267
287
- ui . updateMsg ( { msg : 'login_tpl' , obj : { name : app . caller . full_name } } ) ;
268
+ qbApp . MsgBoard . update ( 'login_tpl' , { name : app . caller . full_name } ) ;
288
269
}
289
270
} ) ;
290
271
307
288
308
289
app . currentSession . getUserMedia ( mediaParams , function ( err , stream ) {
309
290
if ( err ) {
310
- ui . updateMsg ( { msg : 'device_not_found' , obj : { name : app . caller . full_name } } ) ;
291
+ qbApp . MsgBoard . update ( 'device_not_found' , { name : app . caller . full_name } ) ;
311
292
isDeviceAccess = false ;
312
293
app . currentSession . stop ( { } ) ;
313
294
} else {
338
319
} ) ;
339
320
340
321
ui . $callees . append ( videoElems ) ;
341
- ui . updateMsg ( { msg : 'during_call' , obj : { name : app . caller . full_name } } ) ;
322
+ qbApp . MsgBoard . update ( 'during_call' , { name : app . caller . full_name } ) ;
342
323
ui . setPositionFooter ( ) ;
343
324
344
325
app . currentSession . accept ( { } ) ;
384
365
if ( app . currentSession . peerConnections [ userID ] . stream && ! _ . isEmpty ( $that . attr ( 'src' ) ) ) {
385
366
if ( $that . hasClass ( 'active' ) ) {
386
367
$that . removeClass ( 'active' ) ;
387
-
368
+
388
369
app . currentSession . detachMediaStream ( 'main_video' ) ;
389
370
ui . changeFilter ( '#main_video' , 'no' ) ;
390
371
app . mainVideo = 0 ;
423
404
424
405
/** Before use WebRTC checking WebRTC is avaible */
425
406
if ( ! QB . webrtc ) {
426
- ui . updateMsg ( { msg : 'webrtc_not_avaible' } ) ;
407
+ qbApp . MsgBoard . update ( 'webrtc_not_avaible' ) ;
427
408
} else {
428
409
/**
429
410
* QB Event listener:
473
454
isDeviceAccess = true ;
474
455
} else {
475
456
if ( session . opponentsIDs . length > 1 ) {
476
- ui . updateMsg ( { msg : 'call_stop' , obj : { name : app . caller . full_name } } ) ;
457
+ qbApp . MsgBoard . update ( 'call_stop' , { name : app . caller . full_name } ) ;
477
458
}
478
459
}
479
460
498
479
console . log ( 'Session: ' + session ) ;
499
480
console . groupEnd ( ) ;
500
481
501
- var userInfo = _ . findWhere ( QBUsers , { id : + userId } ) ;
482
+ var userInfo = _ . findWhere ( QBUsers , { id : + userId } ) ,
483
+ currentUserInfo = _ . findWhere ( QBUsers , { id : app . currentSession . currentUserID } ) ;
502
484
503
485
/** It's for p2p call */
504
486
if ( session . opponentsIDs . length === 1 ) {
505
- ui . updateMsg ( {
506
- msg : 'p2p_call_stop' ,
507
- obj : {
508
- name : userInfo . full_name ,
509
- reason : 'not answered'
510
- }
511
- } ) ;
487
+ qbApp . MsgBoard . update (
488
+ 'p2p_call_stop' ,
489
+ {
490
+ name : userInfo . full_name ,
491
+ currentName : currentUserInfo . full_name ,
492
+ reason : 'not answered'
493
+ }
494
+ ) ;
512
495
}
513
496
514
497
/** It's for groups call */
565
548
566
549
/** update list of callee who take call */
567
550
takedCallCallee . push ( userInfo ) ;
568
-
551
+
569
552
if ( app . currentSession . currentUserID === app . currentSession . initiatorID ) {
570
- ui . updateMsg ( { msg : 'accept_call' , obj : { users : takedCallCallee } } ) ;
553
+ qbApp . MsgBoard . update ( 'accept_call' , { users : takedCallCallee } ) ;
571
554
}
572
555
} ;
573
556
578
561
console . log ( 'Extension: ' + JSON . stringify ( extension ) ) ;
579
562
console . groupEnd ( ) ;
580
563
581
- var userInfo = _ . findWhere ( QBUsers , { id : userId } ) ;
564
+ var userInfo = _ . findWhere ( QBUsers , { id : userId } ) ,
565
+ currentUserInfo = _ . findWhere ( QBUsers , { id : app . currentSession . currentUserID } ) ;
582
566
583
567
/** It's for p2p call */
584
568
if ( session . opponentsIDs . length === 1 ) {
585
- ui . updateMsg ( {
586
- msg : 'p2p_call_stop' ,
587
- obj : {
588
- name : userInfo . full_name ,
589
- reason : 'rejected the call'
590
- }
591
- } ) ;
569
+ qbApp . MsgBoard . update (
570
+ 'p2p_call_stop' ,
571
+ {
572
+ name : userInfo . full_name ,
573
+ currentName : currentUserInfo . full_name ,
574
+ reason : 'rejected the call'
575
+ }
576
+ ) ;
592
577
}
593
578
594
579
/** It's for groups call */
602
587
console . log ( 'Extension: ' + JSON . stringify ( extension ) ) ;
603
588
console . groupEnd ( ) ;
604
589
605
- var userInfo = _ . findWhere ( QBUsers , { id : userId } ) ;
590
+ /** It's for p2p call */
591
+ var userInfo = _ . findWhere ( QBUsers , { id : userId } ) ,
592
+ currentUserInfo = _ . findWhere ( QBUsers , { id : app . currentSession . currentUserID } ) ;
606
593
607
594
/** It's for p2p call */
608
595
if ( session . opponentsIDs . length === 1 ) {
609
- ui . updateMsg ( {
610
- msg : 'p2p_call_stop' ,
611
- obj : {
612
- name : userInfo . full_name ,
613
- reason : 'hung up the call'
614
- }
615
- } ) ;
596
+ qbApp . MsgBoard . update (
597
+ 'p2p_call_stop' ,
598
+ {
599
+ name : userInfo . full_name ,
600
+ currentName : currentUserInfo . full_name ,
601
+ reason : 'hung up the call'
602
+ }
603
+ ) ;
616
604
}
617
605
618
606
/** It's for groups call */
627
615
app . currentSession . peerConnections [ userID ] . stream = stream ;
628
616
629
617
app . currentSession . attachMediaStream ( 'remote_video_' + userID , stream ) ;
630
-
618
+
631
619
if ( remoteStreamCounter === 0 ) {
632
620
$ ( '#remote_video_' + userID ) . click ( ) ;
633
-
621
+
634
622
app . mainVideo = userID ;
635
623
++ remoteStreamCounter ;
636
624
}
673
661
if ( connectionState === QB . webrtc . SessionConnectionState . CLOSED ) {
674
662
ui . toggleRemoteVideoView ( userID , 'clear' ) ;
675
663
document . getElementById ( ui . sounds . rington ) . pause ( ) ;
676
-
664
+
677
665
if ( app . mainVideo === userID ) {
678
666
$ ( '#remote_video_' + userID ) . removeClass ( 'active' ) ;
679
667
703
691
704
692
if ( app . currentSession . currentUserID === app . currentSession . initiatorID && ! isCallEnded ) {
705
693
/** get array if users without user who ends call */
706
- takedCallCallee = _ . reject ( takedCallCallee , function ( num ) { return num . id !== + userID ; } ) ;
707
- ui . updateMsg ( { msg : 'accept_call' , obj : { users : takedCallCallee } } ) ;
694
+ takedCallCallee = _ . reject ( takedCallCallee , function ( num ) { return num . id === + userID ; } ) ;
695
+
696
+ qbApp . MsgBoard . update ( 'accept_call' , { users : takedCallCallee } ) ;
708
697
}
709
698
710
699
if ( _ . isEmpty ( app . currentSession ) || isCallEnded ) {
711
700
if ( callTimer ) {
712
701
$ ( '#timer' ) . addClass ( 'hidden' ) ;
713
-
702
+
714
703
clearInterval ( callTimer ) ;
715
704
callTimer = null ;
716
705
ui . callTime = 0 ;
720
709
} ;
721
710
}
722
711
} ) ;
723
- } ( window , jQuery ) ) ;
712
+ } ( window , jQuery ) ) ;
0 commit comments