onIceConnectionStateChange_(event) {
    if (!this.peerConnection_) return;

    const state = this.peerConnection_.iceConnectionState;
    this.logger_.info('New ICE connection state: ' + state + '.');
    if (state == 'connected') {
      this.onConnectionSuccess_(PeerConnection.Event.ICE_CONNECTED);
    } else if (state == 'completed') {
      this.onConnectionSuccess_(PeerConnection.Event.ICE_COMPLETED);
    } else if (state == 'failed') {
      this.logger_.warning(
          () => 'Ice connection failed: ' + JSON.stringify(event));
      this.onConnectionFailure_(PeerConnection.Event.ICE_FAILED);
    } else if (state == 'closed') {
      this.onConnectionClosed_(PeerConnection.Event.ICE_CLOSED);
    } else if (state == 'disconnected') {
      this.logger_.warning('Ice connection state is bad.');
      if (this.enableIceRestart_ && this.isStarted()) {
        this.logger_.info('Restarting ICE.');
        this.peerConnection_.createOffer(
            this.setLocalDescription_.bind(this), error => {
              this.logger_.warning('Error creating new offer.', error);
            }, PeerConnection.ICE_RESTART_MEDIA_CONSTRAINTS);
      } else {
        this.onConnectionStale_();
      }
    }
  }
/**
   * Handles ICE connection state changes. Tries to restart PeerConnection when
   * we
   * are in a disconnected state by creating a new offer with the IceRestart
   * constraint.
   * @param {Event} event
   * @private
   */
Handles ICE connection state changes. Tries to restart PeerConnection when
we
are in a disconnected state by creating a new offer with the IceRestart
constraint.
@param {Event} event
@private
Handles ICE connection state changes . Tries to restart PeerConnection when we are in a disconnected state by creating a new offer with the IceRestart constraint . @param { Event } event @private
onIceConnectionStateChange_(event) {
    if (!this.peerConnection_) return;
    const state = this.peerConnection_.iceConnectionState;
    this.logger_.info('New ICE connection state: ' + state + '.');
    if (state == 'connected') {
      this.onConnectionSuccess_(PeerConnection.Event.ICE_CONNECTED);
    } else if (state == 'completed') {
      this.onConnectionSuccess_(PeerConnection.Event.ICE_COMPLETED);
    } else if (state == 'failed') {
      this.logger_.warning(
          () => 'Ice connection failed: ' + JSON.stringify(event));
      this.onConnectionFailure_(PeerConnection.Event.ICE_FAILED);
    } else if (state == 'closed') {
      this.onConnectionClosed_(PeerConnection.Event.ICE_CLOSED);
    } else if (state == 'disconnected') {
      this.logger_.warning('Ice connection state is bad.');
      if (this.enableIceRestart_ && this.isStarted()) {
        this.logger_.info('Restarting ICE.');
        this.peerConnection_.createOffer(
            this.setLocalDescription_.bind(this), error => {
              this.logger_.warning('Error creating new offer.', error);
            }, PeerConnection.ICE_RESTART_MEDIA_CONSTRAINTS);
      } else {
        this.onConnectionStale_();
      }
    }
  }
onIceConnectionStateChange_ ( event ) { if ( ! this . peerConnection_ ) return ; const state = this . peerConnection_ . iceConnectionState ; this . logger_ . info ( 'New ICE connection state: ' + state + '.' ) ; if ( state == 'connected' ) { this . onConnectionSuccess_ ( PeerConnection . Event . ICE_CONNECTED ) ; } else if ( state == 'completed' ) { this . onConnectionSuccess_ ( PeerConnection . Event . ICE_COMPLETED ) ; } else if ( state == 'failed' ) { this . logger_ . warning ( ( ) => 'Ice connection failed: ' + JSON . stringify ( event ) ) ; this . onConnectionFailure_ ( PeerConnection . Event . ICE_FAILED ) ; } else if ( state == 'closed' ) { this . onConnectionClosed_ ( PeerConnection . Event . ICE_CLOSED ) ; } else if ( state == 'disconnected' ) { this . logger_ . warning ( 'Ice connection state is bad.' ) ; if ( this . enableIceRestart_ && this . isStarted ( ) ) { this . logger_ . info ( 'Restarting ICE.' ) ; this . peerConnection_ . createOffer ( this . setLocalDescription_ . bind ( this ) , error => { this . logger_ . warning ( 'Error creating new offer.' , error ) ; } , PeerConnection . ICE_RESTART_MEDIA_CONSTRAINTS ) ; } else { this . onConnectionStale_ ( ) ; } } }
Handles ICE connection state changes.
Handles ICE connection state changes .