function handleCallUpdate(call) {
  currentCall = call;
  console.log(currentCall);
  switch (call.state) {
    case 'new': // Setup the UI
      break;
    case 'trying': // You are trying to call someone and he's ringing now
      break;
    case 'recovering': // Call is recovering from a previous session
      if (confirm('Recover the previous call?')) {
        currentCall.answer();
      } else {
        currentCall.hangup();
      }
      break;
    case 'ringing': // Someone is calling you
      //used to avoid alert block audio play, I delayed to audio play first.
      setTimeout(function () {
        if (confirm('Connect to conference?')) {
          currentCall.answer();
          currentCall.unmuteAudio();
          currentCall.undeaf();
        } else {
          currentCall.hangup();
        }
      }, 1000);
      break;
    case 'active': // Call has become active
      startCall.classList.add('d-none');
      hangupCall.classList.remove('d-none');
      hangupCall.disabled = false;
      break;
    case 'hangup': // Call is over
      startCall.classList.remove('d-none');
      hangupCall.classList.add('d-none');
      hangupCall.disabled = true;
      break;
    case 'destroy': // Call has been destroyed
      currentCall = null;
      break;
  }
}
/**
 * Update the UI when the call's state change
 */
Update the UI when the call's state change
Update the UI when the call ' s state change
function handleCallUpdate(call) {
  currentCall = call;
  console.log(currentCall);
  switch (call.state) {
    case 'new': 
      break;
    case 'trying': 
      break;
    case 'recovering': 
      if (confirm('Recover the previous call?')) {
        currentCall.answer();
      } else {
        currentCall.hangup();
      }
      break;
    case 'ringing': 
      setTimeout(function () {
        if (confirm('Connect to conference?')) {
          currentCall.answer();
          currentCall.unmuteAudio();
          currentCall.undeaf();
        } else {
          currentCall.hangup();
        }
      }, 1000);
      break;
    case 'active': 
      startCall.classList.add('d-none');
      hangupCall.classList.remove('d-none');
      hangupCall.disabled = false;
      break;
    case 'hangup': 
      startCall.classList.remove('d-none');
      hangupCall.classList.add('d-none');
      hangupCall.disabled = true;
      break;
    case 'destroy': 
      currentCall = null;
      break;
  }
}
function handleCallUpdate ( call ) { currentCall = call ; console . log ( currentCall ) ; switch ( call . state ) { case 'new' : break ; case 'trying' : break ; case 'recovering' : if ( confirm ( 'Recover the previous call?' ) ) { currentCall . answer ( ) ; } else { currentCall . hangup ( ) ; } break ; case 'ringing' : setTimeout ( function ( ) { if ( confirm ( 'Connect to conference?' ) ) { currentCall . answer ( ) ; currentCall . unmuteAudio ( ) ; currentCall . undeaf ( ) ; } else { currentCall . hangup ( ) ; } } , 1000 ) ; break ; case 'active' : startCall . classList . add ( 'd-none' ) ; hangupCall . classList . remove ( 'd-none' ) ; hangupCall . disabled = false ; break ; case 'hangup' : startCall . classList . remove ( 'd-none' ) ; hangupCall . classList . add ( 'd-none' ) ; hangupCall . disabled = true ; break ; case 'destroy' : currentCall = null ; break ; } }
Update the UI when the call's state change
Update the UI when the call ' s state change
// Setup the UI // You are trying to call someone and he's ringing now // Call is recovering from a previous session // Someone is calling you //used to avoid alert block audio play, I delayed to audio play first. // Call has become active // Call is over // Call has been destroyed