@@ -3,14 +3,14 @@ import { createDiv, createImg, createLabel } from "../utils/domUtil";
33import { getCallOption } from "../utils/util" ;
44import CallButtons from "./CallButtons" ;
55import { classes } from "../css/styles.js" ;
6+ import PeriodicJob from "../modules/PeriodicJob" ;
67
78export default class CallView extends BaseElement {
89 constructor ( { call, state, args } ) {
910 super ( { id : 'call_view' , className : `${ classes [ 'column' ] } ${ classes [ 'center' ] } ${ classes [ 'view' ] } ${ classes [ 'viewCall' ] } ` , args } ) ;
1011
1112 this . call = call ;
1213 this . state = state ;
13- this . timer = null ;
1414 this . connected = false ;
1515 this . addCallListeners ( call ) ;
1616 }
@@ -25,7 +25,7 @@ export default class CallView extends BaseElement {
2525 const peerProfile = createImg ( { src : remoteUser . profileUrl , className : classes [ 'remoteProfile' ] } ) ;
2626 const peerName = createLabel ( { id : 'peer_name' , innerText : remoteUser . userId , className : `${ classes [ 'peerName' ] } ${ classes [ 'fontBig' ] } ` } ) ;
2727
28- const connectionInfo = createLabel ( { id : 'conn_info_label' , className : `${ classes [ 'connectionInfo' ] } ${ classes [ 'fontNormal' ] } ` } ) ;
28+ this . connectionInfo = createLabel ( { id : 'conn_info_label' , className : `${ classes [ 'connectionInfo' ] } ${ classes [ 'fontNormal' ] } ` } ) ;
2929
3030 const peerStateDiv = createDiv ( { id : 'peer_state' , className : `${ classes [ 'column' ] } ${ classes [ 'peerStateDiv' ] } ${ classes [ 'invisible' ] } ` } ) ;
3131 const peerMuteIcon = createDiv ( { id : 'peer_mute_icon' , className : classes [ 'peerMuteIcon' ] } ) ;
@@ -37,41 +37,37 @@ export default class CallView extends BaseElement {
3737
3838 this . element . appendChild ( peerProfile ) ;
3939 this . element . appendChild ( peerName ) ;
40- this . element . appendChild ( connectionInfo ) ;
40+ this . element . appendChild ( this . connectionInfo ) ;
4141 this . element . appendChild ( peerStateDiv ) ;
4242 buttons . appendToBaseElement ( this ) ;
4343
44- let tick = 0 ;
45- this . timer = setInterval ( ( ) => {
46- const callingStr = 'Calling' ;
47- if ( this . call && this . call . endResult ) {
48- connectionInfo . innerText = this . call . endResult ;
49- clearInterval ( this . timer ) ;
50- } else if ( ! this . connected && this . call . caller . userId === localUser . userId ) {
51- connectionInfo . innerText = callingStr + '.' . repeat ( ( tick % 3 ) + 1 ) ;
52- } else if ( this . connected ) {
53- const durationInSec = Math . floor ( this . call . getDuration ( ) / 1000 ) ;
54- const minutes = `0${ Math . floor ( durationInSec / 60 ) } ` . slice ( - 2 ) ;
55- const seconds = `0${ durationInSec % 60 } ` . slice ( - 2 ) ;
56- connectionInfo . innerText = `${ minutes } :${ seconds } ` ;
57- }
58-
59- tick += 1 ;
60- } , 1000 ) ;
44+ if ( this . call . caller . userId === localUser . userId ) {
45+ this . drawCallingText ( ) ;
46+ }
6147
6248 this . sendToChildren ( this . state ) ;
6349 }
6450
6551 addCallListeners ( call ) {
6652 call . onConnected = ( ) => {
6753 this . connected = true ;
54+ this . drawCurrentTime ( ) ;
6855 this . sendToChildren ( 'connected' ) ;
6956 } ;
7057
7158 call . onEnded = ( ) => {
59+ this . drawEndResult ( ) ;
7260 this . sendToChildren ( 'ended' ) ;
7361 } ;
7462
63+ call . onReconnected = ( ) => {
64+ this . drawCurrentTime ( ) ;
65+ } ;
66+
67+ call . onReconnecting = ( ) => {
68+ this . drawReconnectingText ( ) ;
69+ } ;
70+
7571 call . onRemoteAudioSettingsChanged = ( call ) => {
7672 this . onRemoteMuted ( call . isRemoteAudioEnabled ) ;
7773 } ;
@@ -108,7 +104,7 @@ export default class CallView extends BaseElement {
108104 accept ( ) {
109105 const callOption = getCallOption ( ) ;
110106
111- this . call . accept ( callOption ) . catch ( ( e ) => {
107+ this . call . accept ( { callOption : callOption } ) . catch ( ( e ) => {
112108 alert ( e ) ;
113109 } ) ;
114110 }
@@ -127,8 +123,51 @@ export default class CallView extends BaseElement {
127123
128124 close ( ) {
129125 this . end ( ) ;
130- clearInterval ( this . timer ) ;
126+ this . removeConnectionInfoDrawer ( ) ;
131127
132128 this . sendToParent ( 'close' , this . call ) ;
133129 }
130+
131+ drawCallingText ( ) {
132+ this . removeConnectionInfoDrawer ( ) ;
133+ const rotatingTexts = [ 'Calling' , 'Calling.' , 'Calling..' ] ;
134+ let frame = 0 ;
135+ this . connectionInfoDrawer = new PeriodicJob ( ( ) => {
136+ this . connectionInfo . innerText = rotatingTexts [ frame ] ;
137+ frame = ( frame + 1 ) % rotatingTexts . length ;
138+ } ) . start ( ) ;
139+ }
140+
141+ drawReconnectingText ( ) {
142+ this . removeConnectionInfoDrawer ( ) ;
143+ const rotatingTexts = [ 'Reconnecting' , 'Reconnecting.' , 'Reconnecting..' ] ;
144+ let frame = 0 ;
145+ this . connectionInfoDrawer = new PeriodicJob ( ( ) => {
146+ this . connectionInfo . innerText = rotatingTexts [ frame ] ;
147+ frame = ( frame + 1 ) % rotatingTexts . length ;
148+ } ) . start ( ) ;
149+ }
150+
151+ drawCurrentTime ( ) {
152+ this . removeConnectionInfoDrawer ( ) ;
153+ this . connectionInfoDrawer = new PeriodicJob ( ( ) => {
154+ const durationInSec = Math . floor ( this . call . getDuration ( ) / 1000 ) ;
155+ const minutes = `0${ Math . floor ( durationInSec / 60 ) } ` . slice ( - 2 ) ;
156+ const seconds = `0${ durationInSec % 60 } ` . slice ( - 2 ) ;
157+ this . connectionInfo . innerText = `${ minutes } :${ seconds } ` ;
158+ } ) . start ( ) ;
159+ }
160+
161+ drawEndResult ( ) {
162+ this . removeConnectionInfoDrawer ( ) ;
163+ this . connectionInfo . innerText = this . call . endResult ;
164+ }
165+
166+ removeConnectionInfoDrawer ( ) {
167+ if ( this . connectionInfoDrawer ) {
168+ this . connectionInfoDrawer . stop ( ) ;
169+ this . connectionInfoDrawer = null ;
170+ }
171+ this . connectionInfo . innerText = '' ;
172+ }
134173}
0 commit comments